mashpie / i18n-node

Lightweight simple translation module for node.js / express.js with dynamic json storage. Uses common __('...') syntax in app and templates.
MIT License
3.09k stars 421 forks source link

en.js should work normal #408

Closed raksa closed 1 year ago

raksa commented 5 years ago

in locale i need en.js

module.exports = { "hello": "Hello", };

with:

i18n.configure({ extension: ".js", updateFiles: false, ... });

should work as normal

rimiti commented 4 years ago

Is any update about this issue? @mashpie

raksa commented 4 years ago

Is any update about this issue? @mashpie

Check here it’s working https://github.com/raksa/i18n-node

mashpie commented 4 years ago

.json is the only supported storage by now. Native, no deps, no eval, no vulnerabilties. Plus: anyone van transpile almost anything to json.

No eta but a new 1.x branch will add pluggable Storage interface. Let there be yaml, toml, csv, tsv, ini, js or Redis, mongo, Couch, sql.

Internally all those will be processed as js objects to any extend... and by now json represents the serialized Version of that object in a native cheapest human read/writable way possible.

rimiti commented 4 years ago

Thank you for you answers. Just so you, I moved to i18n-next and it works fine.

mashpie commented 4 years ago

Alright, I like i18n-next as a framework with it's plugins and adapters while i18n-node intended to be a lib not a framework. Do you also plan to try integration with https://locize.com/ (just curious)?

rimiti commented 4 years ago

I'm using i18n-next as i18n-node. I'm exporting my js translations and it works well. I was happy to use your package but it's very useful to use .js extension if you're coding in TS.

PS: I don't plan to use locize.com service ;)

mashpie commented 4 years ago

...ts I see - well, what I am thinking of is to add a setCatalog() as the logikal counterpart to getCatalog() https://github.com/mashpie/i18n-node#i18ngetcatalog

That would open up loading translations programmatically from any external source anyway and give devs complete control. Like in this case just require() these .js modules and set them, like:

// en.js
module.exports = {
  'Ola': 'Hi'
}

// any app.js
const transEN = require('./en.js')

i18n.setCatalog(transEN, 'en')

or maybe

// myTranslations.js
module.exports = {
  'en': {
    'Ola': 'Hi'
  },
  'de': {
    'Ola': 'Hallo'
  }
}

// any app.js
const translations = require('./myTranslations.js')

i18n.setCatalog(translations)

plus options for adding, merging and similar edge cases (fallbacks, contexts, etc.)

Ok, let's keep this open as note of WIP

bfischetti commented 1 year ago

Any news on this feature @mashpie ?

mashpie commented 1 year ago

actually this should be resolved by https://github.com/mashpie/i18n-node#some-words-on-staticcatalog-option