Prepare your app for localization
String(localized:) to mark localizable strings in your codebase.
Text elements in SwiftUI are automatically marked for localization.
- Use the
comment property on
Text to provide relevant context. This will help the language model and professional translators produce more accurate translations.
- Use the
verbatim property on
Text elements that don’t need to be localized to omit them from the string catalog.
- We recommend using the string catalog feature available starting in Xcode 15. Select File → New → File…, scroll down and select String Catalog. To localize strings in
Info.plist, create another string catalog with the file name
- In the string catalog, use the plus icon in the lower left to add the languages for which you want to localize your app.
- Build your app to update the string catalog.
- Check the string catalog for strings that have been split into fragments due to interpolation. In such cases, it makes sense to keep strings in your code in one piece instead of composing them dynamically, at the expense of having more repetition in your code. This will help the language model and professional translators produce more accurate translations.
For more information, see Apple’s documentation:
Export localization files from Xcode
- In the Product menu, select Export Localizations…, and save the localizations folder.
Import localization files into Local Hero
- Create a new project in Local Hero if you haven’t already.
- Navigate to your project in Local Hero, select File → Import…, and select the exported localizations folder. You can also select one or several
.xcloc files inside the folder to only import certain languages.
- Local Hero uses the OpenAI API to produce translations. Create an OpenAI API key if you don’t have one already.
- In your project, select Translate → API keys…, and enter your API key. Your key is stored locally in your browser.
- To provide custom instructions to the language model, select Translate → Custom instructions…. For example: “The app’s name, Watchful, should be kept in English.”
- Use the options in the Edit menu to select the strings you want to translate.
- Use the options in the Translate menu to translate your strings. Keep your browser window open while the translation is in progress.
- You can edit the strings in the Target column by clicking on them.
- To verify the translations, select the strings you want to check and use the Back translate options in the Translate menu. This will translate the translations back to the source language in a separate column.
- To allow someone else to edit the translations, select File → Share link to edit [language]. Anyone with the link can edit the translations for the selected language.
- When you’ve finalized the translations, change their state to translated. Only strings marked translated will be imported into Xcode.
Export translated files from Local Hero and import into Xcode
- Use the Export options in the File menu to export localization files for individual languages or all the languages in your project.
- If you’ve exported all the languages in your project, you’ll need to unzip the exported file.
- In Xcode, select Product → Import Localizations…, and select the
.xcloc files that you exported from Local Hero.
- After confirming the changes, the translations from Local Hero should appear in the string catalog.
Android Studio, Next.js, SvelteKit, …
Want to be notified when support for other platforms is added to Local Hero? Subscribe to our (infrequent, short) newsletter, and
let us know what plaforms you use.