Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localization not working on Xcode

I can't get my app to work with localization.

  • I have created a Localizable.strings file and ticked the languages that I am localizing. (For now I have base, english and spanish.)
  • Localized storyboard with three languages.
  • In Project settings > Info I checked Use Base internationalization and all languages are correctly added. (Moreover, beside the language it shows 2 Files Localized, which I guess they must be the storyboard and .strings file.

I am using this example for testing:

self.loginLabel.text = NSLocalizedString(@"login", @"Login text info");

This is how the Localizable.strings (Base) file is looking like:

"login" = "Log in";

However, it is not working and instead it is showing login. Have I forgotten a key step?

BTW: I have tried already changing the login text just it case something was overriding the label.

like image 473
alvarolopez Avatar asked Oct 20 '22 04:10

alvarolopez


2 Answers

Those are the steps indeed, I don't think you've left anything out. I usually set the comment to nil instead of another NSString though - not sure if that makes a difference.

However, rather than in only base, make sure you're adding the same line also to the English and Spanish files (obviously translated as appropriate).

Next, for the language to show up, set the device to said language. Close your app and start it again. Strings should now show up in the other language.

Note that the Simulator often has trouble with new translations, especially when they've been added to an already deployed app. In that case, remove the app from the Simulator, click on Product - Clean, and re-deploy.

like image 134
Jay Versluis Avatar answered Oct 22 '22 21:10

Jay Versluis


In my case, it didn't work because the UILabel text was set as "Attributed" instead of "Plain" in the Attributes Inspector.

Localization with a .strings file doesn't seem to work on Attributed strings.

I even had a storyboard with mixed Plain and Attributed string labels, and the localization only worked on the Plain ones.

like image 44
sschmidTU Avatar answered Oct 22 '22 22:10

sschmidTU