yargs / y18n

:ledger: the bare-bones i18n library used by yargs
ISC License
146 stars 48 forks source link

Make it so that it's easier to load translations dynamically #60

Open zakkudo opened 6 years ago

zakkudo commented 6 years ago

I wrote a static parser for webpack that reads the source files and uses y18n to generate the json file. But cache isn't part of the public api and there is no way to keep readFile from being called in a browser. Is there any way to make this more flexible?

https://github.com/zakkudo/translation-static-analyzer https://github.com/zakkudo/translate-webpack-plugin

I plan on making npm packages by next week for this, which will be a bit easier to test with....

zakkudo commented 6 years ago

As it is now, to work around it I have to do:

import y18n from 'y18n';
const instance = y18n({updateFiles: false});
instance.setLocale('language');
instance.cache['language'] = {};

const translation = instance.__('translate this!');