Vue-i18n: Data interpolation within locale strings

Created on 15 May 2015  路  2Comments  路  Source: kazupon/vue-i18n

Hi,

Does this plugin support dynamic data interpolation for locales as in projects such as Polyglot?

Something like:

Locale object:

var locales = {
  en: {
    message: {
      hello: 'total products %{num}'
    }
  }
};

Template:

<div id="message">
{{$t('message.hello', 10)}}
</div>

Rendered HTML:

<div id="message">
total products 10
</div>

Thanks in advance!

Most helpful comment

There are two ways.

named formatting

locale:

var locales = {
  en: {
    message: {
      hello: 'total products {num}'
    }
  }
}

tempale:

<div id="message">
{{$t('message.hello', { num: 10 })}}
</div>

list formatting

locale:

var locales = {
  en: {
    message: {
      hello: 'total products {0}'
    }
  }
}

tempale:

<div id="message">
{{$t('message.hello', [10])}}
</div>

Sorry, poor document ;)

All 2 comments

There are two ways.

named formatting

locale:

var locales = {
  en: {
    message: {
      hello: 'total products {num}'
    }
  }
}

tempale:

<div id="message">
{{$t('message.hello', { num: 10 })}}
</div>

list formatting

locale:

var locales = {
  en: {
    message: {
      hello: 'total products {0}'
    }
  }
}

tempale:

<div id="message">
{{$t('message.hello', [10])}}
</div>

Sorry, poor document ;)

No problem. Sounds great!

Thank you very much!

Was this page helpful?
0 / 5 - 0 ratings