Open Kaspik opened 9 months ago
It sounds like your Strings Catalog is a good stress-test for the tool 😄
That is strange though, you are right, the screenshot looks fine... Would you be able to pull the JSON for common.feed.translations_seen_by
out of the .xcstrings file and share it here?
We can then put it into the fixture tests to try and replicate the issue... So far, this is what the tests are checking:
Great, thanks! From a quick glance, it looks like argNum
is missing... It's fun working with an undocumented file format 😆 ... I'll try to reproduce to that kind of configuration in the test suite and confirm if it is that 👍
That said.. How do you actually get the Strings Catalog GUI to let you add a single substitution?
The option to Vary by Plural isn't enabled in this case:
Honestly, no idea, that was an automated mgiration of Xcode from .stringsdict
:) But we have plenty of those.
that was an automated migration of Xcode
Ahh, that makes sense.. .stringsdict required that you had a single substitution (purple) whereas .xcstrings seems to support one plural without the substitution syntax.
I created a .stringsdict file that replicates a few valid scenarios:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fromStringsDictionary</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>There %#@number_of_substitutions@ in this phrase</string>
<key>number_of_substitutions</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>lld</string>
<key>zero</key>
<string>are no substitutions</string>
<key>one</key>
<string>is %lld substitution</string>
<key>other</key>
<string>are %lld substitutions</string>
</dict>
</dict>
<key>fromStringsDictionaryWithArg</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%@! There %#@number_of_substitutions@ in this phrase</string>
<key>number_of_substitutions</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>lld</string>
<key>zero</key>
<string>are no substitutions</string>
<key>one</key>
<string>is %lld substitution</string>
<key>other</key>
<string>are %lld substitutions</string>
</dict>
</dict>
<key>fromStringsDictionaryWithPositionalArgs</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%2$@! There %1$#@number_of_substitutions@ in this phrase</string>
<key>number_of_substitutions</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>lld</string>
<key>zero</key>
<string>are no substitutions</string>
<key>one</key>
<string>is %lld substitution</string>
<key>other</key>
<string>are %lld substitutions</string>
</dict>
</dict>
</dict>
</plist>
func testStringsDictionary() throws {
let bundle = Bundle.module
XCTAssertEqual(
String(format: bundle.localizedString(forKey: "fromStringsDictionary", value: nil, table: "Migration"), 0),
"There are no substitutions in this phrase"
)
XCTAssertEqual(
String(format: bundle.localizedString(forKey: "fromStringsDictionaryWithArg", value: nil, table: "Migration"), "John", 10),
"John! There are 10 substitutions in this phrase"
)
XCTAssertEqual(
String(format: bundle.localizedString(forKey: "fromStringsDictionaryWithPositionalArgs", value: nil, table: "Migration"), 1, "John"),
"John! There is 1 substitution in this phrase"
)
}
Using the migrator, this gives me the following Strings Catalog:
{
"sourceLanguage" : "en",
"strings" : {
"fromStringsDictionary" : {
"extractionState" : "migrated",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "There %#@number_of_substitutions@ in this phrase"
},
"substitutions" : {
"number_of_substitutions" : {
"formatSpecifier" : "lld",
"variations" : {
"plural" : {
"one" : {
"stringUnit" : {
"state" : "translated",
"value" : "is %arg substitution"
}
},
"other" : {
"stringUnit" : {
"state" : "translated",
"value" : "are %arg substitutions"
}
},
"zero" : {
"stringUnit" : {
"state" : "translated",
"value" : "are no substitutions"
}
}
}
}
}
}
}
}
},
"fromStringsDictionaryWithArg" : {
"extractionState" : "migrated",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "%@! There %#@number_of_substitutions@ in this phrase"
},
"substitutions" : {
"number_of_substitutions" : {
"formatSpecifier" : "lld",
"variations" : {
"plural" : {
"one" : {
"stringUnit" : {
"state" : "translated",
"value" : "is %arg substitution"
}
},
"other" : {
"stringUnit" : {
"state" : "translated",
"value" : "are %arg substitutions"
}
},
"zero" : {
"stringUnit" : {
"state" : "translated",
"value" : "are no substitutions"
}
}
}
}
}
}
}
}
},
"fromStringsDictionaryWithPositionalArgs" : {
"extractionState" : "migrated",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "%2$@! There %#@number_of_substitutions@ in this phrase"
},
"substitutions" : {
"number_of_substitutions" : {
"argNum" : 1,
"formatSpecifier" : "lld",
"variations" : {
"plural" : {
"one" : {
"stringUnit" : {
"state" : "translated",
"value" : "is %lld substitution"
}
},
"other" : {
"stringUnit" : {
"state" : "translated",
"value" : "are %lld substitutions"
}
},
"zero" : {
"stringUnit" : {
"state" : "translated",
"value" : "are no substitutions"
}
}
}
}
}
}
}
}
}
},
"version" : "1.0"
}
So argNum
is only non-nil in a couple of scenarios:
NSStringLocalizedFormatKey
value explicitlyThis means that we should not assume that it will be defined. The only reason that we require it anyway is to use the substitution key as the label for the argument.. I'll have a play around to see how to relax this a bit 👍
Hey @liamnichols !
I downloaded your demo project DogTracker to test things out, and replaced the
Localizable.xcstrings
with our own (we have a lot of languages, and a lot of strings - the file itself has 12MB and ~600 000 lines).When compiling the dog Tracker, error is shown:
Decoding error at ‘strings → common.feed.translations_seen_by → localizations → ar → substitutions → number_of_parents‘ - The data couldn’t be read because it is missing.
As you can see on the screenshot, everything looks correct. I wonder if you are able to debug this issue. Note: It is using 0.1.1 version released 30 mins ago. :)