Last active
March 1, 2018 06:18
-
-
Save hmsk/b6394c2170a0d5878292c3e91208c798 to your computer and use it in GitHub Desktop.
Determine locale with env variable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- pages/about.vue --> | |
<template> | |
<div class="Content"> | |
<div class="container"> | |
<h1 class="Content__Title">{{ $t('about.title') }}</h1> | |
<p>{{ $t('about.introduction') }}</p> | |
</div> | |
</div> | |
</template> | |
<script> | |
export default { | |
head() { | |
return { title: this.$t('about.title') } | |
} | |
} | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// nuxt.config.js | |
module.exports = { | |
env: { | |
baseUrl: process.env.BASE_URL || 'http://localhost:3000', | |
buildLocale: process.env.BUILD_LOCALE || 'en' | |
}, | |
build: { | |
vendor: ['vue-i18n'] | |
}, | |
plugins: ['~/plugins/i18n.js'], | |
generate: { | |
routes: ['/', '/about'] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// plugins/i18n.js | |
import Vue from 'vue' | |
import VueI18n from 'vue-i18n' | |
import en from '~/locales/en.yaml' | |
import ja from '~/locales/ja.yaml' | |
Vue.use(VueI18n) | |
export default ({ app, store }) => { | |
app.i18n = new VueI18n({ | |
locale: store.state.locale, | |
fallbackLocale: 'en', | |
messages: { | |
en, ja | |
} | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const state = (): State => ({ | |
locale: process.env.buildLocale | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment