As many people don't know, the way to localize an application name on iOS and OSX is to add an InfoPlist.strings
file to the bundle and localize that file. People mix this file with the Info.Plist
file. Localization is not done into the Info.plist
, is done in the InfoPlist.strings
file.
Said that, I have created this file with two keys: CFBundleDisplayName
and CFBundleName
, as I always do. This works wonderfully and you can define different names for your app in different localizations. This file works seamlessly. You have to do nothing, just add the file to the project and localize it.
InfoPlist.strings
is a strings file like this:
"CFBundleDisplayName" = "My Localized App Name";
"CFBundleName" = "My Localized App Name";
For this project in particular I have also to read the value of CFBundleDisplayName
at run time.
I have tried to use this code:
NSString *appName = [[NSBundle mainBundle] localizedStringForKey:@"CFBundleDisplayName" value:nil table:@"InfoPlist"];
to read the CFBundleDisplayName
key but the value I get back is CFBundleDisplayName
. In other words, I provide the key and receive the key back, not the value. I should receive My Localized App Name
.
What am I missing?
I did this exactly in Swift, and it works as expected.
let appname = NSBundle.mainBundle().localizedStringForKey("CFBundleDisplayName", value: nil, table: "InfoPlist")
but, if I delete de localisation string from the corresponding InfoPlist.strings
file, it returns "CFBundleDisplayName".
So, check that you are not missing something in your .strings
files
After trying several possibilities..
The BUG was "A second copy of InfoPlist.strings inside the project"