Created
January 10, 2018 10:20
-
-
Save exophunk/c3ced7c9c267f9b030eeb4c3f29a6c13 to your computer and use it in GitHub Desktop.
Revisions
-
exophunk created this gist
Jan 10, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ import Vue from 'vue'; import VueI18n from 'vue-i18n'; //import messagesDe from 'lang/de'; // import messagesFr from 'lang/fr'; // import messagesIt from 'lang/it'; Vue.use(VueI18n); const loadedLanguages = []; const i18n = new VueI18n({ locale: null, fallbackLocale: 'de', // messages: { // //de: messagesDe, // // fr: messagesFr, // // it: messagesIt, // }, }); export default i18n; export function setI18nLanguage(lang) { i18n.locale = lang; document.querySelector('html').setAttribute('lang', lang); return lang; } export function loadLanguageAsync(lang) { if (i18n.locale !== lang) { if (!loadedLanguages.includes(lang)) { return import(/* webpackChunkName: "lang-[request]" */ `lang/${lang}`).then(msgs => { i18n.setLocaleMessage(lang, msgs.default); loadedLanguages.push(lang); return setI18nLanguage(lang); }) } return Promise.resolve(setI18nLanguage(lang)); } return Promise.resolve(lang); } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ import Vue from 'vue'; import VueRouter from 'vue-router'; import {loadLanguageAsync} from 'i18n'; import PageLanding from 'components/pages/PageLanding.vue'; Vue.use(VueRouter); const routes = [ { path: '/', redirect: { name: 'index', params: { langSlug: 'mut' } }}, { name: 'index', path: '/:langSlug', component: PageLanding, }, ]; const router = new VueRouter({ routes: routes, mode: 'history', }); router.beforeEach((to, from, next) => { const lang = mapSlugToLang(to.params.langSlug); loadLanguageAsync(lang).then(() => next()); }) function mapSlugToLang(slug) { switch(slug) { case 'mut': return 'de'; case 'courage': return 'fr'; case 'coraggio': return 'it'; } } export default router; 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ webpack: { ... output: { chunkFilename: 'build/js/[name].bundle.js', } }, 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ ... mix .setPublicPath('public') ....