仅允许针对不同的方案/目标进行特定的翻译 [英] Allow only specific translations for different schemes/targets

查看:109
本文介绍了仅允许针对不同的方案/目标进行特定的翻译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,对于几种语言,我有一套基本的Localizable.strings,但是我不想 允许他们在我所有的构建目标/方案中 (我们的一些客户只想要这些,其他的客户只允许使用语言).

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.

我使用NSLocalizedStringWithDefaultValueNSLocalizedString,但是没有找到任何允许它们本地化的选项.

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

谢谢.

推荐答案

我最终将自己的使用方式从使用NSLocalizedString更改为特定于语言的命名文件(对于德语Localizable_de.strings,英语Localizable_en.strings等) ).

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).

跟随

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

我在翻译课上使用

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];

其中[MyLibrary currentLocalization];

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

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

    return [AppSettings defaultLocalization];
}

AppSettings是目标相关的,[AppSettings supportedLocales];

+(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 :)

这篇关于仅允许针对不同的方案/目标进行特定的翻译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆