Jed icon indicating copy to clipboard operation
Jed copied to clipboard

Load dinamically locale_data

Open raurodse opened this issue 9 years ago • 4 comments

is it possible change locale_data dinamically when JED object is already created?

raurodse avatar Mar 03 '15 10:03 raurodse

Feels like a hack, but this works: Load the translations, in Jed's format, using po2json or whatever

const translations = po2json.parse(poFileContent, { format: 'jed1.x' });
const i18n = new Jed({});  // Empty instance

Later...

Object.assign(i18n.options, translations);

then...

console.log(i18n.gettext('My string'));

mandx avatar Dec 07 '16 21:12 mandx

Hello, what about to make this functionality in Jed method?

In my cases i need to load additional translations dynamically and i don't want write this hack.

Suhoy95 avatar May 17 '17 06:05 Suhoy95

I would not consider this a hack. You're just adding more keys to the translation object. On Wed, May 17, 2017 at 1:54 AM Илья Сухоплюев [email protected] wrote:

Hello, what about to make this functionality in Jed method?

In my cases i need to load additional translations dynamically and i don't want write this hack.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/messageformat/Jed/issues/37#issuecomment-302002562, or mute the thread https://github.com/notifications/unsubscribe-auth/AAF5KnLspBb8Ij6qZgqx6Y_p7_mB6fvMks5r6pm7gaJpZM4Don1G .

SlexAxton avatar May 17 '17 18:05 SlexAxton

Ok. Maybe it should be in documentation that new Jed (options) and i18n.options have identical structure. And we can change this data safely if i keep structure's integrity (or something similar, it may require more conditions to keep i18n-object in work state).

However, i have realized that creation of new i18n-object is more dumb and clear way in cases where this trick may be appropriate.

Suhoy95 avatar May 17 '17 19:05 Suhoy95