i18n 中消息属性命名的正确方法是什么?
我们确实有一个应该翻译成不同语言的网站。消息属性文件中的某些措辞已准备好翻译。我现在想将其余文本添加到这些文件中。
命名文本块的好方法是什么?
<view>.<type>.<name>
我们主要有网页,并且某些元素/模块在某些网站上重复。
We do have a website which should be translate into different languages. Some of the wording is in message properties files ready for translation. I want now add the rest of the text into these files.
What is a good way to name the text blocks?
<view>.<type>.<name>
We mostly have webpages and some of the elements/modules are repeating on some sites.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
据我所知,不存在“标准”。因此,很难区分什么是正确的、什么是不正确的资源键命名方式。然而,根据我的经验,我可以推荐这种方式:
我们可以讨论将一个模块中的每个字符串放入一个属性文件中是否是正确的方法 - 如果更新不经常发生并且没有那么频繁,那么可能是正确的很多消息。否则,您可能会考虑每个视图一个文件。
至于关键命名策略:对于翻译者来说(听起来像尊敬的州长阿诺德·S. 的电影不是吗?)有一个上下文非常重要。翻译实际上可能取决于它,即在波兰语中,如果消息是页面/对话框/任何标题,则您将以不同的方式翻译消息;如果消息是按钮上的文本,则以完全不同的方式翻译。
此类资源键的一个示例可能是:
它向翻译器提供了有关其实际含义的足够提示,这可能会导致正确的翻译......
As far as I know, no "standard" exists. Therefore it is pretty hard to tell what is proper and what is improper way of naming resource keys. However, based on my experience, I could recommend this way:
We may discuss if it is proper way to put every strings from one module into one property files - probably it could be right if updates doesn't happen often and there are not so many messages. Otherwise you might think about one file per view.
As for key naming strategy: it is important for the Translator (sounds like film with honorable governor Arnold S. isn't it?) to have a Context. Translation may actually depend on it, i.e. in Polish you would translate a message in a different way if it is page/dialog/whatever title and in totally different way if it is text on a button.
One example of such resource key could be:
It gives enough hints to the Translator about what it actually is, which could result in correct translation...
我们使用点表示法和驼峰式大小写提出了以下键命名约定(Java,btw):
标签键(表单标签、页面/表单/应用程序标题等......即,不完整句子;用于多个 UI 位置):
如果标签表示 Java 字段(即表单字段)并与表单标签匹配:label.nameOfField
其他:label.sameAsValue
示例:
内容键:
< strong>projectName.uiPath.messageOrContentType.n.*
其中:
当页面上有多个内容区域并且需要进一步分解一个或多个内容区域时(基于上面的 HTML 示例),可以将辅助数字标识符附加到键上。示例:...content.1.1、...content.1.2
示例:
优点/缺点:
+ 标签键可以轻松重复使用;位置无关紧要。
+ 对于不重复使用的内容键,在 UI 上定位页面将变得简单且合乎逻辑。
- 翻译人员可能不清楚标签键位于 UI 上的位置。对于不浏览页面的翻译人员来说,这可能不是问题,但对于开发人员来说可能仍然是一个问题。
- 如果内容键必须在 UI 上的多个位置使用(这种情况很有可能),则键名称选择在其他位置将没有意义。在我们的例子中,管理层不关心内容区域的值重复,因此在这种情况下我们将使用不同的键(以演示 UI 上的位置)。
对这一公约的反馈——尤其是能够改进它的反馈——将不胜感激,因为我们目前正在改进我们的资源包! :)
We have come up with the following key naming convention (Java, btw) using dot notation and camel case:
Label Keys (form labels, page/form/app titles, etc...i.e., not full sentences; used in multiple UI locations):
If the label represents a Java field (i.e., a form field) and matches the form label: label.nameOfField
Else: label.sameAsValue
Examples:
Content Keys:
projectName.uiPath.messageOrContentType.n.*
Where:
When there are multiple content areas on a page and one or more need to be further broken up (based on the HTML example above), a secondary numeric identifier may be appended to the key. Example: ...content.1.1, ...content.1.2
Examples:
Advantages / Disadvantages:
+ Label keys can easily be reused; location is irrelevant.
+ For content keys that are not reused, locating the page on the UI will be simple and logical.
- It may not be clear to translators where label keys reside on the UI. This may be a non-issue for translators who do not navigate the pages, but may still be an issue for developers.
- If content keys must be used in more than one location on the UI (which is highly likely), the key name choice will not make sense in the other location(s). In our case, management is not concerned with a duplication of values for content areas, so we will be using different keys (to demonstrate the location on the UI) in this case.
Feedback on this convention - especially feedback that will improve it - would be much appreciated since we are currently revamping our resource bundles! :)
我建议采用以下约定,
这样您就可以在超级上下文中对所有常见消息进行逻辑分组(下面示例中的 id )。有一些东西不是特定于任何功能上下文(如姓氏等)的,您可以将其分组为逻辑上下文。
I'd propose the below convention
This way you can logically group all the common messages in a super context (id in the below example). There are few things that aren't specific to any functional context (like lastName etc) which you can group into logical-context.
我个人使用过并且到目前为止我更喜欢的方法是使用句子来本地化作为关键。例如:(请根据语言将 T 替换为正确的语法)
例如:
print(T("Hello world"))
在这种情况下 T 将搜索键“Hello world”。如果没有找到则返回键,否则返回键的值。
这样,您不需要编辑消息(以您的默认语言),至少您需要使用参数......它节省了我很多开发时间
the method that I have personally used and that I've liked more so far is using sentence to localisee as the key. For example: (pls replace T with the right syntax dependably on the language)
for example:
print(T("Hello world"))
in this case T will search for a key "Hello world". If it is not found then the key is returned, otherwise the value of the key.
In this way, you do not need to edit the message (in your default language) at least that you need to use parameters.... It saved me a LOT of dev time