开发者

Localization of CFBundleDisplayName doesn't work whatever I try

开发者 https://www.devze.com 2023-01-29 05:33 出处:网络
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 con

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:

  • Triple checked spelling and capitalization
  • clean all
  • delete app from device and in simulator
  • delete user dir in simulator
  • changed the english app name in MyApp-Info.plist - that works.
  • reread whatever I could find in Apples documentation and lots of googling, confirming that it should work.

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.


In my case, my Xcode project only had localizations for:

  • English (Development Language)
  • Japanese

(and "Use Base internationalization" checked)

...but my InfoPlist.strings file only had localizations for:

  • Base
  • Japanese

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.


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.


I solved this problem today. You should use NSBundle's -localizedInfoDictionarymethod to get the dictionary, therefore you can get the localized string for CFBundleDislplayName

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号