国际化与笔尖。这是真的好主意吗? [英] Internationalization with Nibs. Is that really a good idea?

查看:111
本文介绍了国际化与笔尖。这是真的好主意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Apple文档中,他们说一个Nib通过将Nib翻译成多种语言来实现国际化。我现在想的是一个更糟糕但现实的情况:你做了一个巨大的用户界面。然后将其翻译成25种语言。所以你得到25个不同的笔尖。你也得到一个巨大的冗余在造型和定义的UI:25倍的相同的东西。相同的绑定,一样。只是文字是不同的。



所以,我真的认为这是一个非常糟糕的方法。相反,我宁愿链接所有文本从一个资源束或类似的东西。只是一个文本字符串,在运行时从相应的语言资源链接。然后你只有麻烦链接在文本,这真的没有使任何乐趣。但是,然后,您可以在您的UI上进行更改,而不必一遍又一遍地执行相同的步骤25次。每个笔尖都有一个新的Binding。那将是那么可怕!



现在,请告诉我我错了。苹果不假设我们做了这么奇怪的事情吗?

解决方案

本地化的情况是不理想的。虽然Cocoa UI元素在它们的大小(大小标记)中支持一些动态灵活性,但是很难在视图中排列它们,以便它们适应任何大小的文本。



正如恒昌指出,这通常意味着需要对每个本地化基础进行一些布局调整。 Apple支持一个称为增量本地化的过程,使用一个名为ibtool的工具,与您的开发人员工具捆绑在一起。该过程远不是直观的,并且似乎有一些细微的错误,但它有助于使过程更容易,比如说,手动单独维护25个不同的笔尖。该过程基本上包括将您对主要笔尖的更改映射到其他本地化笔尖。 Apple更详细地描述此过程:



https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html



为了避免这个痛苦的过程,有些人采取不同的方法。如果在视图的布局上妥协,您可以实现每个UI元素容纳最大的本地化字符串的情况。使用文本字段等的对齐特征,因此可以布置可接受的布局,但是对于具有最大字符串的定位所需的额外间隔通常对于字符串最短的语言造成不太理想的布局。如果你采用这种方法,你需要设计你的nibs,使控制器类在运行时用正确的本地化字符串填充nib的UI元素。

最后,一些开发者去以便将它们自己的重新布局应用到笔尖中的元素,从而针对已经在它们上设置的字符串的大小来优化它们。这将是上述策略的细化,其中单个nib在运行时被使用和操纵以实现期望的效果。


In the Apple Docs they say that a Nib enables internationalization by just translating the Nib into many languages. I am thinking now about a worse but realistic scenario: You have made a huge user interface. Then you translate this into 25 languages. So you get 25 different Nibs. You also get a huge redundancy in styling and defining the UI: 25 times the same stuff. Same Bindings, same everything. Just text is different.

So, I really think this is a very bad approach. Instead, I would prefer to just link in all texts from a resource bundle or something like that. Just a file with text strings, which is linked in at run time from the appropriate language resource. Then you only have "trouble" linking in the text which really doesnt make any fun. But then, you can do changes on your UI ONCE without having to do the same step 25 times over and over again. A new Binding in every nib. That would be so horrible!!

Now, please tell me I got that wrong. Apple does not assume that we do something so creazy?

解决方案

The localization situation is not ideal. Although Cocoa UI elements support some dynamic flexibility in their sizing (the ausosizing flags), it's very difficult to arrange them in a view so that they will accommodate any sized text.

As Heng-Cheong points out, this usually means that some adjustment to layout is required on a per-localization basis. Apple supports a process called incremental localization with a tool called "ibtool", bundled with your developer tools. The process is far from intuitive and seems to have some subtle bugs, but it helps to make the process easier than, say, separately maintaining 25 different nibs manually. The process essentially involves mapping changes you make to your primary nib onto the other localized nibs. Apple describes the process in more detail:

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html

In order to avoid this painful process, some people take a different approach. If you compromise on the layout of your views, you can achieve a situation where every UI element accommodates the largest localized string. Using the alignment features of text fields, etc., you can thus arrange an acceptable layout, though the extra spacing required for the localization with the largest strings often causes a less-than-ideal layout for the language whose strings are shortest. If you take this approach, you need to design your nibs so that a controller class populates the nib's UI elements with the correct localized strings at runtime.

Finally, some developers go so far as to apply their own relayout to the elements in a nib, optimizing them for the sizes of the strings that have been set upon them. This would be a refinement of the strategy above, where a single nib is used and manipulated at runtime to achieve the desired effect.

这篇关于国际化与笔尖。这是真的好主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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