备用语言iOS(带有不完整的Localizable.strings文件)

我有一个本地化为16种语言的iOS项目。 只有一些文字没有本地化(主要是那些进入更新和本地化办公室没有及时交付)。 对于我的钥匙,我使用英文措辞,因为如果翻译者希望,这也可以改变。 所以现在如果我只是没有一个语言的翻译,如果退回到我使用的密钥。 但是,由于这个关键不是“人类可读的”,或者至less不是“人类可读的”,所以这是一个问题。

我做了一些研究,但找不到解决我的确切问题。 我有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... 

所以现在我只是把英文翻译复制到缺less的Localizable.strings文件中。 但这是一个很大的破解! 但是,用英文单词作为键似乎对我来说是一个黑客!

有没有办法告诉我的应用程序,它应该使用fe英语作为后备,如果没有给定的键值? 我试图添加一个基本的本地化,但这并没有帮助…

非常感谢

据我所知,没有“官方”的办法,但是我已经实现了这样的function:

 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(),它将返回inputstring,这个版本将回退到英语,如有必要。

你可以使用一个Base本地化,所有非本地化的string将从这个。