Reputation: 4734
I have created the strings files for a few languages and added texts to them. The spanish file, for example, is called Main.strings (Spanish) and I have added two texts to it. The first one to apply the translation to a label in the interface builder (it works) and the other one to print in the viewdidload method (it doesn't work).
"yFi-2X-1s7.text" = "hola";
"lb-hello" = "hola";
What I mean with "it doesn't work" is that the text that is being printed is lb-hello instead of hola
This is the code I'm using to print the text:
NSLog(NSLocalizedString("lb-hello", comment: "Hello translated"));
Any idea about why the translation only works through the Interface Builder? Am I missing something?
Upvotes: 2
Views: 179
Reputation: 4734
Okay, I found the answer to my own question.
Apparently, if the strings file is called Main.strings (Spanish) it works to localize label IDs but not to create new variables and apply them through code.
To do be able to create new ones and use them in the code, you have to rename each file and replace Main for Localizable. So the file name for Spanish has to be Localizable.strings (Spanish)
Upvotes: 1