Skip to content

Commit

Permalink
Merge pull request #16 from stelabouras/stelios/improvement/xliff
Browse files Browse the repository at this point in the history
Stelios/improvement/xliff
  • Loading branch information
Nikos Vasileiou authored Oct 27, 2021
2 parents d372bdf + 81502a7 commit c178a63
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ By default the value of this option is `true`, so the keys will be hashed unless
- Translation keys are now printed next to the source string when `--dry-run`
option is provided.
- Updates Transifex Swift library to 1.0.1.

## Transifex Command Line Tool 1.0.2

*October 26, 2021*

- Introduces parsing directly from an `.xliff` file using the `--project`
argument of the push command.
42 changes: 29 additions & 13 deletions Sources/TXCli/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ that can be bundled with the iOS application.
The tool can be also used to force CDS cache invalidation so that the next pull
command will fetch fresh translations from CDS.
""",
version: "1.0.1",
version: "1.0.2",
subcommands: [Push.self, Pull.self, Invalidate.self])
}

Expand Down Expand Up @@ -80,8 +80,8 @@ You can either provide the Transifex token and secret via enviroment variables
private var sourceLocale: String = "en"

@Option(name: .long, help: """
Path to the .xcodeproj file of the project
(e.g. ../MyProject/myproject.xcodeproj)
Either the path to the project's .xcodeproj (e.g. ../MyProject/myproject.xcodeproj),
or the path to the generated .xliff (e.g. ../en.xliff).
""")
private var project : String

Expand Down Expand Up @@ -134,25 +134,41 @@ Control whether the keys of strings to be pushed should be hashed or not.

logHandler.verbose("[prompt]Using secret: \(transifexSecret)[end]")

guard let localizationExporter = LocalizationExporter(sourceLocale: sourceLocale,
project: project,
logHandler: logHandler) else {
logHandler.error("Failed to initialize localization exporter")
throw CommandError.exporterInitializationFailure
var xliffURL : URL? = nil
let url = URL(fileURLWithPath: project)

if url.pathExtension == "xliff" {
xliffURL = url
logHandler.verbose("[prompt]XLIFF file detected: \(xliffURL!)[end]")
}
else {
guard let localizationExporter = LocalizationExporter(sourceLocale: sourceLocale,
project: project,
logHandler: logHandler) else {
logHandler.error("Failed to initialize localization exporter")
throw CommandError.exporterInitializationFailure
}

defer {
if !keepTempFolder {
localizationExporter.cleanup()
defer {
if !keepTempFolder {
localizationExporter.cleanup()
}
}

guard let exportXliffURL = localizationExporter.export() else {
logHandler.error("Localization export failed")
throw CommandError.exportingFailure
}

xliffURL = exportXliffURL
}

guard let xliffURL = localizationExporter.export() else {
guard let fileURL = xliffURL else {
logHandler.error("Localization export failed")
throw CommandError.exportingFailure
}

guard let parser = XLIFFParser(fileURL: xliffURL,
guard let parser = XLIFFParser(fileURL: fileURL,
logHandler: logHandler) else {
logHandler.error("Failed to initialize XLIFF parser")
throw CommandError.xliffParserInitializationFailure
Expand Down

0 comments on commit c178a63

Please sign in to comment.