使用Localizable.strings实现本地化

吴均
2023-12-01
#define ENGLSIH_LANGUAGE 1
#define CHINESE_HANS_LANGUAGE 2
#define CHINESE_HANT_LANGUAGE 3
#define PORTUGUESE_LANGUAGE 4

//Translate a text

-(NSString*) selectedLanguage:(int)whichLanguage languageSelectedStringForKey:(NSString*) key
{
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];
    if(whichLanguage==ENGLSIH_LANGUAGE)
        path = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];
    else if(whichLanguage==CHINESE_HANS_LANGUAGE)
        path = [[NSBundle mainBundle] pathForResource:@"zh-Hans" ofType:@"lproj"];
    else if(whichLanguage==CHINESE_HANT_LANGUAGE)
        path = [[NSBundle mainBundle] pathForResource:@"zh-Hant" ofType:@"lproj"];
    else if(whichLanguage==PORTUGUESE_LANGUAGE)
        path = [[NSBundle mainBundle] pathForResource:@"pt" ofType:@"lproj"];
    
    NSBundle* languageBundle = [NSBundle bundleWithPath:path];
    NSString* str=[languageBundle localizedStringForKey:key value:@"" table:nil];
    return str;
}


 类似资料: