2011-11-19 85 views
1

我想开发一个iphone应用程序,您可以从应用程序本身而不是iphone设置中更改语言。iPhone应用程序中的多语言支持

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

等待回应。

问候, Jagruti

+0

查看本教程http://www.raywenderlich.com/2876/how-to-localize-an-iphone-app-tutorial 用于创建String文件 – aViNaSh

回答

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)[email protected]"sp":@"en"]; 

创建两束作为字符串的文件名Sp.lproj和en.lproj 给同一个密钥对于两个字符串 获得值如下面 [YourAppDelegate的getLocalValue:@ “设置” ]。