Skip to content

Commit c10750e

Browse files
author
Nikos Vasileiou
authored
Merge pull request #21 from stelabouras/stelios/fix/workspace-project
Address project parameter to allow `.xcworkspace` + update version to 1.0.5
2 parents 992266f + 0ed53b4 commit c10750e

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,10 @@ argument of the push command.
5656
*March 15, 2022*
5757

5858
- Fixes issue where special characters in XLIFF were not producing correct source strings.
59+
60+
## Transifex Command Line Tool 1.0.5
61+
62+
*October 25, 2022*
63+
64+
- Allows users to enter a `.xcworkspace` as a `project` argument and handles it correctly.
65+

Sources/TXCli/main.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ that can be bundled with the iOS application.
4242
The tool can be also used to force CDS cache invalidation so that the next pull
4343
command will fetch fresh translations from CDS.
4444
""",
45-
version: "1.0.4",
45+
version: "1.0.5",
4646
subcommands: [Push.self, Pull.self, Invalidate.self])
4747
}
4848

@@ -80,7 +80,7 @@ You can either provide the Transifex token and secret via enviroment variables
8080
private var sourceLocale: String = "en"
8181

8282
@Option(name: .long, help: """
83-
Either the path to the project's .xcodeproj (e.g. ../MyProject/myproject.xcodeproj),
83+
Either the path to the project's .xcodeproj or .xcworkspace (e.g. ../MyProject/myproject.xcodeproj),
8484
or the path to the generated .xliff (e.g. ../en.xliff).
8585
""")
8686
private var project : String
@@ -135,7 +135,7 @@ Control whether the keys of strings to be pushed should be hashed or not.
135135
logHandler.verbose("[prompt]Using secret: \(transifexSecret)[end]")
136136

137137
var xliffURL : URL? = nil
138-
let url = URL(fileURLWithPath: project)
138+
let projectURL = URL(fileURLWithPath: project)
139139

140140
var localizationExporter : LocalizationExporter? = nil
141141

@@ -145,14 +145,14 @@ Control whether the keys of strings to be pushed should be hashed or not.
145145
}
146146
}
147147

148-
if url.pathExtension == "xliff" {
149-
xliffURL = url
148+
if projectURL.pathExtension == "xliff" {
149+
xliffURL = projectURL
150150
logHandler.verbose("[prompt]XLIFF file detected: \(xliffURL!)[end]")
151151
}
152152
else {
153153
guard let locExporter = LocalizationExporter(sourceLocale: sourceLocale,
154-
project: project,
155-
logHandler: logHandler) else {
154+
project: projectURL,
155+
logHandler: logHandler) else {
156156
logHandler.error("Failed to initialize localization exporter")
157157
throw CommandError.exporterInitializationFailure
158158
}

Sources/TXCliLib/LocalizationExporter.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public class LocalizationExporter {
1515
/// The source (base) locale of the project that will be used for looking up the generated XLIFF file.
1616
let sourceLocale: String
1717

18-
/// The relative or absolute path to the .xcodeproj folder of the Xcode project.
19-
let project: String
18+
/// The relative or absolute file URL to the .xcodeproj or .xcworkspace folder of the Xcode project.
19+
let project: URL
2020

2121
/// The temporary export file URL that will be used to store the exported localizations.
2222
private let exportURL: URL
@@ -37,8 +37,14 @@ public class LocalizationExporter {
3737
/// - project: The path to the project name (can be a relative path)
3838
/// - logHandler: Optional log handler
3939
public init?(sourceLocale: String,
40-
project: String,
40+
project: URL,
4141
logHandler: TXLogHandler? = nil) {
42+
guard project.pathExtension == "xcodeproj"
43+
|| project.pathExtension == "xcworkspace" else {
44+
logHandler?.error("Error: project parameter is not a .xcodeproj or .xcworkspace")
45+
return nil
46+
}
47+
4248
self.sourceLocale = sourceLocale
4349
self.project = project
4450
self.logHandler = logHandler
@@ -98,14 +104,15 @@ public class LocalizationExporter {
98104
public func export() -> URL? {
99105
logHandler?.verbose("[prompt]Exporting localizations for project \(project) to[end] [file]\(exportURL.path)[end][prompt]...[end]")
100106

107+
let isProject = project.pathExtension == "xcodeproj"
101108
let outputPipe = Pipe()
102109
let errorPipe = Pipe()
103110

104111
let process = Process()
105112
process.executableURL = URL(fileURLWithPath: "/usr/bin/xcodebuild")
106113
process.arguments = [ "-exportLocalizations",
107114
"-localizationPath", exportURL.path,
108-
"-project", project]
115+
isProject ? "-project" : "-workspace", project.path]
109116
process.standardOutput = outputPipe
110117
process.standardError = errorPipe
111118

0 commit comments

Comments
 (0)