D
D
Dmitry2020-08-27 20:57:51
JavaScript
Dmitry, 2020-08-27 20:57:51

How to localize object fields?

I have an array of objects from which I print out the v-for field names:

info: [
          {
              name: 'Name',
              value: '',
              pattern: /^[a-zA-Z ]{2,30}$/
           },
         ]


How can I localize the name field using the i18n library? $.t in the object does not roll (it is understandable).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aetae, 2020-08-27
@Tim308

a) Localize in the template itself, store the i18n label in name.
b) Give an array from the computed property.
c) Generate an array in the data() function before putting it in the data object. (when changing the locale - will not be updated)
...

D
Dmitry, 2020-08-27
@Tim308

In general, I added a key to each object, by which I look for the desired text in the dictionary

{
   name: '',
   value: '',
   pattern: /^[a-zA-Z ]{2,30}$/,
   key: 'nameTxt'
},

ru: {
     nameTxt: 'Имя',
     phoneTxt: 'Телефон',
     emailTxt: 'Электронный адрес',
     someField1Txt: 'Дополнительное поле 1',
     someField2Txt: 'Дополнительное поле 2',
   }

Everything is working. If anyone knows a more "correct" way, I'll be glad to see.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question