1

In my iPhone app, I can successfully change language inside the app's Settings (just the user have to restart the app). I use the trick mentioned in this post: link. I made some modification. I store the selected language in NSUserDefaults, and in main.m:

int main(int argc, char *argv[]) {

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    if ( [[NSUserDefaults standardUserDefaults] objectForKey:@"language"] == nil ) {
        [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"hu"] forKey:@"AppleLanguages"];
    } else {
        [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"language"]] forKey:@"AppleLanguages"];
}

    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

The "default" Info.plist file is in english, I placed it in the root of the project. I made a hungarian translation of this, because of app name. This file is InfoPlist.strings, and I placed it in hu.lproj folder. In this file:

CFBundleDisplayName = "Sör";

If I change the language, after restart the app, everything is work fine (nib files, strings), except of app name. It doesn't change...

Can someone tell me what is the problem?

Community
  • 1
  • 1
madik
  • 133
  • 2
  • 10

2 Answers2

1

You have done almost everything you need to do.

You also need to instruct your app that it has a localized app name. You do this by adding the following key to your app's info.plist

LSHasLocalizedDisplayName

set it's type as boolean and it's value to true.

Once you have done this, your app should localize it's name.

You can read more here

EDIT:

One more thing you need to do is create an InfoPlist.strings file in the en.lproj folder and add the same key to it with the English equivalent

CFBundleDisplayName = "<Replace Me>";

Credit for this addition goes to this link

Community
  • 1
  • 1
  • Yes, you right, but doesn't happen anything, if I add this key to Info.plist. And in the documentation, what does it mean: " The functions that access localized display name information check for the existence of this key before retrieving the information"? – madik Jun 28 '11 at 13:16
  • I have a question in connection of your edited answer. I mentioned, I have an Info.plist file at the root of the project, and in the build settings, I point to that file. In this file, there is a key too for the name of the app. Till this time, I have only one InfoPlist.strings file in the hu.lproj folder, and I added this file to the project. Now I have to localize this file (and the result of this 'operation' would be that, there will be two InfoPlist.strings files in the right folders)? – madik Jun 29 '11 at 06:47
  • I made this change, but the app name doesn't switch to the selected language...the device always displays the english name :S – madik Jun 29 '11 at 06:57
  • Did you read through the link I posted on my edit, as it seems that person was able to achieve exactly what you're trying to? –  Jun 29 '11 at 07:27
0

Well the app name is read by iOS which is not set to the language that your app is set to. So it will display the name of the app which is set for the system language.

rckoenes
  • 69,092
  • 8
  • 134
  • 166
  • This is not *strictly* true, please see my answer –  Jun 28 '11 at 11:41
  • True, but will it change if you only change the language via code and not set the OS language? Eq. if my iPhone is in english and via code I change my app to dutch will the OS display the app name in dutch or in english. Since you tell the os that the DisplayName is localized I thought that it would read the display name of the language of the OS since the app language is only set after run it. – rckoenes Jun 28 '11 at 11:44
  • To be honest I'm not sure what will happen in this instance as I've only ever localized an app in the usual manner (*i.e reflecting the system wide language choice*). On second thoughts you may be right, and you may not be able to get the app name to reflect an in-app language change but on the other hand it's quite possible the app name may change for the lifetime the app is running in it's alternate language. I suppose the best way to find out is to give it a go. –  Jun 28 '11 at 11:57