Reputation: 3950
I am trying to use i18n-iso-countries to get a list of countries
What I usually do
/plugins/i18nCountries.js
import countries from 'i18n-iso-countries'
console.log(countries.getNames('en'))
function getNames (locale) {
return countries.getNames(locale)
}
export default ({ app }, inject) => {
inject('getNames', (locale) => { return getNames(locale) })
}
The console.log(countries.getNames('en'))
statement prints to the console a list of country names
However, when I am inside a vue page/component
//somecomponent.vue
<template>
...
</template>
<script>
export default {
created () {
console.log(this.$getNames('en'))
},
}
</script>
it prints out {}
What can I do to make this library accessible on the client?
Upvotes: 2
Views: 1594
Reputation: 5784
You need to register the languages you want to use. If you put the following below the import line, it should work:
countries.registerLocale(require("i18n-iso-countries/langs/en.json"));
Upvotes: 1