xcode 如何在 xcode4 中本地化 Settings.bundle?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5396078/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:37:05  来源:igfitidea点击:

How to localize Settings.bundle in xcode4?

xcodelocalizationxcode4settings-bundle

提问by Upvote

I am working on xcode4 and created a Settings.bundlefor my project. I can edit the Root.plistfile in xcode4 but it is not possible to edit the Root.stringsfile. It isn't even displayed in the editor.

我正在使用 xcode4 并Settings.bundle为我的项目创建了一个。我可以Root.plist在 xcode4 中编辑该文件,但无法编辑该Root.strings文件。它甚至没有显示在编辑器中。

enter image description here

在此处输入图片说明

I can not expand the en.lprojfolder as you see in the picture.

如图所示,我无法展开en.lproj文件夹。

But when I do right-click, open in external editorit gives me:

但是当我右键单击时,在外部编辑器中打开它给了我:

enter image description here

在此处输入图片说明

Double clickon Root.stringsgives me:

双击Root.strings给我:

enter image description here

在此处输入图片说明

I tried it several times, creating a new window-based application project and creating a new Settings.bundle. I always can not localize it. Any ideas?

我尝试了几次,创建了一个新的基于窗口的应用程序项目并创建了一个新的 Settings.bundle。我总是无法本地化它。有任何想法吗?

回答by Javi

In XCode 4.2 you have to follow this steps (just a modification of Xcode 3.2.2 and localization of Settings.bundle)

在 XCode 4.2 中,您必须遵循以下步骤(只是Xcode 3.2.2的修改和 Settings.bundle 的本地化

  1. Reveal your Settings.bundle in Finder.
  2. Right click (or Ctrl-click) on it and select Show Package contents.
  3. Create a new folder called as the desired language (e.g., fr.lproj).
  4. Copy the Root.strings file from the en.lproj folder and paste in fr.lproj folder.
  1. 在 Finder 中显示您的 Settings.bundle。
  2. 右键单击(或按住 Ctrl 键单击)并选择显示包内容。
  3. 创建一个名为所需语言的新文件夹(例如,fr.lproj)。
  4. 从 en.lproj 文件夹中复制 Root.strings 文件并粘贴到 fr.lproj 文件夹中。

回答by Matthias Bauch

EDIT: Apple fixed, once again, the wrong bug. Their change rendered my workaround useless. It just doesn't work anymore, you can't add files to the Settings.bundle.

编辑:Apple 再次修复了错误的错误。他们的改变使我的解决方法毫无用处。它只是不再起作用,您无法将文件添加到 Settings.bundle。

Please refer to the answer of Javifor a method that seems to work.

请参阅Javi的答案以了解似乎有效的方法。



I hope you like ugly workarounds.

我希望你喜欢丑陋的解决方法。

  1. Right click on the settings bundle in the side bar.
  2. Select New File
  3. Pick Resource / Strings file
  4. Name it Root.strings, make sure it is placed inside settings.bundle
  5. In the side bar the file will be visible twice. In the "root" section, and in the Settings.bundle. But both point to the same files.
  6. Select the Root.strings file in the root section. (AFAIR you have to convert it to UTF16)
  7. Add localization, xcode will ask you if you want to replace the file. Yes, you want this.
  8. Add as much localizations as you want. You should be able to edit the file in the root section of the sidebar.
  1. 右键单击侧栏中的设置包。
  2. 选择 New File
  3. 选择资源/字符串文件
  4. 将其命名为 Root.strings,确保将其放置在 settings.bundle 中
  5. 在侧栏中,文件将显示两次。在“根”部分和 Settings.bundle 中。但两者都指向相同的文件。
  6. 在根部分选择 Root.strings 文件。(AFAIR 你必须把它转换成 UTF16)
  7. 添加本地化,​​xcode 会询问您是否要替换文件。是的,你想要这个。
  8. 根据需要添加尽可能多的本地化。您应该能够在侧边栏的根部分编辑文件。

I hope this works for you, for me it does.

我希望这对你有用,对我来说确实如此。

And if you haven't done it please report the bug at bugreport.apple.com

如果您还没有这样做,请在bugreport.apple.com 上报告错误



I'll install the new release now, let's see if this is fixed. Edit: Not fixed.

我现在将安装新版本,让我们看看是否已修复。编辑:不固定。



EDIT: I don't know If I understood your second question correctly. But when you add a localization to the file that appears outside of the bundle it adds a localization folder to the settings.bundle

编辑:我不知道我是否正确理解了您的第二个问题。但是,当您向出现在包之外的文件添加本地化时,它会将本地化文件夹添加到 settings.bundle

enter image description here

在此处输入图片说明

After adding spanish localization to Root.strings:

将西班牙语本地化添加到Root.strings

enter image description here

在此处输入图片说明

The actual file is in the foo.lproj folder, it just doesn't show them in the xcode sidebar. If you check the location in the file system you'll see they are inside the settings bundle. enter image description here

实际文件在 foo.lproj 文件夹中,它只是没有在 xcode 侧栏中显示它们。如果您检查文件系统中的位置,您会看到它们位于设置包中。 在此处输入图片说明

Yesterday I checked with a english and german file and it worked correctly in the simulator. I guess it's just a wrong sidebar layout. The underlying locations and the handling of the files seems correct.

昨天我检查了英文和德文文件,它在模拟器中正常工作。我想这只是一个错误的侧边栏布局。文件的底层位置和处理似乎是正确的。

回答by dalind

For me it worked to change the File Type (in the File Inspector) of the Folder "en.lproj" from "Default / Directory" to "Directory". Magic.

对我来说,它可以将文件夹“en.lproj”的文件类型(在文件检查器中)从“默认/目录”更改为“目录”。魔法。

回答by Urkle

Xcode 4 is creating the "Root.strings" as a binary property list. so what I had to do was set the file type to "Property List (binary)" for it to show up correctly.

Xcode 4 正在创建“Root.strings”作为二进制属性列表。所以我必须做的是将文件类型设置为“属性列表(二进制)”才能正确显示。

回答by 18446744073709551615

I have just given up trying to do something with Root.strings. Instead, I just copied the plist into each *.lproj, and it worked!

我刚刚放弃尝试用 Root.strings 做一些事情。相反,我只是将 plist 复制到每个 *.lproj 中,并且它起作用了!

As far as this is about translation into English and my native language, no problem.

至于这是关于翻译成英语和我的母语,没问题。

So I have:

所以我有:

Settings.bundle
|- en.lproj
|  |- Root.plist
|  `- Root.strings -- nothing useful there
|
`- zz.proj
   `- Root.plist

The good news is that Root.plist is utf8.

好消息是 Root.plist 是 utf8。

回答by Rolleric

If you already have a Root.strings file that is a "Property List (binary)" and you wish to convert it to a proper text-based strings file, you can use plutilin the Terminal application to convert it, for instance into JSON format:

如果您已经有一个“属性列表(二进制)”的 Root.strings 文件,并且您希望将其转换为适当的基于文本的字符串文件,您可以plutil在终端应用程序中使用将其转换,例如转换为 JSON 格式:

> plutil -convert json /path/to/Settings.bundle/en.lproj/Root.strings

N.B. You can run plutil -hfor usage help.

注意您可以运行plutil -h以获取使用帮助。

However, you will then need to convert the JSON format:

但是,您随后需要转换 JSON 格式:

{"key1":"value1","key2":"value2"}

to that of a strings file:

到字符串文件的那个:

"key1" = "value1";
"key2" = "value2";

This is easily done with a few search/replace operations in a text editor.

这可以通过在文本编辑器中进行一些搜索/替换操作轻松完成。