iphone应用程序中的多语言支持

时间:2011-11-19 07:17:44

标签: iphone multilingual

我想开发一个iphone应用程序,你可以从应用程序本身改变语言而不是iphone设置。

怎么可能? 有没有可用的教程?

等待回复。

此致 Jagruti

1 个答案:

答案 0 :(得分:2)

+(void)GetLangKey:(NSString *)Langkey
{
    NSString *tmpstr=[NSString stringWithFormat:@"%@",[[NSBundle mainBundle]pathForResource:@"LanguageResources" ofType:@"bundle"]]; 
    tmpstr =[tmpstr stringByAppendingString:@"/"];
    tmpstr=[tmpstr stringByAppendingString:Langkey];
    tmpstr =[tmpstr stringByAppendingString:@".lproj"];

    //  NSLog(@"%@",tmpstr);
    myLocalizedBundle=[NSBundle bundleWithPath:tmpstr];
}

+(UIImage*)GetLocalImage:(NSString *)ImgName
{
    NSString *filepath= [myLocalizedBundle pathForResource:ImgName ofType:@"png"]; 
    UIImage *returnImg=[UIImage imageWithContentsOfFile:filepath];
    return returnImg;
}

+(UIImage*)GetLocalImage:(NSString *)ImgName Type:(NSString *)imgType
{
    NSString *filepath= [myLocalizedBundle pathForResource:ImgName ofType:imgType]; 
    UIImage *returnImg=[UIImage imageWithContentsOfFile:filepath];
    return returnImg;   
}

+(NSString *)getLocalvalue:(NSString*)Key
{
    NSString *localValue=NSLocalizedStringFromTableInBundle(Key,@"Localized",myLocalizedBundle,@"");
    //NSLog(@"%@",localValue);
    return localValue;
}

when you changed Language change kay
[YourAppDelegate GetLangKey:(btn_Language.selected)?@"sp":@"en"];

创建两个捆绑包作为字符串文件命名Sp.lproj AND en.lproj    为两个字符串提供相同的键    获得如下价值     [YourAppDelegate getLocalvalue:@“设置”];