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

I need to develop or find some easy gettext-like library in JavaScript for browser-side translations. It is preferable that the same library can be used by node.js if I would like to translate the server side.

1) But, what are the real pros and cons of using .po and JavaScript gettext library files?
(Unlike JSON and jQuery globalization or the like?)

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

+8
javascript internationalization gettext po
source share
3 answers

1) But what are the real pros and cons of using .po and JavaScript gettext library files? The gettext format is quite common: - so if your server server uses the gettext format, you can share it with the client - translators may feel more comfortable with the gettext (or yaml) format than with the json format - there are many tools for it

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

Or you can use:

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

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

+14
source share

I would recommend using l10ns . For any project related to i18n, you need the following:

  • A good storage system that stores a localization string.
  • A good localization format that can handle complex formatting, not just simple strings. And by complex formatting, I mean a format that can handle multiple formatting, gender / context based formatting, number formatting, date formatting, etc.

There are very few tools that process both of these points. The most common solution is to use gettext with xgettext . xgettext is a tool that moves your source code to synchronize localization keys between source code and localization storage. Although gettext is not so good at handling point 2. For example, you cannot format a string with two plural words. Therefore, strings like I like 2 cats and 1 dog are very difficult to format. Multiple formatting is a very difficult task to solve and has many edge cases. Let's say that instead of loving only two cats, we like 2000. The correct formatted string would be I like 2,000 cats and 1 dog . Have you noticed at 2,000 ? Therefore, to correctly use the multiple gettext solution, we also need to use an external library to handle number formatting.

So, for point 2, which has a good localization format. I believe that ICU MessageFormat handles this best. It is a markup language that deals with l10n formatting and is used by many large companies such as Google, Apple and Yahoo. It handles the boundary cases with the multiple formatting mentioned above. It also handles many other types of complex formatting. For example, gender context, ordinal formatting, number formatting and date formatting, etc.

One tool that supports ICU MessageFormat and has l10ns built-in storage. It also supports xgettext . You write the source code and then synchronize your localization keys.

+2
source share

The benefits of using gettext is that it has many tools available, translators are used to use it, and you can easily share lines between your javascript and the rest of the interface.

You can create .po files from javascript using xgettext, although javascript is not supported by default. If you use the same function names and say you use perl (I think), it works more reliably. There are several tools for converting .po to json, or just use one of the j-get get implementations.

0
source share

All Articles