Reputation: 5150
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:
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?
Upvotes: 17
Views: 2499
Reputation: 5150
So I found the problem. 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.
Upvotes: 8
Reputation: 3661
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
Upvotes: 3
Reputation: 4259
If you specify table:nil
, then NSBundle
will try to fetch the localization from the default table (the one in SOMELANG.lproj/Localizable.strings
). If you have the localization
elsewhere, you should explicitly specify the table using table:@"File"
(or use the NSLocalizedStringFromTable()
macro in a similar manner:
NSString *value = NSLocalizedStringFromTable(@"key", @"File", nil);
Also,
Double check that the Localizable.strings
file is being added to
Targets -> BuildPhases -> Copy Bundle Resources
It hadn't been added automatically for me.
Upvotes: 1