Skip to content

Instantly share code, notes, and snippets.

@cornelia-schulz
Last active May 13, 2019 04:43
Show Gist options
  • Save cornelia-schulz/8027717cd0a5e26df6d3bc0c8ddd57f6 to your computer and use it in GitHub Desktop.
Save cornelia-schulz/8027717cd0a5e26df6d3bc0c8ddd57f6 to your computer and use it in GitHub Desktop.
Setting up i18next for Vue
{
"message": "hallo",
"tryitfree": "Probiere es kostenlos",
"readytobuild": "Bist du bereit, deine Community aufzubauen?"
}
{
"message": "hello",
"tryitfree": "Try it free",
"readytobuild": "Ready to build your community?"
}
<button class="try">
{{ $t("tryitfree") }}
</button>
import Vue from 'vue'
import i18next from 'i18next'
import VueI18Next from '@panter/vue-i18next'
import App from './App.vue'
import en from './locales/en.json'
import de from './locales/de.json'
const locales = {
en: en,
de: de
}
Vue.use(VueI18Next)
i18next.init({
lng: 'en',
fallbackLng: 'en',
resources: {
en: { translation: locales.en },
de: { translation: locales.de }
}
})
const i18n = new VueI18Next(i18next)
if (document.getElementById('app')) {
/* eslint-disable-next-line no-new */
new Vue({
el: '#app',
i18n: i18n,
render: h => h(App)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment