iOS Localization
Localize an iOS application: keep the strings in a String Catalog (.xcstrings) or in .strings and .stringsdict files, translate them in Soluling, and let Soluling write the localized resources that Xcode builds into your application.
Soluling reads a resource file, or the whole Xcode project to also localize storyboards, images, and other resources. It shows plurals in a pattern editor, checks the placeholders, and writes the translations into the String Catalog, or each language into its own .lproj folder. Translate in Soluling Desktop or, for .strings, .stringsdict, and .xcstrings files, in a browser with Soluling Cloud. The same steps localize a macOS application.
- Input
- The Xcode project (
project.pbxproj), resource files (.strings,.stringsdict), or a String Catalog (.xcstrings) - Output
- Localized resources in language folders (
fi.lproj\Localizable.strings), or the translations in the String Catalog itself - Runtime
- iOS uses the resources of the user's preferred language, with no code
- Cloud
- Upload
.strings,.stringsdict, and.xcstringsfiles to Soluling Cloud directly; storyboards and images need Soluling Desktop
On this page
- Tutorial: localize an iOS application step by step
- How iOS localization works
- String Catalogs
- Comments for translators
- Right-to-left languages
- Test in another language
- Translate in Soluling Cloud
- Update the translations over the air
- Do and don't
- Typical localizability problems
- Troubleshooting
- Samples
- FAQ
Localize an iOS application, step by step
Six steps take the application from hard-coded English to one multilingual application.
Prepare: move the strings to resources
Strings in the code can't be localized. A typical problem looks like this:
label.text = "Hello World"
countLabel.text = "\(count) files"
Internationalizing the application takes three changes:
-
Read the strings with
NSLocalizedString. Xcode extracts them intoLocalizable.strings, or into a String Catalog with Xcode 15 and later. In SwiftUI,Text("Hello World")is already localized, because a string literal is a localized string key. -
Use base internationalization. Keep the storyboards and
.xibfiles inBase.lproj. Xcode writes their texts into a.stringsfile for each language, such asfi.lproj\Main.strings, and Soluling translates those files. You keep only one set of user interface files. -
Use a plural rule for counts. Add a
Localizable.stringsdictfile, or plural variations in a String Catalog, and format the string withString.localizedStringWithFormat. Other languages have other plural forms.
label.text = NSLocalizedString("Hello World", comment: "This is a comment")
countLabel.text = String.localizedStringWithFormat(
NSLocalizedString("files", comment: "Number of files. %d is the amount"), count)
Add: choose the resource files or the project
Soluling localizes an iOS application in two ways:
| Resource file | Project file | |
|---|---|---|
| You add | en.lproj\Localizable.strings, a .stringsdict file, or a String Catalog (.xcstrings) |
The Xcode project: Sample.xcodeproj\project.pbxproj |
| It localizes | Strings and plurals | Also the storyboard and .xib strings, images, audio, and other resources |
| New resource files | You add each file to the project | Soluling finds them |
| Where | Soluling Desktop or Soluling Cloud | Soluling Desktop |
Use the project file if you have the full Xcode project: it finds every resource, including the strings of the storyboards. Use the resource file if you only need the strings, or want to use Soluling Cloud. Soluling Desktop runs on Windows, so make the folder of the Xcode project visible on Windows, such as a shared Mac folder or a cloned repository. On Windows, Sample.xcodeproj is a folder, and project.pbxproj is the file inside it. Drag and drop the file on Soluling, and Project Wizard starts.
- With the project file, select the resource types on the Resources sheet.
- Select the original language and the target languages, and complete the wizard. If the project already has translations, Soluling imports them.
- A String Catalog is added as its own file, also when you localize the project. See String Catalogs.
Translate: strings, plurals, and images
Each string is a row in the grid, identified by its key, such as Hello World. A storyboard string is identified by its object ID and property, such as r8V-Nr-Axy.text, and its comment tells the class and the original text. Plurals open in the pattern editor, which shows the plural forms that each target language needs, such as one and other in Finnish and only other in Japanese. With the project file, you can also replace images and other files for each language. See Comments for translators to give translators more information.
- Machine translation and translation memory. Click Use Machine Translation to translate with Amazon, Claude, DeepL, Google, Microsoft, ModernMT, or MyMemory, and reuse earlier translations from translation memory and terminology.
- External translators. Send a translation package, an Excel file, or XLIFF to a translator, and import the results back. See teamwork.
- Translators in a browser. Upload the project to Soluling Cloud and let translators work in Translate.
Check: find problems before release
- Pseudo translation. Click Translate | Pseudo Translations | Fill, build, and run the application. Pseudo translations are longer and use accented characters, so texts that don't fit and strings still in the code (shown in plain English) stand out. See pseudo translation.
- Validation. Soluling validates translations while you type and in batch (Validation | Validate Translations): missing translations, inconsistent placeholders and patterns, duplicate hotkeys, and more. See validation.
Validation knows the Apple placeholders: %@ for an object or a string, %1$@ with a position, and %#@files@ for a plural rule. A translation that drops or changes one of them is an error.
Build: create the localized resources
Choose Home | Build All. Soluling writes the localized resources into your project, in a .lproj folder for each language. Soluling doesn't add the languages to the Xcode project: add each language once in Xcode. Select the project, open Info, click + under Localizations, and choose the language. When Xcode asks which files to localize, keep them all selected.
Adding a language makes Xcode write its own .strings files for that language, so choose Home | Build All in Soluling again after you add languages. A new resource file needs the same once: select it in Xcode, click Localize in the File inspector, and check the languages; if Xcode says the file already exists, click Use file. Then build the application in Xcode. If a translation doesn't show, choose Product | Clean Build Folder and build again, because Soluling changed the files without Xcode knowing it. Soluling doesn't sign anything: you sign the application when you archive it.
Update: translate only what changed
When the resources change, click Home | Scan. Soluling keeps the existing translations, adds the new strings, and marks the rows whose original text changed. Rows are matched by the key, so keep the keys stable. Translate the new rows, build, and rebuild the application. You don't import or export anything in Xcode. Add the scan and build steps to your build pipeline with SoluMake or, with Soluling Cloud, SoluCLI.
Language folders choose the language
An iOS application keeps its localized resources in .lproj folders named by the language: fi.lproj holds the Finnish files, and Base.lproj the storyboards of base internationalization. All the languages are built into one multilingual application. iOS goes through the user's preferred languages in order and uses the first one that the application has, or the development language if there is none. You write no code for it.
A string that is missing from fi.lproj\Localizable.strings shows its key, which is why the key is usually the English text. A storyboard string that is missing from fi.lproj\Main.strings shows the text of the storyboard.
String Catalogs
Xcode 15 and later can keep the strings in a String Catalog (Localizable.xcstrings) instead of .strings and .stringsdict files. Xcode adds every NSLocalizedString and SwiftUI string to it when it builds. One JSON file holds all the languages, the comments, and the plural and device variations.
Add the .xcstrings file to Soluling Desktop or Soluling Cloud as its own file, also when you localize the Xcode project: the project method reads the .strings and .stringsdict files. Soluling imports the existing translations, shows the plural variations in the pattern editor, and a string that varies by device as a row for each device. The build writes the translations of every project language into the same file, keeping its formatting. Add the languages to the Xcode project as with .strings files.
Comments for translators
The comment of NSLocalizedString goes into the strings file or the String Catalog, and Soluling shows it as the row's comment. Tell what the string is and what each placeholder holds. A comment can also set a maximum length that validation checks:
NSLocalizedString("Calculate", comment: "Button that calculates the time MaxChars=12")
/* Button that calculates the time MaxChars=12 */
"Calculate" = "Calculate";
Right-to-left languages
iOS mirrors the user interface in Arabic and Hebrew if the layout lets it. In Auto Layout, use leading and trailing constraints instead of left and right; SwiftUI uses leading and trailing already. Use .natural text alignment, so that text aligns to the start of the line in every language.
Test in another language
In Xcode, choose Product | Scheme | Edit Scheme, select Run, and set App Language on the Options tab. You can also choose the Double-Length Pseudolanguage to find texts that don't fit, and the Right-to-Left Pseudolanguage to check the mirrored layout. On a device or in Simulator, add the language in Settings | General | Language & Region, or change the language of one application in its own page of Settings.
Translate in Soluling Cloud
With Soluling Cloud, translators use Translate in a browser. How you start depends on what you localize:
- Strings and strings dictionary files (
.strings,.stringsdict). On the dashboard, add a project, selecten.lproj\Localizable.strings, and choose iOS/macOS strings file as the source type. Translators work in Translate; click Build localized files, and save each download to the folder of its language, such asfi.lproj\Localizable.strings. When the application changes, upload the new file; the existing translations are kept. String Catalogs (.xcstrings). Choose iOS/macOS String Catalog as the source type. One file holds every language, so Build localized files gives back the whole catalog: replaceLocalizable.xcstringsin the project with it. - Storyboards, images, and other resources. These need Soluling Desktop, and Soluling Cloud can't read an Xcode project itself. Create the project in Soluling Desktop, and choose Translate | Configure Cloud to upload it. Use Import from Cloud to get the translations back and build the localized files locally. Your application files never leave your machine.
To run the scan, upload, import, and build steps in your build pipeline, use SoluMake. See the Cloud tutorial and workflows.
Update the translations over the air
When you translate in Soluling Cloud and publish the project's files, SolulingOta of Soluling's Swift package gets new translations to your users without a new release. Once a day, it downloads the changed strings files of the user's language, such as fi.lproj/Localizable.strings and .stringsdict, or the String Catalog, and keeps them in the application's Application Support folder. Without a connection, or before the first download, the strings built into the application are used as before. The package needs iOS 13 or macOS 11 or later.
In Xcode, choose File | Add Package Dependencies, enter https://github.com/soluling/I18N, and add the SolulingOta library to the application target. Initialize it when the application starts, with the project's GUID from its Manage page:
import SolulingOta
@main
struct SampleApp: App {
init() {
SolulingOta.initialize(projectGuid: "1b6e2f0a-4c2d-4e9a-9f1a-0123456789ab")
}
var body: some Scene {
WindowGroup { ContentView() }
}
}
The package takes over the string lookup of the main bundle, so NSLocalizedString, String(localized:), and String.localizedStringWithFormat with the plurals of a .stringsdict file or a String Catalog return the downloaded strings. A downloaded String Catalog is converted to strings files on the device, as Xcode does when it builds the application. A downloaded string is used only if it has the same placeholders as the built-in one, so a translation made for a newer version of the application can't break an older one. Strings of other bundles, such as frameworks, keep the built-in ones.
New translations are used from the next time a string is read; the texts already on the screen don't change. To show them at once, set onUpdated of SolulingOta.Options and reload the user interface. Call SolulingOta.update(force: true) to check at once. See over-the-air updates for how publishing works.
Do and don't
Do
- Read every string the user sees with
NSLocalizedString, or use SwiftUI's localized string keys. - Use base internationalization for storyboards and
.xibfiles. - Use a
.stringsdictfile or plural variations, withString.localizedStringWithFormat, for counts. - Write a comment for every string, and tell what each placeholder holds.
- Add each language to the Xcode project once, and build again in Soluling after that.
- Pseudo-translate before the first real translation.
Don't
- Hard-code strings, or build sentences from pieces in the code.
- Choose plural forms with
ifstatements; other languages have other rules. - Format a plural with
String(format:); it doesn't apply the plural rule. - Change a key after translation starts; the key identifies its translation.
- Use left and right constraints if you support right-to-left languages.
Typical localizability problems
See also internationalization and pseudo translation.
| Problem | How it shows | Find and fix |
|---|---|---|
| Strings in code | English text in a pseudo-translated build | Read them with NSLocalizedString. |
| Sentences built from pieces | Word order and grammar are wrong in the translation | Use one string with placeholders, such as %1$@ and %2$@. |
| Plural forms in code | Grammar is wrong for some counts | Use a .stringsdict file or plural variations. |
| Fixed sizes | Clipped text in the pseudo or German build | Use Auto Layout, and let labels grow with their text. |
| Text in images | The image stays in English | Keep the text in strings, or replace the image per language with the project file method. |
Troubleshooting
| Symptom | Likely cause | What to do |
|---|---|---|
| The application stays in English | The language isn't added to the Xcode project, or the application wasn't built again | Add the language under Localizations, choose Product | Clean Build Folder, and build again. |
| The translations turned back to English | Xcode wrote its own files when you added a language | Choose Home | Build All in Soluling again. |
| A storyboard isn't translated | The storyboard isn't localized in Xcode | Select it, click Localize, choose Base, and check the languages. |
A count shows the wrong plural form, or %#@files@ |
The string is formatted with String(format:), or the .stringsdict file isn't in the application |
Use String.localizedStringWithFormat, and check that the file is in the target. |
| A new string isn't translated | The string wasn't scanned | Click Home | Scan, translate, build, and rebuild the application. |
| Soluling can't open the project | Sample.xcodeproj was selected |
Select project.pbxproj inside it; on Windows, the project is a folder. |
Samples
The samples are in Samples\iOS of the Soluling installation and on GitHub:
- Sample: a Swift application with strings, a storyboard, a localized image, and Finnish, German, and Japanese translations. It has a Soluling project for the Xcode project. Try this first.
- Multilingual: an application with existing translations in seven languages, which Soluling imports.
- Plural: plural messages in Swift with a
.stringsdictfile. - PluralSample: plural messages in Objective-C.
- SwiftImage and Image: localized images in Swift and Objective-C.
See iOS and macOS localization in the Desktop documentation for all the details.
FAQ
.xcstrings file as its own file. See String Catalogs..strings, .stringsdict, and .xcstrings files. Upload them to Soluling Cloud, translate in Translate, and download the localized files. See Translate in Soluling Cloud..lproj folders, strings files, and String Catalogs.Related
- iOS and macOS localization - the full Desktop documentation
- Resources - the resource types of an Xcode project
- Patterns - plurals, genders, and selects
- Supported formats - everything else Soluling localizes