Allow exporting to one JSON file per language
tcitworld opened this issue · 3 comments
tcitworld commented
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
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
Looks perfect, I can even load locales dynamically using this.
lzurbriggen commented
Released with 2.2.0