Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vuefity translate v-text-field label

I need to translate the label (and placeholder) of vuetify text-field (v-text-field). The code looks like this

<template>(...)
<v-text-field
  label="$t('common.nameLabel')"
  v-model="registerName"
  required
     ></v-text-field>
<vuetify-google-autocomplete
  ref="registerAddress"
  id="map"
  dark
  label="registerAddressLabel"
  google-api-key="Xyz"
  v-on:placechanged="getAddressData"
  >
  </vuetify-google-autocomplete>
(...)</template>
<script>
   import VuetifyGoogleAutocomplete from 'vuetify-google-autocomplete'
   export default {
     data () {
       return {
         registerAddressLabel () {
           return this.$t('common.addressLabel')
         },
         registerAddress: '',
         registerEmail: '',
         registerPassword: '',
         registerName: ''
       }
    },
    methods: {
      getAddressData (addressData, placeholderResultData) {

      }
    },
    components: {
      VuetifyGoogleAutocomplete
    }
  }
</script>

in the first case (also tried with autocomplete) the label is exactly ($t('common.nameLabel') as a string). so it seems it doesn't handle as a function. Is it possible to translate all labels this way?

like image 409
Dario Rusignuolo Avatar asked Feb 04 '18 11:02

Dario Rusignuolo


2 Answers

You need to use v-bind (or the colon shorthand) to pass a JavaScript value, otherwise it will just pass the string literal:

<v-text-field
  v-bind:label="$t('common.nameLabel')"
  v-model="registerName"
  required></v-text-field>

Here's a little JSFiddle: https://jsfiddle.net/9rjpaz4L/

like image 168
craig_h Avatar answered Oct 19 '22 18:10

craig_h


You can also do it without the word v-bind, just with the colon:

<v-text-field
  :label="$t('common.nameLabel')"
  v-model="registerName"
  required>
</v-text-field>
like image 38
Scoreby Avatar answered Oct 19 '22 20:10

Scoreby