By Kevin Hou
3 minute read
Go to the project page → Localizations → Add a new language and select all the resources. Sometimes the storyboards aren’t all localized. If that’s the case, you must manually localize storyboards. To do this, on the info panel on the right, can press localize and add the languages you want.
This is for hard coded strings in the code. You can wrap them in: NSLocalizedString(String, comment: String).
For instances where you have hard coded strings and variables within the hard coded strings, you must use the String format setup. For example:
1// Old setup:
2let localizedString = NSLocalizedString("Test Results - \(interval)", comment: "Test results")
3
4// New setup:
5let localizedString = String.localizedStringWithFormat(NSLocalizedString("Test Results - %@", comment: "Test results date string"), interval)
6
The "%@" represents a placeholder in the String that will not be translated into another language, and can therefore be used as a bookmark to inject a variable into a localized string.
To Export:
Delete Localizable.strings in parent so that there's no duplicate.
Change the .xliff file (found it useful to use a simple IDE like Atom or Sublime to quickly change text. I added in 'French: ' at the beginning of every translation so that I would know when the app recognizes a NSLocalizedString type).
Import the .xliff file.
Add the newly created Localizable.strings file (in the parent) to the build phases (Target --> Build Phases --> Copy Bundle Resources --> Add) — Reference.
Build and run.
Localize the Localizable.strings file and replace the content with the translations for that specific language.
Typically denoted by a \n in the code.
It doesn't format correctly in the .xliff file.
When you import it back into the project, it won’t recognize your translation. Instead, modify the Localizable.strings file directly. Syntax as such:
"{Original…}\n{Original…}"="French: {Original…}\n{Original…}"
You must add in the \ns because Swift exports the \ns as actual line breaks, but doesn’t convert the line breaks back into \ns on import.
Change \n to another placeholder like [[n.
Before it is injected into the frontend, replace all instances of [[n to \n.