2

How do I change my applications default language within my application? I am trying to change my applications language to Arabic, and I'm not sure how to accomplish this.

Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
Ved
  • 2,701
  • 2
  • 22
  • 30
  • 1
    You can find answer here, http://stackoverflow.com/questions/1669645/how-to-force-nslocalizedstring-to-use-a-specific-language – Hasintha Janka Apr 02 '12 at 06:04

1 Answers1

4

There is a way:

First make a different folder named as ar.lproj and put localizable.String

May following sample code help you. You can call this function in viewWillAppear with the key for which you need to get value.

-(NSString*) languageSelectedStringForKey:(NSString*) key
{

   NSString *path;
   NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
  if([[userDefault valueForKey:@"language_Selected"] intValue] == 0)
  path = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];

  else if([[userDefault valueForKey:@"language_Selected"] intValue] == 1)
  path = [[NSBundle mainBundle] pathForResource:@"ar" ofType:@"lproj"];

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

Hope you will understand the concept.

Lucifer
  • 29,392
  • 25
  • 90
  • 143
Neelam Verma
  • 3,232
  • 1
  • 22
  • 33