cibernox / svelte-intl-precompile

I18n library for Svelte.js that analyzes your keys at build time for max performance and minimal footprint
https://svelte-intl-precompile.com
ISC License
274 stars 13 forks source link

Add support for .json files #16

Closed uside closed 2 years ago

uside commented 2 years ago

By default it handles $locales/en.ts import, reads contents of en.json file and precompile it on the fly. Live reload supported too.

svelte.config.js:

precompileIntl('src/locales', '$locales')

__layout.svelte:

import en from '$locales/en.ts';

src/locales/en.json:

{"foot": "Test {count} {count, plural, =1 {foot} other {feet}}"}
cibernox commented 2 years ago

ovation

Thank you so much for this. I'll test this tomorrow on a project. However something we'd need is to handle both TS and JS files for this to be useful for a much people as possible.

cibernox commented 2 years ago

I just tested and it works perfectly!

Just a couple more requests.

uside commented 2 years ago

I can add third argument for plugin initialization that receives event emitter with async load method

const BigCorpLocales = new EventEmitter();
BigCorpLocales.load = async (localeCode) => {
  return asyncLoadLocaleFromService(localeCode);
};
BigCorpLocales.emit('change', 'en');

precompileIntl('src/locales', '$locales', BigCorpLocales);
cibernox commented 2 years ago

Let's keep it focused on the Jason thing, but I think it could be usefulin the future

cibernox commented 2 years ago

Thanks! I'll release a new minor version