Multilanguage Application in Iphone

喜欢而已 提交于 2019-12-08 00:57:14

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/9971469/multilanguage-application-in-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!