xcode iPhone Settings.bundle 的本地化
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3113365/
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
Localization of the iPhone Settings.bundle
提问by Axeva
For some reason I cannot get the Settings.bundle to recognize my additional languages. I must be missing something obvious, but I just cannot figure it out. Here's what I've got:
出于某种原因,我无法让 Settings.bundle 识别我的其他语言。我一定遗漏了一些明显的东西,但我就是想不通。这是我所拥有的:
Project Structure in XCode:
XCode 中的项目结构:
Root.plist file:
根.plist文件:
Root.plist file http://img227.imageshack.us/img227/571/screenshot20100624at334.png
Root.plist 文件 http://img227.imageshack.us/img227/571/screenshot20100624at334.png
French Root.strings file
法语 Root.strings 文件
french Root.strings file http://img121.imageshack.us/img121/571/screenshot20100624at334.png
法语 Root.strings 文件 http://img121.imageshack.us/img121/571/screenshot20100624at334.png
From everything I've read, I believe the project structure is right. The StringsTable in the Root.plist matches the name of the individual .strings files, and the Key for each item in the Root.plist has a match in the .strings files as well.
从我读过的所有内容来看,我相信项目结构是正确的。Root.plist 中的 StringsTable 匹配各个 .strings 文件的名称,Root.plist 中每个项目的 Key 在 .strings 文件中也匹配。
Why don't I see French text in my settings when I change the default iPhone language?
当我更改默认 iPhone 语言时,为什么在我的设置中看不到法语文本?
Thanks in advance!
提前致谢!
采纳答案by Axeva
I'll go ahead and answer my own question since I solved the problem myself through testing and failing. Hopefully this will help someone else in the future.
我会继续回答我自己的问题,因为我通过测试和失败自己解决了这个问题。希望这会在将来对其他人有所帮助。
First, I think my Root.plist
file may have been corrupted. I'm not exactly sure why, but I completely deleted the Settings.bundle
, and re-created it to be sure.
首先,我认为我的Root.plist
文件可能已损坏。我不确定为什么,但我完全删除了Settings.bundle
,并重新创建它以确保。
Second, and perhaps most importantly, the main issue was the "key" in the root.strings
file didn't match to the "key
" field in the Root.plist
, it actually matches the "Title
" field.
其次,也许是最重要的,主要问题是文件中的“键”root.strings
与 中的“ key
”字段不匹配Root.plist
,它实际上与“ Title
”字段匹配。
Once I made those changes to the Root.strings
file, it all started to work.
一旦我对Root.strings
文件进行了这些更改,它就开始工作了。
回答by Shane Rayner
For me, the problem was leaving off a semi-colon!
对我来说,问题是去掉分号!
In localizable.strings, you get a runtime error if you omit the ";", but in Root.strings, you don't get any warnings, you can run it fine, but it just won't work!
在 localizable.strings 中,如果您省略“;”,则会出现运行时错误,但在 Root.strings 中,您不会收到任何警告,您可以正常运行它,但它不会工作!
So double-check to make sure you punctuate each key:value pair with a semi-colon!
因此,请仔细检查以确保用分号标点每个键:值对!
回答by Eduardo Russo
All you have to do is keep (or Add, if it's not there) "Strings Filename" in the Root.plist, after your settings.
你所要做的就是在你的设置之后在 Root.plist 中保留(或添加,如果它不存在)“字符串文件名”。
Then, add Value "Root" (or, the name of your file and the translations) to make the created lang.lproj translations functional.
然后,添加值“Root”(或文件名和翻译)以使创建的lang.lproj 翻译起作用。
回答by Karsten
In Xcode 5 there is still no obvious way to localize the Settings.bundle.
在 Xcode 5 中,仍然没有明显的方法来本地化 Settings.bundle。
The problem
问题
Xcode doesn't allow you to localize a file that is only shown because it is a file inside a folder that's directly shown in Xcode (hence the blue folder icons in the tree).
Xcode 不允许您本地化仅显示的文件,因为它是在 Xcode 中直接显示的文件夹内的文件(因此树中的蓝色文件夹图标)。
The Solution:
解决方案:
- right-click the Root.strings file and select "Show in Finder"
- List item
- move the Root.strings file one folder up, so that the en.lproj folder is empty and the Cmd-Drag the Root.strings file is next to the Root.plist.
- delete the now empty en.lproj
- go back to Xcode, notice that the tree will reflect the changes you now made
- cmd-drag the file in the tree outside to outside the settings-bundle, so that it appears next to your source-code.
- Do not copy the file
- a dialog will appear asking you what to do with the file.
- DO NOT select the checkbox to copy the file (you need this to be a reference)
- DO NOT select a target to include the strings-file (the settings.bundle is already assigned to the correct target)
- in the file inspector you can now choose to localize the file and to add languages to the localizations. The files will be placed correctly inside the settings.bundle and the tree will automatically reflect these changes, too.
- 右键单击 Root.strings 文件并选择“在 Finder 中显示”
- 项目清单
- 将 Root.strings 文件向上移动一个文件夹,以便 en.lproj 文件夹为空,并且 Cmd-Drag Root.strings 文件位于 Root.plist 旁边。
- 删除现在空的 en.lproj
- 返回 Xcode,注意树将反映您现在所做的更改
- cmd-将树中的文件拖到设置包之外,使其出现在源代码旁边。
- 不要复制文件
- 将出现一个对话框,询问您如何处理该文件。
- 不要选中复选框来复制文件(您需要将此作为参考)
- 不要选择包含字符串文件的目标(settings.bundle 已经分配给正确的目标)
- 在文件检查器中,您现在可以选择本地化文件并向本地化添加语言。这些文件将正确放置在 settings.bundle 中,并且树也会自动反映这些更改。
回答by Rok Strni?a
In my case, it appeared as if "Strings Filename"
was set to "Root"
in the Property List Viewof Root.plist
, but when viewed the file in Source Code View, it was actually "StringsTable"
pointing to "Root"
. The solution is to add another entry where "Strings Filename"
points to "Root"
. (I also tried deleting the previous entry, but then it stops working, so you need both.)
以我为例,觉得好像"Strings Filename"
被设置为"Root"
在属性列表视图中Root.plist
,但在看文件时源代码视图,它实际上"StringsTable"
指向"Root"
。解决方案是添加另一个条目 where"Strings Filename"
指向"Root"
. (我也尝试删除上一个条目,但随后它停止工作,因此您需要两者。)
回答by Alphonse R. Dsouza
After some repeated tries to activate localization,following steps worked for me:
经过反复尝试激活本地化,以下步骤对我有用:
- Close xcode
- Drag and duplicate the settings bundle onto the desktop (or wherever)
- Open bundle contents
- Drag Root.strings into the en.lproj folder
Duplicate the en.lproj folder and rename to whatever language you want (using 2-letter code ie fr.lproj)
Replace the original settings bundle with the new one(without opening xcode).
- Now Open xcodeand the new files and folders should be there
- 关闭 xcode
- 将设置包拖动并复制到桌面(或任何地方)
- 打开捆绑内容
- 将 Root.strings 拖入 en.lproj 文件夹
复制 en.lproj 文件夹并重命名为您想要的任何语言(使用 2 个字母的代码,即 fr.lproj)
用新的设置包替换原始设置包(无需打开 xcode)。
- 现在打开 xcode,新的文件和文件夹应该在那里
Now delete the older app and run xcode,Works fine in simulator and on device.
现在删除旧的应用程序并运行 xcode,在模拟器和设备上运行良好。
NOTE:Closing xcode,updating of duplicated setting bundle outside xcode and replacing updated back only will help.
注意:关闭 xcode,更新 xcode 之外的重复设置包并仅替换更新回来会有所帮助。