使用“用户定义的运行时属性”在故事板中本地化视图。 [英] Localize a view within a storyboard using "User Defined Runtime Attributes"

查看:89
本文介绍了使用“用户定义的运行时属性”在故事板中本地化视图。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个半 - 自动化方式本地化我的观点。然而,今天我在IB中发现了一个有趣的部分,这似乎表明我可以在Interface Builder中本地化我的视图。

I currently have a semi-automated way to localize my views. However, today I found an interesting section in IB, which seems to suggest that I can localize my views from within Interface Builder.

所以在IB中你可以定义运行时属性Identity Inspector中的选定对象。所以对于我的 UILabel 我可以将我的标签的 text keypath设置为String Hello World

So in IB you can define runtime attributes for a selected object in the Identity Inspector. So for my UILabel I can set the text keypath of my label to the String Hello World.

但是,当我选择 Type = Localized String 然后输入名称时我的 Localized.strings中的一个键我没有得到翻译的字符串,而只是我在IB中输入的值(因此是键)。

However, when I choose the Type = Localized String and then the name of a key in my Localized.strings I don't get a translated string but rather just the value (hence the key) which I entered in IB.

我不明白,这种机制应该如何运作。我会 能够翻译我的观点,这样,任何想法?

I don't understand, how this mechanism is supposed to work. I would love to be able to translate my views like this, any ideas?

推荐答案

用户定义的运行时属性记录很少。从我读过的一本书中我记得的是,UDRA最初是为MacOSX编程实现的,因此TypeLocalized String可能是目前iOS中尚未完全支持的功能。

The "user defined runtime attributes" are poorly documented. What I can remember from some book I read is, that UDRA was first implemented for MacOSX programming, so the Type "Localized String" could be a feature that is not fully supported for now in iOS.

有趣的是,他正在翻译故事板预览中的字符串(xCode 4.5.1),但后来在编译的iOS应用程序中,他只是注入了关键字符串。

The funny thing is, that he is translating the strings in the storyboard previews (xCode 4.5.1), but later in the compiled iOS app, he is just injecting the key string.

我现在正在考虑的一个解决方案是创建一个小帮助类,即检查viewDidLoad上关键字的视图的标题/文本字符串像钥匙,例如XYControllerTitleKey,然后对此制作NSLocalizedString-Method。

One solution I am thinking about right now, is to make a little helper class, that is checking the title/text strings of views on viewDidLoad for a keyword like "key", e.g. "XYControllerTitleKey", and then make NSLocalizedString-Method on that.

更新:
似乎在此期间,有一种使用UDRA的方法:

UPDATE: It seems that in the meantime, there is a way to use the UDRAs:

故事板/ XIB和本地化最佳实践

作为结果的教程( link

这篇关于使用“用户定义的运行时属性”在故事板中本地化视图。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆