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

发布于 2024-10-25 13:13:31 字数 577 浏览 7 评论 0原文

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

在此处输入图像描述

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

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

在此处输入图像描述

双击 Root.strings 会显示:

在此处输入图像描述

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

I am working on xcode4 and created a Settings.bundle for my project. I can edit the Root.plist file in xcode4 but it is not possible to edit the Root.strings file. It isn't even displayed in the editor.

enter image description here

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

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

enter image description here

Double click on Root.strings gives me:

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

羁〃客ぐ 2024-11-01 13:13:31

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

  1. 在 Finder 中显示您的 Settings.bundle。
  2. 右键单击(或按住 Ctrl 键单击)它并选择“显示包内容”。
  3. 创建一个名为所需语言的新文件夹(例如,fr.lproj)。
  4. 从 en.lproj 文件夹复制 Root.strings 文件并粘贴到 fr.lproj 文件夹中。

In XCode 4.2 you have to follow this steps (just a modification of Xcode 3.2.2 and localization of 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.
沫尐诺 2024-11-01 13:13:31

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

请参考Javi的答案,寻找似乎有效的方法。


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

  1. 右键单击侧栏中的设置包。
  2. 选择新建文件
  3. 选择资源/字符串文件
  4. 将其命名为Root.strings,确保将其放置在settings.bundle 内
  5. 在侧栏中,该文件将可见两次。在“root”部分和 Settings.bundle 中。但两者都指向相同的文件。
  6. 选择根部分中的 Root.strings 文件。 (AFAIR你必须将其转换为UTF16)
  7. 添加本地化,​​xcode会询问你是否要替换文件。是的,你想要这个。
  8. 添加任意数量的本地化内容。您应该能够在侧边栏的根部分编辑该文件。

我希望这对你有用,对我也有用。

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


我将安装现在新版本发布了,看看这个问题是否修复了。编辑:未修复。


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

enter image description here

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

在此处输入图像描述

实际文件位于 foo.lproj 文件夹中,只是不在 xcode 侧边栏中显示它们。如果您检查文件系统中的位置,您将看到它们位于设置包内。
在此处输入图像描述

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

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.

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


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.

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


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

enter image description here

After adding spanish localization to 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

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.

余生共白头 2024-11-01 13:13:31

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

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

梦一生花开无言 2024-11-01 13:13:31

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

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.

鹤仙姿 2024-11-01 13:13:31

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

就翻译成英语和我的母语而言,没问题。

所以我有:

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

好消息是 Root.plist 是 utf8。

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

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.

川水往事 2024-11-01 13:13:31

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

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

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

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

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

为字符串文件的格式:

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

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

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 plutil in the Terminal application to convert it, for instance into JSON format:

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

N.B. You can run plutil -h for usage help.

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

{"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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文