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

查看:31
本文介绍了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天全站免登陆