Hacker News new | ask | show | jobs
by falbala 2109 days ago
Nice work! What's the difference between this and .po/.mo files and the ugettext standard?
3 comments

Update:

As far as I know, this should be a subset of the PO format (http://pology.nedohodnik.net/doc/user/en_US/ch-poformat.html....).

The file format used by a18n is JSON, where its keys are extracted from code (using `a18n extract`) into one of these formats:

- "static text"

- "dynamic text with one variable: %s"

- "dynamic text with multiple variables: %1, %2, %3"

- "#some.text.id" or "xxx#some.text.id" -- user manually assign text an ID with: a18n("xxx", {_: "some.text.id"})

(It worth noting that my company further converts this JSON to Excel before sending to translators)

Thank you for asking this question - it lead me to find this library (and I think the quickstart highlights some differences to how the gnu gettext standard could be leveraged in js/ts vs a "propiatary" solution based on json) :

https://ttag.js.org/

https://ttag.js.org/docs/quickstart.html

Thanks for feedback! It looks like a decent lib and I would recommend anyone who need richer i18n support (like plural forms) take a look.

As for a18n, it's a deliberate choice to use current format (JSON with extracted key/value pair) instead of standard like ICU messageformat. Here are reasons:

1. This lib is built to enable automated i18n workflow for existing projects (~200kloc), with minimal human interfere and impose minimal complexity for build configuration, in this regard current format is working great.

2. This lib is used by both projects, plugins and components in our company, so to keep its footprint down (in case it's not deduped by bundler), it means fewer features (like plural forms, date, list) are supported, and...

3. ...we originally planned to add support for ICU messageformat if these features are desired. But after two years in production, we found the demand is not too strong to justify the cost.

Thank you! I'm not familiar with .po/.mo/ugettext, will take a look and answer later.