Xcode .strings Localization
Replexica supports Xcode's traditional .strings
format, making it easy to manage translations for your iOS, macOS, watchOS, and visionOS apps that use this format.
Setting Up
To use Replexica with .strings
files, configure your i18n.json
as follows:
{
"version": 1.2,
"locale": {
"source": "en",
"targets": ["es", "fr", "de"]
},
"buckets": {
"xcode-strings": {
"include": [
"MyApp/[locale].lproj/Localizable.strings"
]
}
}
}
TIP
Note the use of [locale]
in the path, which Replexica will replace with the appropriate locale code.
How It Works
The .strings
file is a simple key-value format that Xcode uses for localization. Each line in a .strings
file typically looks like this:
"key" = "value";
Replexica parses this format, translates the values, and generates new .strings
files for each target language.
Translating
To translate your .strings
files, run:
npx replexica@latest i18n
Replexica will process your source .strings
file and create or update the target language files.
Features
Comments: Replexica preserves comments in your
.strings
files.Special Characters: The loader handles escaping and unescaping of special characters like newlines and quotes.
Incremental Updates: Only new or changed strings are translated, saving time and processing power.
Example
Here's an example of a .strings
file:
// General
"greeting" = "Hello!";
"welcome_user" = "Welcome, %@!";
// Plurals (handled in .stringsdict)
"items_count" = "%d items";
// Formatting
"complex_format" = "User %1$@ has %2$d points and $%3$.2f balance";
Pro Tips
Pluralization: For plural forms, it's recommended to use
.stringsdict
files alongside.strings
. Replexica supports both formats.Consistency: Use Replexica's lockfile feature to ensure consistency across translations and prevent accidental changes to existing translations.
Integration with Xcode: After translation, you can directly use these
.strings
files in your Xcode project. Xcode will automatically use the correct file based on the user's language settings.Multiple Files: If your project uses multiple
.strings
files, you can include them all in youri18n.json
config:json"xcode-strings": { "include": [ "MyApp/[locale].lproj/Localizable.strings", "MyApp/[locale].lproj/InfoPlist.strings" ] }
Formatting: Replexica preserves the formatting of your
.strings
files, including spaces and line breaks.
By leveraging these features, you can maintain a robust, scalable localization setup for your Xcode projects using the traditional .strings
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 .stringsdict
files.