0

I was working with language localisation .I want to change the language of my application whenever i select a language from a drop down list which is present in my application , that is it should change the language without changing the language of device .please suggest me how can i implement

Thanks in advance

sujay
  • 1,845
  • 9
  • 34
  • 55
  • 1
    As always, consider whether it's both in your users' interest and worth your time to circumvent the standard system behavior here. – Ben Zotto Jul 06 '11 at 14:02

4 Answers4

2

Have a look at this: How to force NSLocalizedString to use a specific language

Community
  • 1
  • 1
Dunja Lalic
  • 752
  • 13
  • 26
  • hey i followed your link, its really helpful partly.In one example they are selecting a language on click of a button , but my doubt is can i set it through a pickerview ,i.e on selecting from the list in pickerview the language should change – sujay Jul 07 '11 at 04:30
  • Have an array of country codes like @"it", @"de" and use it to fill up the picker. Then just use the picker delegate method to switch languages: `- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { [Language setLanguage: [_array objectAtIndex: row]]; //some code to update the view (labels and everywhere different language is used) }`. If I understood your question correctly :) – Dunja Lalic Jul 07 '11 at 22:51
0

You can do this, but it won't play nicely with the built in localization functions in Foundation (e.g. NSLocalizedString), so you'll need to ignore them and write your own string-getting function, XIB-loading path, etc.

The question and answer here covers how to access localizations in the bundle on the fly like this: Overriding preferred strings localization on the fly for testing

Community
  • 1
  • 1
Ben Zotto
  • 70,108
  • 23
  • 141
  • 204
0

You can force the "AppleLanguages" user default. The example below shows how can be done; in particular here I'm switching the first (default) with the second language.



    NSArray *lang = [[NSUserDefaults standardUserDefaults] arrayForKey:@"AppleLanguages"];
    NSLog(@"current lang: %@",lang);
    [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:
                                                      [lang objectAtIndex:1],
                                                      [lang objectAtIndex:0],
                                                      nil]
                                              forKey:@"AppleLanguages"];
viggio24
  • 12,316
  • 5
  • 41
  • 34
0
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSMutableArray *languages = [NSMutableArray arrayWithArray:[defaults objectForKey:@"AppleLanguages"]];

    [languages replaceObjectAtIndex:0 withObject:@"fr"];

    [defaults setObject:languages forKey:@"AppleLanguages"];
    [defaults synchronize];

This is setting the language to French. Just put on position 0 what language you want to be loaded.

Alex Terente
  • 12,006
  • 5
  • 51
  • 71