字符串和标签的本地化和全球化的最佳实践 [英] Best practice for localization and globalization of strings and labels

查看:211
本文介绍了字符串和标签的本地化和全球化的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个拥有20多名开发人员的团队成员。每个开发人员都在一个单独的模块上工作(接近10个模块)。在每个模块中,我们可能至少有50个CRUD表单,这意味着我们目前有近500个添加按钮保存按钮编辑按钮,等等。

I'm a member of a team with more than 20 developers. Each developer works on a separate module (something near 10 modules). In each module we might have at least 50 CRUD forms, which means that we currently have near 500 add buttons, save buttons, edit buttons, etc.

但是,因为我们想要使我们的应用程序全球化,所以我们需要能够在我们的应用程序中翻译文本。例如,在任何地方,添加一词应该成为法国用户的 ajouter

However, because we want to globalized our application, we need to be able to translate texts in our application. For example, everywhere, the word add should become ajouter for French users.

我们做过什么直到现在,对于UI或表示层中的每个视图,我们都有一个关键/值对翻译的字典。然后在渲染视图时,我们使用此字典翻译所需的文本和字符串。然而,这种方法,我们已经在500个字典中接近500 add 。这意味着我们已经违反了DRY本金。

What we've done till now, is that for each view in UI or Presentation Layer, we have a dictionary of key/value pairs of translations. Then while rendering the view, we translate required texts and strings using this dictionary. However, this approach, we've come to have something near 500 add in 500 dictionaries. This means that we've breached DRY principal.

另一方面,如果我们集中常见字符串,例如将添加放在一个地方,并要求开发人员在任何地方使用它,我们遇到的问题是不确定字符串是否已在集中字典中定义。

On the other hand, if we centralize common strings, like putting add in one place, and ask developers to use it everywhere, we encounter the problem of not being sure if a string is already defined in the centralized dictionary or not.

另外一个选项可能是没有翻译词典,并使用谷歌翻译,Bing翻译等在线翻译服务。

One other options might be to have no translation dictionary and use online translation services like Google Translate, Bing Translator, etc.

我们遇到的另一个问题是一些开发人员面临着提供项目准时无法记住翻译密钥。例如,对于添加按钮的文本,开发人员使用添加,而其他开发人员使用等。

Another problem that we've encountered is that some developers under the stress of delivering the project on-time can't remember the translation keys. For example, for the text of the add button, a developer has used add while another developer has used new, etc.

应用程序字符串资源的全球化和本地化的最佳实践或最着名的方法是什么?

What is the best practice, or most well-known method for globalization and localization of string resources of an application?

推荐答案

据我所知,有一个很好的库叫做 localeplanet ,用于JavaScript中的本地化和国际化。此外,我认为它是原生的,并且与其他库没有依赖关系(例如jQuery)

As far as I know, there's a good library called localeplanet for Localization and Internationalization in JavaScript. Furthermore, I think it's native and has no dependencies to other libraries (e.g. jQuery)

这是图书馆的网站: http://www.localeplanet.com/

另外看看Mozilla的这篇文章,你可以找到非常好的客户端翻译方法和算法: http://blog.mozilla.org/webdev/2011/10/06/i18njs-internationalize-your-javascript-with-a-little-help -from-json-and-the-server /

Also look at this article by Mozilla, you can find very good method and algorithms for client-side translation: http://blog.mozilla.org/webdev/2011/10/06/i18njs-internationalize-your-javascript-with-a-little-help-from-json-and-the-server/

所有这些文章/库的共同部分是他们使用 i18n class和一个 get 方法(在某些方面还定义了一个较小的函数名,如 _ )用于检索/转换。在我的解释中,表示要翻译的字符串,表示翻译的字符串。

然后,您只需要一个JSON文档来存储 key

The common part of all those articles/libraries is that they use a i18n class and a get method (in some ways also defining an smaller function name like _) for retrieving/converting the key to the value. In my explaining the key means that string you want to translate and the value means translated string.
Then, you just need a JSON document to store key's and value's.

例如:

var _ = document.webL10n.get;
alert(_('test'));

这里是JSON:

{ test: "blah blah" }

我相信使用当前流行的库解决方案是一种很好的方法。

I believe using current popular libraries solutions is a good approach.

这篇关于字符串和标签的本地化和全球化的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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