I18n-module: Trigger fallback when value is emptry

Created on 2 Nov 2020  ·  5Comments  ·  Source: nuxt-community/i18n-module

I use BabelEdit for managing my locale json files. A new item gets added to all json files. Good!
But that makes it very likely the editor forgets to add a translation.

In that case $t('some.nested.value') will return an empty string.

Is it possible to force nuxtI18n to use a fallback instead?

question❓

Most helpful comment

It seems like BabelEdit has an option to not save empty translations.

Screenshot 2020-11-02 at 23 05 23

All 5 comments

It seems like BabelEdit has an option to not save empty translations.

Screenshot 2020-11-02 at 23 05 23

Dude, I freakin love the internet.
Thank you very much :)

While this will work for my setup, not all devs in our team will probably use this tool.
So I'm still curious if we can force nuxt-i18n to (or vue-i18n for that matter) to fallback for empty values?

I'm not really planning to do anything to address this. I think the better approach is to make sure that the files are in the expected format in the first place. You could validate them from a commit hook for example.

Otherwise, you can try to play with defining custom fallback function through vueI18n options (https://i18n.nuxtjs.org/options-reference#vuei18n) but I'm not sure if you have access to all translations from there so it might require hacks).

😢

If you can find a clean solution for this then feel free to open a PR for consideration.

Was this page helpful?
0 / 5 - 0 ratings