iOS Localizable.strings未从BASE文件中检索 [英] iOS Localizable.strings not being retrieved from BASE file

查看:723
本文介绍了iOS Localizable.strings未从BASE文件中检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 iOS 上进行本地化工作的问题与我认为的方式有关,但这是我第一次尝试本地化,所以也许我误解了。

I am having a problem getting localization on iOS to work the way I think it is suppose to, but this is my first foray into localization so maybe I am misunderstanding.

我有三个 Localizable.strings 文件:

基础

"TAB_TITLE_Camera" = "CAMERA";

英文

"TAB_TITLE_Camera" = "Camera";

西班牙语

"TAB_TITLE_Camera" = "Cámara";







NSLocalizedString(@"TAB_TITLE_Camera", nil)






iOS 6.1

Xcode 5 上使用第4代iPod Touch 运行 iOS 6.1 英语西班牙语似乎有效,但如果我更改为德语(或没有本地化文件的任何其他语言)它不会从 Base Localizable.strings 中提取
,而是从英语文件中提取。

On Xcode 5 with a 4th generation iPod Touch running iOS 6.1, English and Spanish seem to work, but if I change to German (or any other language without a localization file) it does not pull from Base Localizable.strings, instead it pulls from the English file.

为什么来自 BASE 文件?

为什么 DOES 它从英文文件中提取?

Why DOES it pull from the English file?

iOS 7.1

此外,当第5代iPod Touch 运行 iOS 7.1 时,我更改为德语似乎从最后选择的具有本地化文件的语言中提取,英语西班牙语。嗯?!

Also, with a 5th generation iPod Touch running iOS 7.1, when I change to German it seems to pull from the last selected language that has a localization file, either English or Spanish. Huh?!

推荐答案

找到一种方法来确定我是否有当前所选语言的本地化文件,如果没有,我可以从 Base 本地化文件中提取。

Found a way to determine whether or not I have a localization file for the currently selected language, and if not, I can pull from the Base localization file.

NSString *path = [[NSBundle mainBundle] pathForResource:[[NSLocale preferredLanguages] objectAtIndex:0] ofType:@"lproj"];
if (path == nil)
{
    path = [[NSBundle mainBundle] pathForResource:@"Base" ofType:@"lproj"];
}

NSLocalizedStringFromTableInBundle(@"TAB_TITLE_Camera", @"Localizable", [NSBundle bundleWithPath:path], @"");

如果当前语言为:

英语返回相机

西班牙语返回Cámara

其他没有本地化文件的内容返回 CAMERA

Anything else that doesn't have a localization file returns CAMERA

简单的解决方案,可以完成我需要的一切。

Simple solution that does everything I need.

适用于 iOS 6.1 iOS 7.1

这篇关于iOS Localizable.strings未从BASE文件中检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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