Option to merge .pot files
Ninowis opened this issue · 1 comments
Is there any way to merge or specify several .pot files before extracting them to .po files?
This would be really handy when extracting from several sources, or when we need to add additional custom keys (for example to translate dynamic text coming from an external source) which just get removed from the .pot and .po files otherwise when running the extract command.
I believe the original xgettext
program from GNU gettext utilities (https://www.gnu.org/software/gettext/manual/html_node/xgettext-Invocation.html) allows to specify several input files and concatenate them into one as suggested in the answers here: https://stackoverflow.com/questions/4052736/how-can-i-merge-2-pot-files-translation-files
Another option could be using the merge
option and/or dgettext
domains as suggested in this elixir implementation https://stackoverflow.com/questions/37411810/add-gettext-translation-keys-manually (which is basically what I was trying to do)
@Ninowis
I do not plan to personally implement this. I think specialized use-cases like this can be handled in userland, but you are free to open a PR.
We had a similar case in one of our projects. This is not a guide, just an example of how somehting like this could be handled.
The way we dealt with it is by having two .pot separate .pot files (each .pot has their own translated .po files) and then merging the compiled json files.
All you need for this is to have separate gettext configs that point to the different paths of your .pots and then call vue-gettext-compile
for each config/.pot:
vue-gettext-compile --config=gettext.backend.config.js
And then deep-merge the jsons:
import backendTranslations from "./backend/translations.json";
import frontendTranslations from "./frontend/translations.json";
import { merge } from "lodash";
import { createGettext, normalizeTranslations } from "vue3-gettext";
const translations = merge(
normalizeTranslations(backendTranslations),
normalizeTranslations(frontendTranslations)
);
createGettext({
translations,
...
});
normalizeTranslations
is undocumented, it has not been battle-tested.