多语言本地化开发Localized

NSString * ViewsLocalizedStringFormat(NSString *key,NSString *defValue);

// Handle localized strings stored in a bundle

NSString * ViewsLocalizedStringFormat(NSString *key,NSString *defValue)
{
    static NSBundle *viewsBundle = nil;
    if (viewsBundle == nil) {
        NSBundle *viewBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"views" ofType:@"bundle"]];
        viewsBundle = [NSBundle bundleWithPath:[viewBundle pathForResource:[[NSLocale preferredLanguages] objectAtIndex:0] ofType:@"lproj"]];
        if (viewsBundle == nil) {
            
            viewsBundle = [NSBundle bundleWithPath:[viewBundle pathForResource:@"en" ofType:@"lproj"]];
        }
    }
    if (defValue==nil) {
        defValue=key;
    }
    return [viewsBundle localizedStringForKey:key value:defValue table:nil];
}

 

posted @ 2015-10-06 00:02  IOS小小鸟  阅读(1131)  评论(0编辑  收藏  举报