后备语言iOS(带有不完整的Localizable.strings文件) [英] Fallback language iOS (with incomplete Localizable.strings file)

查看:112
本文介绍了后备语言iOS(带有不完整的Localizable.strings文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iOS项目,该项目已本地化为16种语言.只有一些单词没有被本地化(主要是那些要更新的单词,而本地化办公室没有及时交付). 对于我的键,我使用英文措词,因为如果翻译人员愿意,这也可以更改. 所以现在,如果我只是没有翻译一种语言,那么就退回到我使用的键了.但是由于该密钥不是人类可读的"或至少不是人类阅读的乐趣",所以这是一个问题.

I have an iOS project that is localized into 16 languages. Only some words are not localized (Mainly those that go into an update and the localization office did not deliver in time). For my keys I do not use the english wording, as this can also change if a translator wishes. So now if I just don't have a translation for a language, if falls back to the key that I used. But as this key is not 'human readable' or at least not 'human enjoyable to read' this is a problem.

我做了一些研究,但是找不到解决我的确切问题的解决方案. 我有fe.:

I did some research but couldn't find a solution to my exact problem. I have fe.:

Localizable.strings in en.lproj
@"Key1" = @"Value 1"
@"Key2" = @"Value 2"

Localizable.strings in de.lproj
@"Key1" = @"Wert 1"
// Note that @"Key2" is missing here in my de.lproj

I would expect that if I make NSLocalizedString(@"Key2", ...)
and am running on a german phone, it falls back to the english
translation for this key as it exists...

因此,现在我只将英语翻译复制到丢失的Localizable.strings文件中.但这是一个大技巧! 但是,使用英语单词作为键似乎对我来说也是一个骇客!

So for now i just copied the english translation into the missing Localizable.strings files. But this is a big hack! But also using the english words as keys seems to be a hack to me!

有什么办法可以告诉我的应用程序,它应该使用f.e.如果给定的键没有价值,则将英语作为后备吗?我尝试添加基本本地化,但这无济于事...

Is there any way to tell my app, that it should use f.e. english as the fallback if there is no value for a given key? I tried adding a base localization but this doesn't help...

非常感谢

推荐答案

据我所知,尚无官方"方法,但我之前已经实现了这样的功能:

As far as I know, there's no "official" way to do it, but I have implemented functions such as this before:

NSString * L(NSString * translation_key) {
    NSString * s = NSLocalizedString(translation_key, nil);
    if (![[[NSLocale preferredLanguages] objectAtIndex:0] isEqualToString:@"en"] && [s isEqualToString:translation_key]) {
        NSString * path = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];
        NSBundle * languageBundle = [NSBundle bundleWithPath:path];
        s = [languageBundle localizedStringForKey:translation_key value:@"" table:nil];
    }
    return s;
}

从以下地址借来: https://stackoverflow.com/a/8784451/1403046

基本上,它会代替NSLocalizedString()来返回输入字符串,如有必要,此版本将回退为英语.

Basically, instead of NSLocalizedString(), which will return the input string, this version will fallback to English if necessary.

这篇关于后备语言iOS(带有不完整的Localizable.strings文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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