Localization is created with String Catalogs, OS supports 40 languages today
You used to have to maintain Strings and StringDict in your project. In Xcode 15 you will have String catalogs to simplify the process
Will update my own app to this quickly. Complex editing is enabled to make it easier to convert strings, including ability to change strings by device.
Extract
- Localizable strings are simply text presented to user at runtime.
- Key (required) – usually the sting itself
- Default value – usually defaults back to Key
- String Comments – to provide translator context about where and how it is used
- Table corresponding to one ore more files where translations are stored. bY default this is Localizable table.
- String Catalog contains the entire string table in a single file. You can create multiple String Catalogs
- Xcode will create the catalog and try to keep it in sync.
- You should define you localizable strings as such with LocalizedStringResource
- Change build setting – Use Compiler to Extract Swift String to make sure that Xcode will extract for your, you can also define your own localized custom macros
- In Interface Builder strings are automatically defined as localizable.
- Add a info.plist to the catalog to capture values in plist files
- Every time you build Xcode will export to the catalog – code is source of truth and the catalog will reflect state of the localized value. It will be considered stale if removed from code an you have a translation defined.
Edit
- The editor allows for first class support of state and progress of translation.
- New – untranslated
- Stale – No longer seen in the code
- Needs Review – may require change
- Translated – Green check mark – no action needed
- Pluralization is a challenge
- You need to change the grammar in English
- But in other languages it may be more complex
- You used to need a StringDict file. New feature has built in value variations via context menu
- Complex examples like you have X items in X packages – which may change if you have 6 items in 1 package
- You define substitutions for items and packages in the prior statement
- You can define manual strings that are defined in code or a database
Export
- To work with translators – you can export localization catalog for each language so you can send to translation team.
- The xliff file is standard format for storing translations.
- There are some changes based on catalog instead of stringDict format, this may require automation tools to change
- Change make sure export works correctly set “Localization Prefers String Catalogs” in build settings to “Yes”
- Import will just add it back in correctly
Build
- During Build catalogs are json files under the hood and easily diffable in source code
- You can back deploy to any OS target
- Source strings are not stored in final build
Migrate
- To migrate your existing project, pick files and targets to migrate
- Right click and choose Migrate to String Catalog
- You must use swift tools version 5.9 or higher