如何在不为每种语言创建 xib 的情况下本地化 xib 视图中的文本?

发布于 2024-12-26 17:02:17 字数 87 浏览 5 评论 0原文

我想本地化 xib 视图中的文本。目前我对每种语言都有几个 xib。

是否可以本地化 xib 文件中的文本,而无需为每种语言创建单独的 xib?

I want to localize text inside xib view. Currently I have several xibs for each language.

Is it possible to localize the text inside xib file without creating separate xibs for each language?

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

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

发布评论

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

评论(5

鲸落 2025-01-02 17:02:18

听起来您想了解 .string 文件。

您可以查看以下相关问题以获取更多信息:
将 .string 文件作为 NSDictionary 打开

Sounds like you want to learn about .string files.

Here is a related question you can look at for more info:
Open .string files as an NSDictionary

书间行客 2025-01-02 17:02:18

来自Android背景,我问了同样的问题。甚至 Apple 建议创建单独的 xib每种语言的文件。幸运的是,可以在构建脚本中使用 ibtool 来自动化此过程。 这篇文章对此进行了很好的描述。

Coming from Android background, I was asking the same question. Even Apple recommends creating separate xib files for each language. Fortunately, this process can be automated using the ibtool in a build script. It's described nicely in this article.

丢了幸福的猪 2025-01-02 17:02:18

本地化适用于文本而不是 Xib。所以,你不需要
考虑 xib 文件。本地化很容易,不太复杂。查看
此链接会对您有所帮助。

http://www.raywenderlich.com/2876/how -本地化 iPhone 应用程序教程

Localization are applied for text not Xib. So, you don't need to
consider xib file. Localization is easy not too Complicated. Check
this link It will help You.

http://www.raywenderlich.com/2876/how-to-localize-an-iphone-app-tutorial

吃→可爱长大的 2025-01-02 17:02:18

这个问题快把我逼疯了。

我在尝试让 xib 本地化变得更容易时遇到了这篇文章和其他几篇文章。我发布了在这个问题上包含标签/按钮的 IBOutles 的方法,对我来说效果很好,将所有更改限制在 Localization.strings 文件中。

https://stackoverflow.com/a/15485572/1449834

This problem was driving me nuts.

I came across this post and several others while trying to make xib localization easier for myself. I posted my method of including IBOutles for labels/buttons on this question, worked great for me, keeps all changes limited to the Localization.strings files.

https://stackoverflow.com/a/15485572/1449834

昨迟人 2025-01-02 17:02:18

我认为直接本地化 xibs 不是一个好的选择。我正在使用 https://github.com/steipete/Aspects 来挂钩 UILabel 的 awakeFromNib 方法和在那里本地化文本。示例:

 #define Localized(_v_) NSLocalizedString(_v_, nil)
 NSError *err = nil;
[UILabel aspect_hookSelector:@selector(awakeFromNib)
                 withOptions:AspectPositionAfter
                  usingBlock:^(id<AspectInfo> aspectInfo) {
                      UILabel *label = aspectInfo.instance;
                      NSString *lStr = Localized(label.text);
                      if (lStr) {
                          label.text = lStr;
                      }
} error:&err];

如果您有 UIButton 和其他 UIView 需要处理,您可以直接挂接 UIView 的 awakeFromNib 并本地化每种视图。

I think localize xibs directly is not an good option. I'm using https://github.com/steipete/Aspects to hook the awakeFromNib method of UILabel and localize text there. Example:

 #define Localized(_v_) NSLocalizedString(_v_, nil)
 NSError *err = nil;
[UILabel aspect_hookSelector:@selector(awakeFromNib)
                 withOptions:AspectPositionAfter
                  usingBlock:^(id<AspectInfo> aspectInfo) {
                      UILabel *label = aspectInfo.instance;
                      NSString *lStr = Localized(label.text);
                      if (lStr) {
                          label.text = lStr;
                      }
} error:&err];

If you have UIButton and other UIView to handle, you could just hook awakeFromNib of UIView and localize each kind of view.

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