Allow only specific translations for different schemes/targets

怎甘沉沦 提交于 2019-12-20 05:45:32

问题


My issue is, that I have a basic set of Localizable.strings for several languages, but I don't want to allow them in all my build-targets / schemes (some of our clients want only these, others only that languages allowed).

Because the set is the same for all and will be extended with every update, I want to avoid to copy the files deeper in the folder hirarchy and maintain every target.

I use NSLocalizedStringWithDefaultValue and NSLocalizedString, but haven't found any option to give them the allowed localizations.

Thank you in advance.


回答1:


I ended up in changing my way from using the NSLocalizedString to language specific named files (for german Localizable_de.strings, for english Localizable_en.strings and so on).

Following to

https://stackoverflow.com/a/12004482/883799

I use in my translation class

NSString *tbl = [@"Localizable_" stringByAppendingString:[MyLibrary currentLocalization]];
NSString *fname = [[NSBundle mainBundle] pathForResource:tbl ofType:@"strings"];
if(!localStrings)
    localStrings = [[NSDictionary dictionaryWithContentsOfFile:fname] retain];

NSString *value = [localStrings objectForKey:key];

where [MyLibrary currentLocalization]; is

+(NSString *)currentLocalization
{
    NSString *currentLocCode = [[NSLocale preferredLanguages] objectAtIndex:0];

    if([[AppSettings supportedLocales] containsObject:currentLocCode])
        return [currentLocCode substringToIndex:2];

    return [AppSettings defaultLocalization];
}

AppSettings is target-depending an [AppSettings supportedLocales]; is

+(NSArray *)supportedLocales
{
    return [NSArray arrayWithObjects:
    @"de",
    @"de_AT",
    @"de_BE",
    @"de_CH",
    @"de_DE",
    @"de_LI",
    @"de_LU",
     //
    @"en",
    @"en_AS",
    @"en_AU",
    @"en_BB",
    @"en_BE",
    @"en_BM",
    @"en_BS",
    @"en_BW",
    @"en_BZ",
    @"en_CA",
    @"en_FJ",
    @"en_FM",
    @"en_GB",
    @"en_GM",
    @"en_GU",
    @"en_GY",
    @"en_HK",
    @"en_IE",
    @"en_IN",
    @"en_JM",
    @"en_MH",
    @"en_MP",
    @"en_MT",
    @"en_MU",
    @"en_MW",
    @"en_NA",
    @"en_NZ",
    @"en_PG",
    @"en_PH",
    @"en_PK",
    @"en_PW",
    @"en_SB",
    @"en_SC",
    @"en_SG",
    @"en_SL",
    @"en_SZ",
    @"en_TT",
    @"en_UM",
    @"en_US",
    @"en_US_POSIX",
    @"en_VI",
    @"en_ZA",
    @"en_ZW",
    //
    @"es",
    @"es_419",
    @"es_AR",
    @"es_BO",
    @"es_CL",
    @"es_CO",
    @"es_CR",
    @"es_DO",
    @"es_EC",
    @"es_ES",
    @"es_GQ",
    @"es_GT",
    @"es_HN",
    @"es_MX",
    @"es_NI",
    @"es_PA",
    @"es_PE",
    @"es_PR",
    @"es_PY",
    @"es_SV",
    @"es_US",
    @"es_UY",
    @"es_VE",
    //
    @"fr",
    @"fr_BE",
    @"fr_BF",
    @"fr_BI",
    @"fr_BJ",
    @"fr_BL",
    @"fr_CA",
    @"fr_CD",
    @"fr_CF",
    @"fr_CG",
    @"fr_CH",
    @"fr_CI",
    @"fr_CM",
    @"fr_DJ",
    @"fr_FR",
    @"fr_GA",
    @"fr_GF",
    @"fr_GN",
    @"fr_GP",
    @"fr_GQ",
    @"fr_KM",
    @"fr_LU",
    @"fr_MC",
    @"fr_MF",
    @"fr_MG",
    @"fr_ML",
    @"fr_MQ",
    @"fr_MR",
    @"fr_NE",
    @"fr_RE",
    @"fr_RW",
    @"fr_SC",
    @"fr_SN",
    @"fr_TD",
    @"fr_TG",
    @"fr_YT",
    //
    @"it",
    @"it_CH",
    @"it_IT",
            nil];
}

but still accepting modifications to this if someone has a better solution :)



来源:https://stackoverflow.com/questions/16979168/allow-only-specific-translations-for-different-schemes-targets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!