xcode 什么时候使用 Base.lproj?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24997671/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
When is Base.lproj used?
提问by LuckyLuke
I am trying to understand Base.lproj but I am not still understanding it. If I create a new simple project with a view controller and Swift+Storyboard in XCode 6 beta 4 I get a Base.lproj folder out of the box containing the storyboard file.
我试图理解 Base.lproj 但我仍然不理解它。如果我在 XCode 6 beta 4 中创建一个带有视图控制器和 Swift+Storyboard 的新简单项目,我会得到一个包含故事板文件的开箱即用的 Base.lproj 文件夹。
I then add a simpel NSLocalizedString(...)
in my view controller for testing purposes. This requires a Localizable.strings file. When I create one should I add it in the Base.lproj or should I add it in a specific language folder?
然后NSLocalizedString(...)
我在我的视图控制器中添加一个 simpel用于测试目的。这需要一个 Localizable.strings 文件。当我创建一个时,我应该将它添加到 Base.lproj 中还是应该将它添加到特定的语言文件夹中?
If I change the Localization native development region
key in Info.plist to de
for german and I no Localizable.strings file for de
in the de.lproj
folder it seems to fallback on Base.lproj
if Localizable.strings file is found there. However, if I add a Localizable.strings file in the de.lproj
folder but don't add the property (key + value) the app fails during runtime. It seems like Base.lproj
isn't searched.
如果我的变化Localization native development region
中的Info.plist键de
为德国和我没有Localizable.strings文件de
中de.lproj
似乎退却的文件夹Base.lproj
,如果Localizable.strings文件在那里发现。但是,如果我在de.lproj
文件夹中添加 Localizable.strings 文件但不添加属性(键 + 值),则应用程序在运行时会失败。好像Base.lproj
没搜到
I don't understand which language Base
is and when it is used? Is it only for Storyboard files?
我不明白是哪种语言Base
以及何时使用?它仅适用于故事板文件吗?
回答by ShayanK
I was under the impression that base.lproj is used in cases where the current language/ localisation file does not have a property key. For instance if I do have Main_Title = "Title Text"; in base.lproj and absent in en.lproj while the current language is English, I assumed iOS will find it in base.lproj but that is not the case.
我的印象是 base.lproj 用于当前语言/本地化文件没有属性键的情况。例如,如果我有 Main_Title = "Title Text"; 在 base.lproj 中并且在 en.lproj 中不存在,而当前语言是英语,我认为 iOS 会在 base.lproj 中找到它,但事实并非如此。
Your initial conclusion is correct:
你的初步结论是正确的:
- Base is only used when you did not support that language in localizable.strings
- The specific language localizable.strings folder is used when device/ app is using that language
- If you do not provide support for a specific file/ string key in a language and you have a folder for that language, it will throw run-time warning
- 仅当您在 localizable.strings 中不支持该语言时才使用 Base
- 当设备/应用程序使用该语言时,将使用特定语言的 localizable.strings 文件夹
- 如果您不为某种语言中的特定文件/字符串键提供支持,并且您有该语言的文件夹,它将抛出运行时警告
In case of storyboard files and xibs if you only have base.lproj folder which contains your views, notwithstanding how many languages you support, it will not fail (this is what I am doing as well).
对于故事板文件和 xib,如果您只有包含视图的 base.lproj 文件夹,无论您支持多少种语言,它都不会失败(这也是我正在做的)。