Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App localization showing the key instead of the value in iOS

I've been using localization in my app, but for some reason, some of the strings (not all of them) won't translate, I see the key instead the value. I've tried to check if the app finds the localization files by doing this:

NSString *enPath = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];
NSString *hePath = [[NSBundle mainBundle] pathForResource:@"he" ofType:@"lproj"];
NSString *ruPath = [[NSBundle mainBundle] pathForResource:@"ru" ofType:@"lproj"];
NSString *esPath = [[NSBundle mainBundle] pathForResource:@"es" ofType:@"lproj"];
NSString *frPath = [[NSBundle mainBundle] pathForResource:@"fr" ofType:@"lproj"];
NSString *arPath = [[NSBundle mainBundle] pathForResource:@"ar" ofType:@"lproj"];

And none of them is nil.

I've checked the name of the localization file and it's Localizable.strings as it should be. Also checked if the key exists inside the Localizable.strings files and it does.

I've also tried:

  • Empty Cache
  • Cleaning all targets
  • Delete Derived Data folder
  • Restart
  • Reset simulator
  • Convert to UTF-16
  • Remove all localization files and recreate them.

Also tried to do everything that is in this question.

It's important to say that this is not just a Simulator/Cache problem. It's also showing on devices which download the app. (I have Enterprise account).

What more can I do in order to identify nor fix the problem?

like image 866
ytpm Avatar asked Dec 14 '15 10:12

ytpm


2 Answers

So I found the problem, I guess who translated the Localizable.strings files for me is an asshole. In 4 places in my strings file there was a row as followed:

"KEY" ;= "Value"

This line cause some kind of a crash, but let the compiler to build successfully for some reason. That's why I couldn't find the bug, only when I decided to take the last Key and Value which are not translate and move them to the top of the Localizable.strings file. Then I was able to understand and see that the problem is somewhere in the middle of the file and the top Keys and Values are translated fine.

like image 126
ytpm Avatar answered Sep 28 '22 06:09

ytpm


One thing that you can do catch these kind of errors is to make a copy of the strings file, change the extension to plist and try to open it in Xcode. If there is any problem in the strings file it will show in Xcode since the dictionary will contain only the keys till the point where there is an error. You can then do a Find operation and find the error until you are sure that all strings appear in the plist file. You can then rename the file back to .strings

enter image description here

like image 23
Pradeep K Avatar answered Sep 28 '22 07:09

Pradeep K