简体   繁体   English

Java类型的i18n(java)

[英]Java typed i18n (java)

I'd like to know if it's possible (and with which tooling) to do typesafe i18n in Java. 我想知道是否有可能(以及使用哪种工具)在Java中进行typesafe i18n。 Maybe it's not clear so here are some details, assuming we use something based on MessageFormat 也许不清楚,所以这里有一些细节,假设我们使用基于MessageFormat东西

1) Translate using typesafe parameters 1)使用类型安全参数进行翻译

I'd like to avoid having an interface like String translate(Object key,Object... values) where the values are untyped. 我想避免使用像String translate(Object key,Object... values)这样的接口String translate(Object key,Object... values)其中的值是无类型的。 It should be impossible to call with a bad parameter type. 用错误的参数类型调用应该是不可能的。

Note I'm fine specifying the typing of all the keys. 注意,我可以指定所有键的类型。 The solution I'm looking for should be scalable and should not increase the backend startup time significantly. 我正在寻找的解决方案应该是可扩展的,并且不应显着增加后端启动时间。

2) It should be known at compile time which keys are still used 2)在编译时应该知道哪些键仍在使用

I don't want my translation keys base to be like many websites' CSS, growing and growing forever and everybody being frightened to remove keys because we don't know easily if they are still useful or not. 我不希望我的翻译密钥像许多网站的CSS一样,永远增长,并且每个人都害怕删除密钥,因为我们不容易知道它们是否仍然有用。

In JS/React land there is babel-plugin-react-intl which permit to extract at compile time the translation keys that are still found in the code. 在JS / React领域中,有babel-plugin-react-intl ,它允许在编译时提取仍在代码中找到的转换键。 Then we can diff these keys with our translation backend/SaaS and delete the unused keys automatically. 然后,我们可以将这些密钥与翻译后端/ SaaS进行比较,并自动删除未使用的密钥。 Is there anything close to that experience in Java land? 在Java领域中,有没有什么接近这种体验的?


I'm looking for: 我在找:

  • any trick you have that could make i18n more manageable in Java regarding these 2 problems I have 关于这两个问题,您有任何可以使i18n在Java中更易于管理的技巧
  • current tooling that might help me solve the problem 当前的工具可能会帮助我解决问题
  • hints on how to implement something custom if tooling does not exist 有关在不存在工具的情况下如何实现自定义的提示

Also, is Enum suitable to store a huge fixed list of translation keys? 另外,Enum是否适合存储庞大的固定翻译键列表?

Translation keys are an open ended domain. 转换键是一个开放式域。 For a closed domain an enum would do. 对于封闭域,可以使用枚举。

Having something like enums or constant lists likely causes a growth of different enums, constants classes. 具有枚举或常量列表之类的内容可能会导致不同的枚举,常量类的增长。

And then there is the very important perspective of the translating business: you would want at least one glossary (not needing translation occurrences), structurally equal phrases grouped, comments maybe on ambivalent terms and usages (button/menu). 然后是翻译业务的一个非常重要的角度:您需要至少一个词汇表 (不需要翻译),结构上相等的短语进行分组,注释可能包含歧义的术语和用法(按钮/菜单)。 This can reduce the time costs and improve the quality. 这样可以减少时间成本并提高质量。 There also are things like online-help. 还有诸如在线帮助之类的东西。

Up till now XML, like simple docbook / translation memory (tmx/xliff/...), was sufficient for that. 到目前为止,XML就像简单的docbook /翻译记忆库(tmx / xliff / ...)一样,已经足够了。 And the tooling including different forms of evaluation was done ourselves. 包括不同形式的评估在内的工具都是我们自己完成的。

I hope a more professional answer will be given, but my answer might shed some light on the desired functionality: 我希望会给出更专业的答案,但我的答案可能会为所需的功能提供一些启示:

  • translation centric: as that needs the most work. 以翻译为中心:这需要最多的工作。
  • version control: some text lists involved. 版本控制:涉及一些文本列表。
  • checking tools: what you mentioned, integrity, missing, almost equal. 检查工具:您提到的内容,完整性,缺失,几乎相等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM