The introduction of .xcstrings
format marks a significant improvement in how we handle localizations in iOS and macOS development. Let’s dive deep into what makes this new format special and why you should consider using it.
What is XCStrings?
XCStrings is Apple’s new localization format that replaces the traditional .strings
and .stringsdict
files. It’s a JSON-based format that combines the functionality of both previous formats into a single, more maintainable file.
Key Benefits
- Single File Management: Instead of managing multiple
.strings
files, all languages are contained in one.xcstrings
file - Built-in Plural Support: No need for separate
.stringsdict
files - Better Version Control: JSON format makes it easier to track changes and resolve conflicts
- IDE Support: Rich editor support in Xcode with inline warnings and errors
Structure of an XCStrings File
{
"sourceLanguage" : "en",
"strings" : {
"welcome_message" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Welcome to the app!"
}
},
"it" : {
"stringUnit" : {
"state" : "translated",
"value" : "Benvenuto nell'app!"
}
}
}
},
"files_count" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"variations" : {
"plural" : {
"one" : {
"stringUnit" : {
"state" : "translated",
"value" : "%d file"
}
},
"other" : {
"stringUnit" : {
"state" : "translated",
"value" : "%d files"
}
},
"zero" : {
"stringUnit" : {
"state" : "translated",
"value" : "No files"
}
}
}
}
}
}
}
},
"version" : "1.0"
}
Migration from .strings to .xcstrings
Xcode provides built-in migration tools to convert your existing .strings
and .stringsdict
files to the new format:
- Select your
.strings
file in Xcode - Choose Editor > Export Localizations
- Choose Editor > Import Localizations with the new format
Managing XCStrings with LocalizApp
LocalizApp fully supports the new .xcstrings
format, making it even easier to manage your localizations:
- View and edit all languages in one place
- Automatic plural forms management
- Easy migration from older formats
- Instant validation of your strings
- One-click translation with DeepL or Google Translate
Best Practices with XCStrings
- Organization:
// Group related strings with prefixes
"login.title" = "Welcome";
"login.username" = "Username";
"login.password" = "Password";
- Comments and Context:
/// Used in the main welcome screen
"welcome.title" = "Welcome";
- Variable Handling:
// In code
String(localized: "welcome.user \(name)",
comment: "Greeting for user")
// In xcstrings
"welcome.user" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Welcome, %@!"
}
}
}
}
Debugging and Validation
XCStrings provides better error detection:
- Missing translations are clearly marked
- Format string mismatches are caught at compile time
- Invalid plural rules are highlighted
Conclusion
The .xcstrings
format represents a significant step forward in iOS and macOS localization. It simplifies management, reduces errors, and provides better tools for developers. Combined with LocalizApp, it makes handling app localizations more efficient than ever.
Ready to modernize your app’s localization? Download LocalizApp from the Mac App Store and experience the power of modern localization management with full .xcstrings
support.