Skip to content

Commit

Permalink
Trigger key_missing_from_base for iOS
Browse files Browse the repository at this point in the history
Fixes Asana#57
  • Loading branch information
marcelofabri committed Aug 21, 2024
1 parent 258bcb5 commit fbc77f2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Sources/LocheckLogic/Validators/parseAndValidateXCStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,22 @@ func validateStrings(
path: baseString.path,
lineNumber: baseString.line)
}

let baseStringsKeys = Set(baseStrings.map(\.key))

var missingInBaseKeys: Set<String> = []
for translationString in translationStrings where !baseStringsKeys.contains(translationString.key) {
problemReporter.report(
KeyMissingFromBase(
key: translationString.key),
path: translationString.path,
lineNumber: translationString.line)
missingInBaseKeys.insert(translationString.key)
}

// MARK: Validate arguments

for translationString in translationStrings {
for translationString in translationStrings where !missingInBaseKeys.contains(translationString.key) {
let baseArgumentPositions = Set(translationString.base.arguments.map(\.position))
let translationArgumentPositions = Set(translationString.translation.arguments.map(\.position))

Expand Down
35 changes: 35 additions & 0 deletions Tests/LocheckLogicTests/ValidateStringsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,39 @@ class ValidateStringsTests: XCTestCase {
"abc:1: warning: 'missing' is missing from trnsltn (key_missing_from_translation)",
])
}

func testExtraKeyInTranslation() {
let problemReporter = ProblemReporter(log: false)
validateStrings(
baseStrings: [
LocalizedStringPair(
string: "\"present\" = \"present\";",
path: "abc",
line: 0,
basePath: "",
baseLineFallback: 0)!,
],
translationStrings: [
LocalizedStringPair(
string: "\"present\" = \"tneserp\";",
path: "def",
line: 0,
basePath: "",
baseLineFallback: 0)!,
LocalizedStringPair(
string: "\"extra\" = \"%s\";",
path: "abc",
line: 1,
basePath: "",
baseLineFallback: 0)!,
],
baseLanguageName: "en",
translationLanguageName: "trnsltn",
problemReporter: problemReporter)

XCTAssertEqual(
problemReporter.problems.map(\.messageForXcode), [
"abc:1: warning: 'extra' is missing from the base translation (key_missing_from_base)",
])
}
}

0 comments on commit fbc77f2

Please sign in to comment.