Xcode .stringsdict Localization
Replexica supports Xcode's .stringsdict
format, which is crucial for handling pluralization and other variable substitutions in your iOS, macOS, watchOS, and visionOS apps.
Setting Up
To use Replexica with .stringsdict
files, configure your i18n.json
as follows:
{
"version": 1.2,
"locale": {
"source": "en",
"targets": ["es", "fr", "de"]
},
"buckets": {
"xcode-stringsdict": {
"include": [
"MyApp/[locale].lproj/Localizable.stringsdict"
]
}
}
}
TIP
Note the use of [locale]
in the path, which Replexica will replace with the appropriate locale code.
How It Works
The .stringsdict
file is an XML-based plist format that Xcode uses for complex localizations, especially for pluralization. Replexica parses this format, translates the content, and generates new .stringsdict
files for each target language.
Here's an example of a .stringsdict
file structure:
<?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>key</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@count@</string>
<key>count</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>zero</key>
<string>No items</string>
<key>one</key>
<string>One item</string>
<key>other</key>
<string>%d items</string>
</dict>
</dict>
</dict>
</plist>
Replexica parses this format, translates the content, and generates new .stringsdict
files for each target language.
Localizing
To localize your .stringsdict
files, run:
npx replexica@latest i18n
Replexica will process your source .stringsdict
file and create or update the target language files.
Features
Pluralization: Replexica handles complex pluralization rules, including zero, one, two, few, many, and other forms.
Variable Substitution: The loader preserves format specifiers like
%lld
and%@
.XML Structure: Replexica maintains the correct XML and plist structure required by Xcode.
Incremental Updates: Only new or changed strings are translated, saving time and processing power.
Pro Tips
Consistency with .strings and .xcstrings: Ensure your pluralization keys in
.stringsdict
match those in your.strings
or.xcstrings
files for proper integration in your app.Language-Specific Plural Rules: Be aware that different languages have different pluralization rules. Replexica handles these differences automatically.
Multiple Files: If your project uses multiple
.stringsdict
files, you can include them all in youri18n.json
config:json"xcode-stringsdict": { "include": [ "MyApp/[locale].lproj/Localizable.stringsdict", "MyApp/[locale].lproj/InfoPlist.stringsdict" ] }
By leveraging these features and tips, you can maintain a robust, scalable localization setup for your Xcode projects using the .stringsdict
format, seamlessly integrating with your existing development workflow.
For more information on other Xcode localization formats supported by Replexica, check out the documentation for .xcstrings
and .strings
files.