Multilanguage Application in Iphone

拟墨画扇 提交于 2019-12-06 11:59:19
Neelam Verma

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.

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