0

I want change localisation my app from some page(for example: from page "Settings")?

but I don't sure if i do this app store reject my app!

so Question:

1 I can do this functionality? if yes, maybe you have some example?

2 Please, give me links on documents which permit or prohibit do this!

Vit
  • 936
  • 1
  • 10
  • 20
  • I know many app use the same language which use devices, but is some app use some functionality which change language into app. – Vit Apr 02 '13 at 11:07
  • http://stackoverflow.com/questions/1669645/how-to-force-nslocalizedstring-to-use-a-specific-language – Ramz Apr 02 '13 at 11:26

2 Answers2

3

Please find the below answers for your questions

1.Yes. You can implement it.

In our project we have added localizable strings for each languages. In the setting screen we have shown drop down to select the language for the application

for e.g

switch([indexPath row])//table row index selected by user
        {
            case 1:[[NSUserDefaults standardUserDefaults] setValue:@"french" forKey:@"language"];

                break;
            case 2:[[NSUserDefaults standardUserDefaults] setValue:@"german" forKey:@"language"];

                break;
            case 0:[[NSUserDefaults standardUserDefaults] setValue:@"english" forKey:@"language"];

                break;
            case 3:[[NSUserDefaults standardUserDefaults] setValue:@"Portuguese" forKey:@"language"];

                break;
        }

For the first time by default we have set the English language.After selecting the language we call the following function by passing key to it

-(NSString*) languageSelectedStringForKey:(NSString*) key
{
    //set = [[SettingsViewController alloc]initWithNibName:@"SettingsViewController" bundle:nil];
    NSString *path=@""; 
    NSString *currentLanguage=[[NSUserDefaults standardUserDefaults] valueForKey:@"language"];

    if([currentLanguage isEqualToString:@"english"])
    {
        path = [[NSBundle mainBundle] pathForResource:@"English" ofType:@"lproj"];

    }
    else if([currentLanguage isEqualToString:@"german"])
    {
        path = [[NSBundle mainBundle] pathForResource:@"de" ofType:@"lproj"];

    }
    else if([currentLanguage isEqualToString:@"french"])
    {
        path = [[NSBundle mainBundle] pathForResource:@"fr" ofType:@"lproj"];
    }

    else if([currentLanguage isEqualToString:@"Portuguese"])
    {
        path = [[NSBundle mainBundle] pathForResource:@"Portuguese" ofType:@"lproj"];
    }

    NSBundle* languageBundle = [NSBundle bundleWithPath:path];
    NSString* str=[languageBundle localizedStringForKey:key value:@"" table:nil];
    return str;
}

for e.g.

aboutUsTitle.text=[self languageSelectedStringForKey:@"AboutUs"];

where in the localizable file you have to set the following key values to get the About us value

"AboutUs" = "A propos de nous";//for french(fr.lproj)



"AboutUs" = "About Us";//for english(english.lproj)

2.http://kb.tethras.com/localizing-your-ios-app

Hope this will help you

svrushal
  • 1,612
  • 14
  • 25
0

yes you can achieve it, in some pages of your app. Folow this tutorial

Tutorial

and by this code you can translate your desired word in to desired language.

NSString *translatedString = [self languageSelectedStringForKey:@"YesButton"]; // Give your key here

-(NSString*) languageSelectedStringForKey:(NSString*) key
{
    NSString *path;
    path = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"]; // give your   language type in pathForResource, i.e. "en" for english, "da" for Danish
    NSBundle* languageBundle = [NSBundle bundleWithPath:path];
    NSString* str=[languageBundle localizedStringForKey:key value:@"" table:nil];
    return str;
}

Hope this helps., thank you. Happy coding.

Dhruvik
  • 984
  • 4
  • 18