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

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

问题描述

我在 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 上使用运行 iOS 6.1英语西班牙语的第 4 代 iPod Touch 似乎有效,但如果我更改为 德语 (或任何其他没有本地化文件的语言),它不会拉来自 Base Localizable.strings,而是从 English 文件中提取.

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 文件中提取?

Why does it NOT pull from the BASE file?

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

Why DOES it pull from the English file?

iOS 7.1

另外,对于运行 iOS 7.1第 5 代 iPod Touch,当我更改为 德语 时,它似乎从上次选择的语言中提取具有本地化文件,EnglishSpanish.啊?!

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.1iOS 7.1.

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

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