AppCode 2019.2 Help

Internationalization and localization

Internationalization (i18n) refers to the process of extracting strings from source code and presenting them as properties with a set of values.

Localization (l10n) refers to the process of translating values of these properties into target languages.

AppCode provides helpful features that simplify working on software internationalization and localization issues. These features include advanced editing assistance for strings files, intention actions and quick fixes related to internationalization issues.

Strings files

In AppCode projects, strings that need to be localized are stored in text files with the .strings extension — strings files. These files contain pairs of keys and values that can be accessed and rendered in the UI.

In a project, there is at least one strings file for each locale (you can add new locales in Xcode). The strings files reside in the .lproj directories, for example, en.lproj, es.lproj. In the Project view of the Project tool window, localizable files are shown as groups of language-specific resources.

Project view

Files view

Strings files in Project view
Strings files in Files view

Extract values to strings file

  1. In the editor, place the caret at a string literal that you want to localize.

  2. Press ⌥⏎, select Localize the string, and press .

AppCode will replace the string literal with the NSLocalizedString macro.

The string will be added to the Localizable.string file for all available locales. If there is no file with such name in your project, a dialog opens where you can choose the location for Localizable.string, and AppCode will add this file to the project.

Provide localization for NSLocalizedString

To add localization for a string used in the NSLocalizedString macro, do the following:

  1. Place the caret at the first parameter of the NSLocalizedString macro.

  2. Press ⌥⏎, select Provide localization for "<string>", and press .

Provide localization intention action

The string will be added to the Localizable.string file. If there is no file with such name in your project, a dialog opens where you can choose the location of Localizable.string, and AppCode will add this file to the project.

Delete unused localized strings

Unused strings are grayed out in the strings file. To delete such strings, do the following:

  1. Place the caret at the grayed out string.

  2. Press ⌥⏎, select Safe deleted localized string '<string>', and press .

  3. In the dialog that opens, choose if you want to search for the string usages in comments and text contents. If any usages are found there, the Find tool window will appear. Check the search results and click Do Refactor to finish the operation.

Delete localized string quick-fix

Change application language and region

You can change the language and region of your application at runtime:

  1. From the main menu, select Run | Edit Configurations or choose Edit Configurations from the selector on the run/debug toolbar.

  2. In the dialog that opens, select your run/debug configuration or create a new one.

  3. Open the Options tab and select a language and region in the corresponding fields.

    Change application language

Last modified: 10 October 2019