Skip to content

Commit

Permalink
v1.0.0 merge (#18)
Browse files Browse the repository at this point in the history
* Add ArgumentParser (#16)

* Add ArgumentParser dependency

* Rename SwiftPolyglotCore struct

* Add RuntimeError

* Rename SwiftPolyglot struct, add ParsableCommand adoption and add RuntimeError usage

* Parse arguments and flag using ArgumentParser and adjust SwiftPolyglotCore initializer's parameters

* Update README

* Rename property

* Format

* Fix command name in help's message

* Add Concurrency (#17)

* Set minimum macOS version to version 10.15 (Catalina)

* Add MissingTranslation struct

* Add concurrency to core functionality

* Adopt AsyncParsableCommand protocol to provide an asynchronous entry point

* Add XCTest extension for testing async throwing expressions

* Add concurrency to tests

* Fix SwiftFormat issues (#19)

* Remove trailing commas

* Fix indentation

* Move inline try to start of expression

* Remove trailing white spaces

* Use opaque generic parameters instead of generic parameters with constraints

* Replace consecutive blank lines with a single blank line

* Disable hoistAwait (#20)

* Fix swiftformat (#21)

* Improve assertions on async throwing expressions (#22)

* Add Equatable adoption for custom error

* Improve custom method for asserting on asynchronous expressions which should run successfully without throwing an error

* Improve custom method for asserting on asynchronous expressions which should throw an error

* Reenable hoistAwait SwiftFormat rule

---------

Co-authored-by: Pere Bohigas <[email protected]>
  • Loading branch information
roddymunro and pereBohigas authored Jun 12, 2024
1 parent 818d73f commit 2d5751c
Show file tree
Hide file tree
Showing 13 changed files with 412 additions and 243 deletions.
3 changes: 2 additions & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@

# rules

--disable preferForLoop
--disable preferForLoop

14 changes: 14 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "46989693916f56d1186bd59ac15124caef896560",
"version" : "1.3.1"
}
}
],
"version" : 2
}
11 changes: 10 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ import PackageDescription

let package = Package(
name: "SwiftPolyglot",
platforms: [
.macOS(.v10_15),
],
products: [
.executable(name: "swiftpolyglot", targets: ["SwiftPolyglot"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMajor(from: "1.3.1")),
],
targets: [
.executableTarget(
name: "SwiftPolyglot",
dependencies: ["SwiftPolyglotCore"]
dependencies: [
"SwiftPolyglotCore",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]
),
.target(name: "SwiftPolyglotCore"),
.testTarget(
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ $ swift build -c release

```
$ cd ../path/to/your/project
$ swift run --package-path ../path/to/SwiftPolyglot swiftpolyglot "en,es,de"
$ swift run --package-path ../path/to/SwiftPolyglot swiftpolyglot en es de
```

## Arguments

You must specify at least one language code, they must be within quotation marks, and they must be separated by commas. If you are not providing a translation for your language of origin, you do not need to specify that language. Otherwise, you will get errors due to missing translations.
You must specify at least one language code, and they must be separated by spaces. If you are not providing a translation for your language of origin, you do not need to specify that language. Otherwise, you will get errors due to missing translations.

By default, SwiftPolyglot will not throw an error at the end of the script if there are translations missing. However, you can enable error throwing by adding the argument `--errorOnMissing`
By default, SwiftPolyglot will not throw an error at the end of the script if there are translations missing. However, you can enable error throwing by adding the flag `--error-on-missing`

## Integrating with GitHub Actions

Expand All @@ -60,6 +60,6 @@ jobs:
- name: validate translations
run: |
swift build --package-path ../SwiftPolyglot --configuration release
swift run --package-path ../SwiftPolyglot swiftpolyglot "es,fr,de,it" --errorOnMissing
swift run --package-path ../SwiftPolyglot swiftpolyglot es fr de it --error-on-missing
```

15 changes: 15 additions & 0 deletions Sources/SwiftPolyglot/RuntimeError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
enum RuntimeError: Error {
case coreError(description: String)
case fileListingNotPossible
}

extension RuntimeError: CustomStringConvertible {
var description: String {
switch self {
case let .coreError(description):
return description
case .fileListingNotPossible:
return "It was not possible to list all files to be checked"
}
}
}
36 changes: 36 additions & 0 deletions Sources/SwiftPolyglot/SwiftPolyglot.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import ArgumentParser
import Foundation
import SwiftPolyglotCore

@main
struct SwiftPolyglot: AsyncParsableCommand {
static let configuration: CommandConfiguration = .init(commandName: "swiftpolyglot")

@Flag(help: "Log errors instead of warnings for missing translations.")
private var errorOnMissing = false

@Argument(help: "Specify the language(s) to be checked.")
private var languages: [String]

func run() async throws {
guard
let enumerator = FileManager.default.enumerator(atPath: FileManager.default.currentDirectoryPath),
let filePaths = enumerator.allObjects as? [String]
else {
throw RuntimeError.fileListingNotPossible
}

let swiftPolyglotCore: SwiftPolyglotCore = .init(
filePaths: filePaths,
languageCodes: languages,
logsErrorOnMissingTranslation: errorOnMissing,
isRunningInAGitHubAction: ProcessInfo.processInfo.environment["GITHUB_ACTIONS"] == "true"
)

do {
try await swiftPolyglotCore.run()
} catch {
throw RuntimeError.coreError(description: error.localizedDescription)
}
}
}
22 changes: 0 additions & 22 deletions Sources/SwiftPolyglot/main.swift

This file was deleted.

30 changes: 30 additions & 0 deletions Sources/SwiftPolyglotCore/MissingTranslation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
struct MissingTranslation {
enum Category {
case deviceMissingOrNotTranslated(forDevice: String, inLanguage: String)
case missingOrNotTranslated(inLanguage: String)
case missingTranslation(forLanguage: String)
case missingTranslationForAllLanguages
case pluralMissingOrNotTranslated(forPluralForm: String, inLanguage: String)
}

let category: Category
let filePath: String
let originalString: String
}

extension MissingTranslation {
var message: String {
switch category {
case let .deviceMissingOrNotTranslated(device, language):
return "'\(originalString)' device '\(device)' is missing or not translated in '\(language)' in file: \(filePath)"
case let .missingOrNotTranslated(language):
return "'\(originalString)' is missing or not translated in '\(language)' in file: \(filePath)"
case let .missingTranslation(language):
return "'\(originalString)' is missing translations for language '\(language)' in file: \(filePath)"
case .missingTranslationForAllLanguages:
return "'\(originalString)' is not translated in any language in file: \(filePath)"
case let .pluralMissingOrNotTranslated(pluralForm, language):
return "'\(originalString)' plural form '\(pluralForm)' is missing or not translated in '\(language)' in file: \(filePath)"
}
}
}
192 changes: 0 additions & 192 deletions Sources/SwiftPolyglotCore/SwiftPolyglot.swift

This file was deleted.

Loading

0 comments on commit 2d5751c

Please sign in to comment.