Skip to content

Internationalization

Eric Lavigne edited this page Apr 25, 2020 · 1 revision

Any text visible to the user should be translated into the phone's preferred language. Follow this process to add text to the app that should be translated.

  1. Add the English version to Localizable.strings.

Select a 'code' to represent that text programmatically, and add both the code and the English version of the text to CoEpi/en.lproj/Localizable.strings.

  1. Generate an enum representation using SwiftGen.

SwiftGen will translate the codes from CoEpi/en.lproj/Localizable.strings into enums in CoEpi/generated/strings.swift.

Install SwiftGen on your computer with the following commands:

brew update
brew install swiftgen

Run SwiftGen with the following commands:

cd CoEpi
swiftgen
  1. Reference the enum from the application.

When using the translatable text from a .swift file, just refer to the enum. If you type "L10n." then auto-complete will help with the rest.

  1. (optional) Provide translations to other supported languages.

This step is optional because the app will fall back to showing the code any time a translated version is unavailable. As long as you followed the previous steps, someone who knows the language can easily add a translation later.

Copy the new code/translation pair from CoEpi/en.lproj/Localizable.strings to one of the matching files for a supported language, such as CoEpi/es.lproj/Localizable.strings. Keep the left part (code) the same and translate the right part.

Clone this wiki locally