R
R
riddlr2018-10-28 14:42:43
Vue.js
riddlr, 2018-10-28 14:42:43

How to not show element if no translation exists (i18n with Vue/Nuxt)?

Question about vue-i18neither module nuxt-i18n
If the data translation does not exist, how to show nothing at all?
Just turning it off fallbackLocalestill shows the name of the key, instead of the data.
For example This exists only in English. If I switch to another language the browser shows me the . What the hell, damn it? I don't want to show anything. Is there a way to check if a translation exists? But this is also a bad option, to cling to each element with localization looks like complete idiocy.
<h3>{{ $t('anotherMessage') }}</h3>
anotherMessage
v-if

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2018-10-28
@riddlr

But this is also a bad option, cling v-if to each element with localization looks like complete idiocy.

However, this is the only option. At least I didn't manage to win it at the time. You will have to sculpt checks like this:
UPD: Working version:
v-if="'anotherMessage' in $i18n.messages[$i18n.locale]"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question