本地化只能通过代码而不是直接在 Interface Builder 中完成吗?

发布于 2024-12-25 15:05:25 字数 150 浏览 2 评论 0原文

IB 是否不允许为显示文本的组件指定本地化键,而不是对值进行硬编码?例如,如果您希望 UILabel 显示国际化文本是通过代码实现此目的的唯一方法吗?当你有一个像 IB 这样的 WYSIWYG 编辑器时,似乎 PITA 必须在代码中设置所有标签文本。我想我在 VB5 中就有这个功能了!

Does IB not allow one to specify a localized key for components that display text instead of hardcoding the value? For instance, if you want a UILabel to display internationalized text is the only way to do this via code? Seems like such a PITA to have to set all your label text in code when you have a nice WYSIWYG editor like IB. I think I had this feature back in VB5!

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

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

发布评论

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

评论(2

败给现实 2025-01-01 15:05:25

实际上,您通常不需要编写任何代码来本地化 Interface Builder 用户界面 (Xibs)。您要做的就是在 XCode 的帮助下创建这些 Xib 的本地化版本。在您的 XCode 项目中,选择一个 Xib,打开文件检查器(位于“实用程序”面板中),您将在其中看到“本地化”部分。单击 + 按钮,XCode 将为您选择的语言创建一个版本,然后您可以通过翻译文本以及调整 UI 元素大小或执行任何您喜欢的其他操作来本地化该版本。

You actually don't normally need to write any code to localize your Interface Builder user interface (Xibs). What you do is create localized versions of these Xibs, with the help of XCode. In your XCode project, select a Xib, open the File Inspector (it's in the Utilities panel) and you'll see a Localization section in there. Click the + button and XCode will create a version for the language of your choice, which you can then localize by translating the text as well as resizing UI elements or do anything else you like.

§普罗旺斯的薰衣草 2025-01-01 15:05:25

Cocoa/AppKit 中的正常方法是将您想要以不同语言存在的文件本地化。但您想要本地化的唯一文件可能是 nib/xib 文件和字符串文件。

Clafou 解释了如何本地化 nib 文件。

字符串文件是包含键值对的文件。通过调用诸如 NSLocalizedString 之类的函数,您可以使用您设置的键来查询它们。

Apple 已记录所有这些功能。
Nib 文件
字符串文件

The normal way in Cocoa/AppKit is to localize the files you want to exist in different languages. But probably the only files you want make localized are your nib/xib files and your strings files.

Clafou has explained how you localize the nib files.

The strings files are files which contain key-value pairs. By calling functions like NSLocalizedString you can query them with the key you've set.

Apple has documented all these features.
Nib files
Strings files

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