iPhone en_* sublanguage localization

后端 未结 6 1627
故里飘歌
故里飘歌 2021-02-08 14:53

I want to localize strings in my iphone app for en_GB and other \'en\' sub-languages, but XCode and the iphone refuse to let this happen. I have created a localization of \"Loca

6条回答
  •  终归单人心
    2021-02-08 15:36

    Create a separate string resource, say UKLocalization.strings, and create localizations for each of your supported languages. For all localizations other than en this file is empty. For en, it contains only the strings that have unique en_GB spelling.

    Next, you create a replacement for NSLocalizationString that will first check the UKLocalization table before falling back to the standard localization table.

    e.g.:

    static NSString* _locTable = nil;
    void RTLocalizationInit()
    {
        _locTable = nil;
    
        NSString* country = [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode];
        if ([country isEqual:@"GB"])
        {
            _locTable = @"UKLocalization";
        }
    }
    
    NSString* RTLocalizedString(NSString* key, NSString* ignored)
    {
        NSString* value = nil;
        value = [[NSBundle mainBundle] localizedStringForKey:key value:nil table: _locTable];
        if (value == key)
        {
            value = NSLocalizedString(key, @"");
        }
        return value;
    }
    

提交回复
热议问题