Iphone中的多语言应用 [英] Multilanguage Application in Iphone

查看:71
本文介绍了Iphone中的多语言应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在应用程序中更改应用程序的默认语言?我正在尝试将应用程序语言更改为阿拉伯语,但不确定如何做到这一点.

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.

推荐答案

有一种方法:

首先创建另一个名为ar.lproj的文件夹,然后放入localizable.String

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

以下示例代码可以为您提供帮助.您可以在viewWillAppear中使用需要获取值的键来调用此函数.

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.

这篇关于Iphone中的多语言应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆