diff --git a/vue/package.json b/vue/package.json index 7aa8ab3..9119ff4 100644 --- a/vue/package.json +++ b/vue/package.json @@ -15,6 +15,7 @@ "jquery": "^3.4.1", "typescript": "^3.7.3", "vue": "^2.6.10", + "vue-i18n": "^8.15.3", "vue-masonry": "^0.11.8", "vue-resource": "^1.5.1", "vue-router": "^3.1.3", diff --git a/vue/src/assets/404.jpg b/vue/src/assets/404.jpg new file mode 100644 index 0000000..4b40845 Binary files /dev/null and b/vue/src/assets/404.jpg differ diff --git a/vue/src/assets/background.jpg b/vue/src/assets/background.jpg deleted file mode 100644 index 945dc4a..0000000 Binary files a/vue/src/assets/background.jpg and /dev/null differ diff --git a/vue/src/lang/index.js b/vue/src/lang/index.js new file mode 100644 index 0000000..f73d5a9 --- /dev/null +++ b/vue/src/lang/index.js @@ -0,0 +1,12 @@ +import de from './translations/de'; +import en from './translations/en'; + +export default { + 'de':de,'de-DE':de,'de-AT':de,'de-CH':de, + 'en':en,'en-US':en,'en-GB':en +}; + +export const i18n_LANGUAGES = [ + 'de','de-DE','de-AT','de-CH', + 'en','en-US','en-GB' +] \ No newline at end of file diff --git a/vue/src/lang/translations/de.json b/vue/src/lang/translations/de.json new file mode 100644 index 0000000..90b5c99 --- /dev/null +++ b/vue/src/lang/translations/de.json @@ -0,0 +1,13 @@ +{ + "about":{ + "message":"Das ist eine About Seite" + }, + "profile":{ + "email":"E-Mail", + "username":"Nutzername", + "password":"Passwort" + }, + + + "HelloWorld": "Hallo Welt!" +} \ No newline at end of file diff --git a/vue/src/lang/translations/en.json b/vue/src/lang/translations/en.json new file mode 100644 index 0000000..a0d8bbf --- /dev/null +++ b/vue/src/lang/translations/en.json @@ -0,0 +1,13 @@ +{ + "about":{ + "message":"This is an About page" + }, + "profile":{ + "email":"E-Mail", + "username":"Username", + "password":"Password" + }, + + + "HelloWorld": "Hello World!" +} \ No newline at end of file diff --git a/vue/src/main.js b/vue/src/main.js index ee0389a..1c2d68b 100644 --- a/vue/src/main.js +++ b/vue/src/main.js @@ -3,6 +3,17 @@ import App from './App.vue'; import router from './router'; import store from './store'; +//import i18n +import VueI18n from 'vue-i18n'; +import messages from './lang'; + +Vue.use(VueI18n); +export const i18n = new VueI18n({ + locale: 'en', + fallbacklocale: 'en', + messages +}); + // import Font Awesome icons import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'; import { library } from '@fortawesome/fontawesome-svg-core'; @@ -23,5 +34,6 @@ Vue.config.productionTip = false; new Vue({ router, store, - render: h => h(App) + i18n, + render: h => h(App), }).$mount('#app'); diff --git a/vue/src/router/index.js b/vue/src/router/index.js index 976d94f..574f492 100644 --- a/vue/src/router/index.js +++ b/vue/src/router/index.js @@ -1,21 +1,49 @@ import Vue from 'vue'; -import VueRouter from 'vue-router'; -import Home from '../views/Home.vue'; -Vue.use(VueRouter); +import Router from 'vue-router'; -const routes = [{ - path: '/', - name: 'noticeBoard', - // route level code-splitting - // this generates a separate chunk (about.[hash].js) for this route - // which is lazy-loaded when the route is visited. - component: () => - import ('../views/NoticeBoard.vue') -} -]; +import RouterView from '@/views/RouterView.vue'; +import { i18n } from '@/main.js'; +import { i18n_LANGUAGES } from '@/lang/index.js'; -const router = new VueRouter({ - routes -}); +Vue.use(Router); + +export default new Router({ + mode: 'history', + base: process.env.BASE_URL, + routes: [{ + path: '/', + component: RouterView, // Empty router object. Do not delete. + beforeEnter(to,from,next){ + // Retrieve browser locale + var lang = window.navigator.userLanguage || window.navigator.language; + // Check if browser locale is supported. Change to 'en-GB' if not. + if(!i18n_LANGUAGES.includes(lang)) { i18n.locale = 'en-GB'; } + else { + if (i18n.locale !== lang) { i18n.locale = lang; } + } + //alert('lang: ' + lang + ' i18n: ' + i18n.locale); + return next(); + }, -export default router; + children: [ + { + path: 'about', + name: 'About', + component: () => import ('../views/About.vue') + }, + { + path: 'home', + name: 'Home', + component: () => import ('../views/NoticeBoard.vue') + } + ] + + }, + // Redirect to 404 page if trying to visit invalid path + { + path: '*', + //redirect: '/home' + component: () => import ('../views/404.vue') + } + ] +}); diff --git a/vue/src/views/404.vue b/vue/src/views/404.vue new file mode 100644 index 0000000..67f2c6e --- /dev/null +++ b/vue/src/views/404.vue @@ -0,0 +1,17 @@ + + + + This is not the Page you are looking for... + +; + + diff --git a/vue/src/views/About.vue b/vue/src/views/About.vue index 7aa6e0f..01fe91f 100644 --- a/vue/src/views/About.vue +++ b/vue/src/views/About.vue @@ -1,5 +1,5 @@ - This is an about page + {{ $t('about.message') }} ; diff --git a/vue/src/views/RouterView.vue b/vue/src/views/RouterView.vue new file mode 100644 index 0000000..dc1f1b6 --- /dev/null +++ b/vue/src/views/RouterView.vue @@ -0,0 +1,4 @@ + + + +