最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - .po files and gettext VS JSON and custom i18n library? - Stack Overflow

programmeradmin0浏览0评论

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.

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?)

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.)?

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.

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?)

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.)?

Share Improve this question edited Mar 26, 2013 at 20:41 Lemmings19 1,4713 gold badges24 silver badges38 bronze badges asked Nov 14, 2011 at 12:27 danidani 5,0008 gold badges57 silver badges96 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 20

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

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.

Libs you could use:

  • jed comes with pure gettext implementation
  • i18next supports gettext files but uses a json approach for translation functions

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.)?

  • http://webtranslateit.com/ might be something interesting
  • http://i18next.com comes with some translation UI you might use

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.

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.

发布评论

评论列表(0)

  1. 暂无评论