alvarolopez
alvarolopez

Reputation: 467

Localization not working on Xcode

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

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.

Upvotes: 6

Views: 5133

Answers (3)

funct7
funct7

Reputation: 3601

For anyone having a similar issue in the future:

Check if your *.strings file has any non-printed characters. I used JavaScript for a simple task and didn't realize it included some whitespace characters.

An easy way to check is to put the translation at the top of the file and see if it works. If it does, there might be some whitespace characters. The next steps are... binary search and remove the whitespace characters.

Upvotes: 0

sschmidTU
sschmidTU

Reputation: 132

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.

Upvotes: 1

Jay Versluis
Jay Versluis

Reputation: 2072

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.

Upvotes: 2

Related Questions