javascript .po 文件和 gettext VS JSON 和自定义 i18n 库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8121575/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 02:22:25  来源:igfitidea点击:

.po files and gettext VS JSON and custom i18n library?

javascriptnode.jsinternationalizationgettextpo

提问by dani

I need to develop or find some sort of lightweight gettext-like library in JavaScript for browser-side translations. Preferably the same library could be used by node.js if I'd like to translate server-side instead.

我需要在 JavaScript 中开发或找到某种轻量级的类似 gettext 的库,用于浏览器端的翻译。如果我想转而翻译服务器端,最好可以由 node.js 使用相同的库。

1) But, what are really the pros and cons of using .po files and a JavaScript gettext library?
(As opposed to JSON and jQuery Globalize or similar?)

1) 但是,使用 .po 文件和 JavaScript gettext 库的真正优缺点是什么?
(相对于 JSON 和 jQuery Globalize 或类似的?)

2) And is there any workflow/service that'll allow crowdsourcing of translations that can be exported to a format (.po/json) that can be used by a JavaScript i18n library (gettext implementation, Globalize.js etc.)?

2) 是否有任何工作流程/服务允许众包翻译,这些翻译可以导出为 JavaScript i18n 库(gettext 实现、Globalize.js 等)可以使用的格式(.po/json)?

回答by jamuhl

1) But, what are really the pros and cons of using .po files and a JavaScript gettext library?gettext format is rather common: - so if your serverside is using gettext format already you might share it with client - translators might feel more comfortable with gettext format (or yaml) than with json format - there is a lot of tooling around for it

1) 但是,使用 .po 文件和 JavaScript gettext 库的真正优缺点是什么?gettext 格式相当常见: - 因此,如果您的服务器端已经在使用 gettext 格式,您可能会与客户端共享它 - 翻译人员可能会觉得 gettext 格式(或 yaml)比使用 json 格式更舒服 - 有很多工具可以用于它

I personally don't like the translation functions build around gettext - feels clumpsy to me, where lightweight javascript libraries (like http://i18next.com) feel better.

我个人不喜欢围绕 gettext 构建的翻译功能 - 对我来说感觉很笨拙,轻量级 javascript 库(如http://i18next.com)感觉更好。

Libs you could use:

你可以使用的库:

  • jedcomes with pure gettext implementation
  • i18nextsupports gettext files but uses a json approach for translation functions
  • jed带有纯 gettext 实现
  • i18next支持 gettext 文件,但使用 json 方法进行翻译功能

2) And is there any workflow/service that'll allow crowdsourcing of translations that can be exported to a format (.po/json) that can be used by a JavaScript i18n library (gettext implementation, Globalize.js etc.)?

2) 是否有任何工作流程/服务允许众包翻译,这些翻译可以导出为 JavaScript i18n 库(gettext 实现、Globalize.js 等)可以使用的格式(.po/json)?

回答by dsas

Pros of using gettext is that there are lots of tools available for it, translators are used to using it and you can easily share strings between your javascript and the rest of the front-end.

使用 gettext 的优点是有很多可用的工具,翻译人员习惯使用它,您可以轻松地在 javascript 和前端的其余部分之间共享字符串。

You can generate .po files from javascript using xgettext, though javascript is not supported by default. If you use the same function names and tell it you're using perl (I think) it works more reliably. There are a few tools to convert .po to json, or just use one of the gettext js implementations.

您可以使用 xgettext 从 javascript 生成 .po 文件,但默认情况下不支持 javascript。如果您使用相同的函数名称并告诉它您使用的是 perl(我认为),它会更可靠地工作。有一些工具可以将 .po 转换为 json,或者只使用 gettext js 实现之一。