Skip to content

Commit

Permalink
Ignore strings where shouldTranslate is set to false
Browse files Browse the repository at this point in the history
  • Loading branch information
roddymunro committed Aug 15, 2024
1 parent 2d5751c commit f6122f8
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .swiftpm/configuration/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" : "41982a3656a71c768319979febd796c6fd111d5c",
"version" : "1.5.0"
}
}
],
"version" : 2
}
4 changes: 4 additions & 0 deletions Sources/SwiftPolyglotCore/SwiftPolyglotCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public struct SwiftPolyglotCore {
var missingTranslations: [MissingTranslation] = []

for (originalString, translations) in strings {
if let shouldTranslate = translations["shouldTranslate"] as? Bool, shouldTranslate == false {
continue
}

guard let localizations = translations["localizations"] as? [String: [String: Any]] else {
missingTranslations.append(
MissingTranslation(
Expand Down
22 changes: 22 additions & 0 deletions Tests/SwiftPolyglotCoreTests/SwiftPolyglotCoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ final class SwiftPolyglotCoreTests: XCTestCase {
await XCTAssertNoThrowAsync(swiftPolyglotCore.run)
}

func testStringCatalogWithDontTranslate() async throws {
guard
let stringCatalogFilePath = Bundle.module.path(
forResource: "WithDontTranslate",
ofType: ".xcstrings",
inDirectory: "TestFiles"
)
else {
XCTFail("Dont translate string catalog for testing not found")
return
}

let swiftPolyglotCore: SwiftPolyglotCore = .init(
filePaths: [stringCatalogFilePath],
languageCodes: ["de", "en"],
logsErrorOnMissingTranslation: true,
isRunningInAGitHubAction: false
)

await XCTAssertNoThrowAsync(swiftPolyglotCore.run)
}

func testStringCatalogVariationsFullyTranslated() async throws {
guard
let stringCatalogFilePath = Bundle.module.path(
Expand Down
30 changes: 30 additions & 0 deletions Tests/SwiftPolyglotCoreTests/TestFiles/WithDontTranslate.xcstrings
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"sourceLanguage" : "en",
"strings" : {
"butterfly" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "butterfly"
}
}
},
"shouldTranslate" : false
},
"football" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "football"
}
}
},
"shouldTranslate" : false
}
},
"version" : "1.0"
}

0 comments on commit f6122f8

Please sign in to comment.