Home > Enterprise >  How translate select options with vuejs
How translate select options with vuejs

Time:12-16

I want to translate the options found inside the contract_project_type array,

this is my select code:

<b-form-select
              :options="contract_project_types"
              v-model="form.contract_data.contract_project_type"
              id="contract_project_types"
              :state="validate(form.contract_data.contract_project_type)"

          ></b-form-select>

and my Data is :

data: {
contract_project_types: [
      'digital_work_city',
      'general_company'
      ]
}

i don't know how to translate these two options. I tried to put this.$t('digital_work_city') this.$t('general_company') but it doesn't work

CodePudding user response:

Try to get $t from the this context when outside of a template.

data() {
    return { contract_project_types: [
      this.$t('digital_work_city'),
      this.$t('general_company')
      ]
    }
}

You may also try

this.$i18n.t('digital_work_city')

CodePudding user response:

Try this. May be, it hasn't reacted to change a language.

computed: {
    contract_project_types() {
         return [
           this.$t('digital_work_city'),
           this.$t('general_company')
      ];
    }
}
  • Related