My notes on adding localization to an iOS app
Setup:
- Create the Localization.strings file from file -> strings file
- Click the .strings file and in the right pan, click localize
- Click the .strings file again and you can now add sub-languages
- In scehme, add spanish etc.
- Add language content, see the format paragraph:
Format:
In the sub .strings file name …spanish.strings add:
"Freedom" = "Libre";
"The world" = "El mundo";
Example:
/**
* Localization
*/
extension MainTabBarController {
/**
* Testing loalization
* ## Examples:
* Swift.print("testTitle: \(NSLocalizedString("Bookmarks", comment: ""))")
*/
func testLocalization() {
let preferredLanguage = NSLocale.preferredLanguages[0]
if preferredLanguage == "en" {
print("👌 this is English")
} else if NSLocale.preferredLanguages[0].range(of: "es") != nil {
print("👌 this is spanish")
}
}
}