i18n 中消息属性命名的正确方法是什么?

发布于 2024-10-06 05:44:51 字数 186 浏览 3 评论 0原文

我们确实有一个应该翻译成不同语言的网站。消息属性文件中的某些措辞已准备好翻译。我现在想将其余文本添加到这些文件中。

命名文本块的好方法是什么?

<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 技术交流群。

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

发布评论

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

评论(4

故事未完 2024-10-13 05:44:51

据我所知,不存在“标准”。因此,很难区分什么是正确的、什么是不正确的资源键命名方式。然而,根据我的经验,我可以推荐这种方式:

property file name: <module>.properties
resource keys: <view or dialog>[.<sub-context>].<control-type>.<name>

我们可以讨论将一个模块中的每个字符串放入一个属性文件中是否是正确的方法 - 如果更新不经常发生并且没有那么频繁,那么可能是正确的很多消息。否则,您可能会考虑每个视图一个文件。

至于关键命名策略:对于翻译者来说(听起来像尊敬的州长阿诺德·S. 的电影不是吗?)有一个上下文非常重要。翻译实际上可能取决于它,即在波兰语中,如果消息是页面/对话框/任何标题,则您将以不同的方式翻译消息;如果消息是按钮上的文本,则以完全不同的方式翻译。

此类资源键的一个示例可能是:

preferences.password_area.label.username=User name

它向翻译器提供了有关其实际含义的足够提示,这可能会导致正确的翻译......

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:

property file name: <module>.properties
resource keys: <view or dialog>[.<sub-context>].<control-type>.<name>

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:

preferences.password_area.label.username=User name

It gives enough hints to the Translator about what it actually is, which could result in correct translation...

池木 2024-10-13 05:44:51

我们使用点表示法和驼峰式大小写提出了以下键命名约定(Java,btw):

标签键(表单标签、页面/表单/应用程序标题等......即,不完整句子;用于多个 UI 位置):

如果标签表示 Java 字段(即表单字段)并与表单标签匹配:label.nameOfField
其他:label.sameAsValue

示例:

  • label.firstName = 名字
  • label.lastName = 姓氏
  • label.applicationTitle = 应用程序标题
  • label.editADocument = 编辑文档

内容键:

< strong>projectName.uiPath.messageOrContentType.n.*

其中:

  • projectName 是项目的短名称(或来自 Java 包的派生名称)
  • uiPath是内容键
  • messageOrContentType 的 UI 导航路径(例如,添加、删除、更新、信息、警告、错误、标题、内容等),应根据内容类型添加。消息示例: (1) 页面已更新。 (2) 处理您的请求时出错。
  • n.* 处理以下情况:当单个页面上有多个内容区域时(例如,当内容被图像等分隔时)、当内容位于多个段落中或当内容位于(无)排序列表中 - 应附加数字标识符。示例:...content.1...content.2

    当页面上有多个内容区域并且需要进一步分解一个或多个内容区域时(基于上面的 HTML 示例),可以将辅助数字标识符附加到键上。示例:...content.1.1...content.1.2

示例:

  • training.mySetup.myInfo.content.1 = 这是内容 1 的第一句。这是内容1的第二句。该内容将被段落标签包围。
  • Training.mySetup.myInfo.content.2 = 这是内容 2 的第一句。这是内容 2 的第二句。该内容也将被段落标签包围。
  • Training.mySetup.myInfo.title = 我的信息
  • training.mySetup.myInfo.updated = 您的个人信息已更新。

优点/缺点


+ 标签键可以轻松重复使用;位置无关紧要。
+ 对于不重复使用的内容键,在 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:

  • label.firstName = First Name
  • label.lastName = Last Name
  • label.applicationTitle = Application Title
  • label.editADocument = Edit a Document

Content Keys:

projectName.uiPath.messageOrContentType.n.*

Where:

  • projectName is the short name of the project (or a derived name from the Java package)
  • uiPath is the UI navigation path to the content key
  • messageOrContentType (e.g., added, deleted, updated, info, warning, error, title, content, etc.) should be added based on the type of content. Example messages: (1) The page has been updated. (2) There was an error processing your request.
  • n.* handles the following cases: When there are multiple content areas on a single page (e.g., when the content is separated by, an image, etc), when content is in multiple paragraphs or when content is in an (un)ordered list - a numeric identifier should be appended. Example: ...content.1, ...content.2

    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:

  • training.mySetup.myInfo.content.1 = This is the first sentence of content 1. This is the second sentence of content 1. This content will be surrounded by paragraph tags.
  • training.mySetup.myInfo.content.2 = This is the first sentence of content 2. This is the second sentence of content 2. This content will also be surrounded by paragraph tags.
  • training.mySetup.myInfo.title = My Information
  • training.mySetup.myInfo.updated = Your personal information has been updated.

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! :)

貪欢 2024-10-13 05:44:51

我建议采用以下约定,

functionalcontext.subcontext.key
logicalcontext.subcontext.key

这样您就可以在超级上下文中对所有常见消息进行逻辑分组(下面示例中的 id )。有一些东西不是特定于任何功能上下文(如姓氏等)的,您可以将其分组为逻辑上下文。

order.id=Order Id
order.submission.submit=Submit Order
name.last=Last Name

I'd propose the below convention

functionalcontext.subcontext.key
logicalcontext.subcontext.key

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.

order.id=Order Id
order.submission.submit=Submit Order
name.last=Last Name
以酷 2024-10-13 05:44:51

我个人使用过并且到目前为止我更喜欢的方法是使用句子来本地化作为关键。例如:(请根据语言将 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

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