jshmrtn / vue3-gettext

Translate Vue 3 applications with gettext.
https://jshmrtn.github.io/vue3-gettext/
MIT License
66 stars 23 forks source link

Allow exporting to one JSON file per language #17

Closed tcitworld closed 2 years ago

tcitworld commented 2 years ago

Using gettext-compile it was possible to export each language in their own JSON file, so that it can be dynamically loaded, something like:

@for lang in $(LOCALES); do \
        gettext-compile --output $(OUTPUT_DIR)/translations/$$lang.json $(OUTPUT_DIR)/locale/$$lang/app.po; \
done;

In next gettext_compile.ts doesn't support that. This could be handled with a split option under output in gettext.config.js.

lzurbriggen commented 2 years ago

Hi @tcitworld, I just released 2.2.0-alpha.1 with this feature.

Enable it in the config using config.output.splitJson and make sure your config.output.jsonPath (if set) ends with a directory, not a json file.

The locale json files containe their own locale keys, so postloading could work like this:

import italian from "./it_IT.json";

const language = useGettext();
language.translations = {
    ...language.translations,
    ...italian,
};

Please test this prerelease and let me know if it works for you.

tcitworld commented 2 years ago

Looks perfect, I can even load locales dynamically using this.

lzurbriggen commented 2 years ago

Released with 2.2.0