A
A
Andrew2021-02-20 09:56:20
Internationalization and localization
Andrew, 2021-02-20 09:56:20

How to translate strings with vue i18n passed to data/computed?

Hey!

If you pass localized strings like this:

data() {
  return {
     title: this.$t('main.title')
  }
}

Then when you change the language, they will not be updated, all sorts of crutches come to mind - re-render the component or the entire application or prescribe string keys in data, and already insert {{ $t(item.name) }}.

The second works in simple cases, but there are times when a string needs to be passed as a prop/attribute, in which case the key parsing logic will have to be implemented in each component that accepts localized strings.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question