alexanderwallin / node-gettext

A JavaScript implementation of gettext, a localization framework.
Other
188 stars 36 forks source link

How to convert PO response to JSON file that node-gettext understands? #40

Closed sabsaxo closed 6 years ago

ArmorDarks commented 6 years ago

I'd say it's rather not.

sabsaxo commented 6 years ago

Well, that's good to know ; ).

But I seem to have issues following the README …

I have JSON files exported from localise.biz (plain key/value format), and no matter how I try to access them I always get:

oh nose No translation was found for msgid "Login" in msgctxt "" and domain "messages"

»oh nose« <- yes, copy/paste from the readme

The translation object look like this (copied from the browser console):

Object { Login: "Ingresar", Password: "Contraseña", Register: "Registrarme", "Wrong-e-mail-or-password": "Dirección electrónica o contraseña incorrecta" }

And I try to access it using gt.gettext("Login").

I add translations like this: gt.addTranslations( this.locale , 'messages', this.trans_file );

also tried: gt.addTranslations( this.locale , 'messages', JSON.stringify( this.trans_file ) );

Where this.locale is a string like 'es', and this.trans_file is a JSON file imported like:

import es_trans from './translations/es_login_trans.json'; // the above output Object

But since the error states both 'msgid' and 'msgctxt' I suspect some formatting issue or missing setting(s) somewhere?

Any idea what I'm missing using this?

sabsaxo commented 6 years ago

OK, and NOW (after posting) I notice your comments on »Migrating from v1 to v2« ... hm hm. Sorry 'bout that.

sabsaxo commented 6 years ago

Unfortunately this only added to the total confusion : (

sabsaxo commented 6 years ago

How do I simply:

  1. Read a PO file (as a response) from a server somewhere
  2. Convert the response to a json file that node-gettext understands

?

This has taken me three days so far ... getting nowhere.

ArmorDarks commented 6 years ago

Maybe this will be helpful: https://github.com/LotusTM/Kotsu/blob/master/modules/gettext.js

alexanderwallin commented 6 years ago

In the Recipes section in the README, it says:

node-gettext expects all translations to be in the format specified by gettext-parser. Therefor, you should use that to parse .mo or .po files.