Multilingual iPhone App

How do I change the default application language in my application? I am trying to change the application language to Arabic and I am not sure how to do this.

+2
source share
1 answer

There is a way:

First create another folder named ar.lproj and put localizable.String

May follow the sample code example. You can call this function in viewWillAppear with the key for which you need to get the 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; } 

I hope you understand the concept.

+4
source

Source: https://habr.com/ru/post/1413152/


All Articles