I can't get my app to work with localization.
Localizable.strings
file and ticked the languages that I am localizing. (For now I have base, english and spanish.)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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With