Reputation: 3136
could someone give me an idea how to find the problem. I have an app named "MyApp". I would like to localize the app name to German. I have a directory de.lproj in the main project directory. It contains a file Localizable.strings and that works fine. I added a InfoPlist.strings file and in there I put:
CFBundleDisplayName = "Applikationsname";
But it wouldn't show the translated name, it stays on "MyApp". Here is what I tried so far:
Whatever I tried, the app name is the one from MyApp-Info.plist. I also log this in the app delegate:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
NSString *currentLanguage = [languages objectAtIndex:0];
NSBundle *bundle = [NSBundle mainBundle];
NSDictionary *info = [bundle infoDictionary];
NSString *prodName = [info objectForKey:@"CFBundleDisplayName"];
NSLog(@"Product Name:%@",prodName);
NSLog(@"Current Locale: %@", [[NSLocale currentLocale] localeIdentifier]);
NSLog(@"Current language: %@", currentLanguage);
Output is:
2010-12-08 12:51:00.886 MyApp[25148:207] Product Name:MyApp
2010-12-08 12:51:00.946 MyApp[25148:207] Current Locale: de_DE
2010-12-08 12:51:00.946 MyApp[25148:207] Current language: de
So the language setting is correct, but the app won't read the InfoPlist.strings file? Any ideas how to continue from here?
Thanks in advance for any reply.
Upvotes: 3
Views: 3957
Reputation: 16246
In my case, my Xcode project only had localizations for:
(and "Use Base internationalization" checked)
...but my InfoPlist.strings file only had localizations for:
As soon as I added an English version of the file, it started to work. Before that, the app icon would display the Target Name (Product Name) no matter what I tried.
I was under the assumption that "Base" serves as the default (i.e., "all languages not supported explicitly"), but it seems the actual behavior is more complicated...
Hope this helps someone.
Upvotes: 4
Reputation: 1104
I solved this problem today. You should use NSBundle
's -localizedInfoDictionary
method to get the dictionary, therefore you can get the localized string for CFBundleDislplayName
Upvotes: 1
Reputation: 3136
Ok, it seems to work finally. I guess I created the InfoPlist.strings the wrong way: Choosing strings file from the Resources tab and specifying de.lproj as destination folder.
After deleting the file and creating a new one in the project root directory, then creating localizable versions did the trick. If anyone stumbles upon this, note that you have to edit the corresponding file in en.lproj as well.
Upvotes: 1