dkfbasel / vuex-i18n

Localization plugin for vue.js 2.0 using vuex as store
MIT License
665 stars 56 forks source link

List of available locales #66

Closed arthurvasconcelos closed 6 years ago

arthurvasconcelos commented 6 years ago

This is more a suggestion/request than a issue.

Would be nice to have a method that allow me to get all available locales.

$i18n.locales(); | $i18n.getLocales(); | $i18n.list();
> ['en', 'en-US', 'pt-BR']
tikiatua commented 6 years ago

Hi @arthurvasconcelos,

Thank you for your feedback. I added the method as $i18n.locales() in the version 1.10.5. An example is given in the test repository.

Please keep in mind that this is a method that will be invoked on every render cycle. To make use of vue's caching system I would recommend to create a getter method or computed property like this.

locales() {
  return Object.keys(this.$store.state.i18n.translations);
}

The translate method ($t) is also run in every render cycle, not sure if we can find a better solution in the future that will make use of the caching functionality.

arthurvasconcelos commented 6 years ago

Thanks @tikiatua! Great lib you have here!