如何在应用程序中列出iphone库中支持的所有语言

如何在应用程序中列出iphone库中支持的所有语言,iphone,ios5,nslocalizedstring,Iphone,Ios5,Nslocalizedstring,我正在创建一个应用程序,需要将库中所有受支持的语言都列在tableview中。因此,用户无需转到“设置”并更改语言。如果他愿意,他可以直接从应用程序更改它。我找了很多,但不知道这是否可能。请任何人帮我做这个 提前谢谢 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSArray *languages = [defaults objectForKey:@"AppleLanguages"]; 这将使苹果更喜欢u语

我正在创建一个应用程序,需要将库中所有受支持的语言都列在tableview中。因此,用户无需转到“设置”并更改语言。如果他愿意,他可以直接从应用程序更改它。我找了很多,但不知道这是否可能。请任何人帮我做这个

提前谢谢

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
这将使苹果更喜欢u语言。但是我不知道支持的语言。可能这是您正在搜索的列表

for (NSString *language in languages) {
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:language] ;
    displayname = [locale displayNameForKey:NSLocaleIdentifier value:language];
}

您可以为应用程序生成不同语言的pList文件

我向您解释本地化语言的示例代码

NSDictionary *dictLang;

-(void)localization_language{

    NSString *errorDesc = nil;
    NSPropertyListFormat format;
    NSString *rootPath;

    if (lang == 1) {
       rootPath = [[NSBundle mainBundle] pathForResource:@"FRA" 
                                               ofType:@"plist"];
    }
    else if(lang == 0){
       rootPath = [[NSBundle mainBundle] pathForResource:@"ENG" 
                                               ofType:@"plist"];
    }

    NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:rootPath];    
    dictLang = (NSDictionary *)[NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&errorDesc];
    NSLog(@"PLIST retrive:%@",plistXML);    

    if (!dictLang) {
       NSLog(@"Error reading plist: %@, format: %d", errorDesc, format);
    }
}
这段代码根据lang变量查找pList文件。法国0分,英语1分

然后,从字典中设置值

lbl1.text =[dictLang objectForKey:@"Key1"];
lbl2.text =[dictLang objectForKey:@"Key2"];
它将根据pList文件中存储的值显示值

希望它能促进语言全球化。
谢谢。

制作一个Language.plist文件,并制作一个语言词典,保留默认文本作为密钥

然后在Defines.h中定义这个宏

#define LocalizedString(key)     [[[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Language" ofType:@"plist"]] valueForKey:[NSString stringWithFormat:@"%d",LANGUAGE_ID]] valueForKey:key]
以编程方式设置全局语言id,并像这样使用LocalizedString(@“Hi”)


根据lang Id,将显示键hi的选定翻译值。

使用上述行,我得到的是语言代码列表,但不是其名称