2011-11-19 115 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:@ 「設置」 ]。