Translations workflow and tools (#768)
* Translations workflow and tools * improved the name of the workflow * need this commit to trigger the workflow for the first time * swift tools can now run on CI * only strings and stringsdict will be committed * fixed a workflow issue * starting the workflow to save it * fixing downgrade issues * fixing URL usage * install localazy * fixing add-paths typo * downloaded strings * removing on push trigger * Update Tools/Sources/DownloadTranslations.swift Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com> * Added locheck for string verification * code formatting improvement * Update Tools/Sources/Locheck.swift Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com> * pr suggestion --------- Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>
This commit is contained in:
@@ -28,7 +28,7 @@ struct BuildSDK: ParsableCommand {
|
||||
var profile: Profile = .debug
|
||||
|
||||
private var parentDirectoryURL: URL { Utilities.projectDirectoryURL.deletingLastPathComponent() }
|
||||
private var sdkDirectoryURL: URL { parentDirectoryURL.appending(path: "matrix-rust-sdk") }
|
||||
private var sdkDirectoryURL: URL { parentDirectoryURL.appendingPathComponent("matrix-rust-sdk") }
|
||||
|
||||
enum Error: LocalizedError {
|
||||
case rustupOutputFailure
|
||||
@@ -109,7 +109,7 @@ struct BuildSDK: ParsableCommand {
|
||||
|
||||
/// Update project.yml with the local path of the SDK.
|
||||
func updateProjectYAML() throws {
|
||||
let yamlURL = Utilities.projectDirectoryURL.appending(path: "project.yml")
|
||||
let yamlURL = Utilities.projectDirectoryURL.appendingPathComponent("project.yml")
|
||||
let yamlString = try String(contentsOf: yamlURL)
|
||||
guard var projectConfig = try Yams.compose(yaml: yamlString) else { throw Error.failureParsingProjectYAML }
|
||||
|
||||
|
||||
18
Tools/Sources/DownloadStrings.swift
Normal file
18
Tools/Sources/DownloadStrings.swift
Normal file
@@ -0,0 +1,18 @@
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
|
||||
struct DownloadStrings: ParsableCommand {
|
||||
static var configuration = CommandConfiguration(abstract: "A tool to download localizable strings from localazy")
|
||||
|
||||
@Flag(help: "Use to download translation keys for all languages")
|
||||
var allLanguages = false
|
||||
|
||||
func run() throws {
|
||||
try localazyDownload()
|
||||
}
|
||||
|
||||
private func localazyDownload() throws {
|
||||
let json = allLanguages ? "localazy-all.json" : "localazy-en.json"
|
||||
try Utilities.zsh("localazy download --config \(json)")
|
||||
}
|
||||
}
|
||||
44
Tools/Sources/Locheck.swift
Normal file
44
Tools/Sources/Locheck.swift
Normal file
@@ -0,0 +1,44 @@
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
|
||||
struct Locheck: ParsableCommand {
|
||||
enum LocheckError: LocalizedError {
|
||||
case missingMint
|
||||
case outputError
|
||||
|
||||
var errorDescription: String? {
|
||||
switch self {
|
||||
case .missingMint:
|
||||
return "💥 Unable to find mint. Fix by running:\nbrew install mint\n"
|
||||
case .outputError:
|
||||
return "💥 Failed to read the output from locheck."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static var configuration = CommandConfiguration(abstract: "A tool that verifies bad strings contained in localization files")
|
||||
|
||||
private var stringsDirectoryURL: URL {
|
||||
Utilities.projectDirectoryURL.appendingPathComponent("ElementX/Resources/Localizations")
|
||||
}
|
||||
|
||||
func run() throws {
|
||||
try checkMint()
|
||||
try checkStrings()
|
||||
}
|
||||
|
||||
func checkStrings() throws {
|
||||
guard let output = try Utilities.zsh("mint run locheck discoverlproj --ignore-missing --ignore lproj_file_missing_from_translation --treat-warnings-as-errors \(stringsDirectoryURL.path)") else {
|
||||
throw LocheckError.missingMint
|
||||
}
|
||||
print(output)
|
||||
}
|
||||
|
||||
private func checkMint() throws {
|
||||
let result = try Utilities.zsh("which mint")
|
||||
|
||||
if result?.contains("not found") == true {
|
||||
throw LocheckError.missingMint
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import Foundation
|
||||
struct OutdatedPackages: ParsableCommand {
|
||||
static var configuration = CommandConfiguration(abstract: "A tool to check outdated package dependencies. Please make sure you have already run setup-project before using this tool.")
|
||||
|
||||
private var projectSwiftPMDirectoryURL: URL { Utilities.projectDirectoryURL.appending(path: "ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm") }
|
||||
private var projectSwiftPMDirectoryURL: URL { Utilities.projectDirectoryURL.appendingPathComponent("ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm") }
|
||||
|
||||
func run() throws {
|
||||
try checkToolsDependencies()
|
||||
|
||||
@@ -15,7 +15,7 @@ struct SetupProject: ParsableCommand {
|
||||
}
|
||||
|
||||
func brewBundleInstall() throws {
|
||||
try Utilities.zsh("brew install xcodegen swiftgen swiftlint swiftformat git-lfs sourcery kiliankoe/formulae/swift-outdated localazy/tools/localazy")
|
||||
try Utilities.zsh("brew install xcodegen swiftgen swiftlint swiftformat git-lfs sourcery mint kiliankoe/formulae/swift-outdated localazy/tools/localazy")
|
||||
}
|
||||
|
||||
func xcodegen() throws {
|
||||
|
||||
@@ -6,5 +6,7 @@ struct Tools: ParsableCommand {
|
||||
static var configuration = CommandConfiguration(abstract: "A collection of command line tools for ElementX",
|
||||
subcommands: [BuildSDK.self,
|
||||
SetupProject.self,
|
||||
OutdatedPackages.self])
|
||||
OutdatedPackages.self,
|
||||
DownloadStrings.self,
|
||||
Locheck.self])
|
||||
}
|
||||
|
||||
@@ -13,13 +13,13 @@ enum Utilities {
|
||||
}
|
||||
}
|
||||
|
||||
static var projectDirectoryURL: URL { URL(filePath: FileManager.default.currentDirectoryPath) }
|
||||
static var projectDirectoryURL: URL { URL(fileURLWithPath: FileManager.default.currentDirectoryPath) }
|
||||
|
||||
/// Runs a command in zsh.
|
||||
@discardableResult
|
||||
static func zsh(_ command: String, workingDirectoryURL: URL = projectDirectoryURL) throws -> String? {
|
||||
let process = Process()
|
||||
process.executableURL = URL(filePath: "/bin/zsh")
|
||||
process.executableURL = URL(fileURLWithPath: "/bin/zsh")
|
||||
process.arguments = ["-cu", command]
|
||||
process.currentDirectoryURL = workingDirectoryURL
|
||||
|
||||
|
||||
Reference in New Issue
Block a user