Skip to content

Commit

Permalink
POC for translations
Browse files Browse the repository at this point in the history
  • Loading branch information
carlobeltrame committed Feb 12, 2024
1 parent 945a0ac commit f08786e
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
61 changes: 61 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"swissgrid": "^1.0.5",
"tiptap-extension-resize-image": "^1.0.2",
"vue": "^3.2.31",
"vue-i18n": "^9.9.1",
"vue-router": "^4.2.5",
"vuex": "^4.1.0"
},
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import store from "./store";
import { mixin } from "./mixins.js";
import "./assets/tailwind.css";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { messages } from './translations.js';
import { createI18n } from 'vue-i18n';

router.beforeEach((to, from, next) => {
let splitPath = to.path.split("/");
Expand All @@ -16,9 +18,16 @@ router.beforeEach((to, from, next) => {
}
});

const i18n = createI18n({
locale: window.navigator.language,
fallbackLocale: 'de',
messages,
});

const app = createApp(App)
.use(store)
.use(router)
.use(i18n)
.mixin(mixin)
.component("font-awesome-icon", FontAwesomeIcon);
app.directive("router-link", {
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/translations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const messages = {
de: {
dashboard: {
hello: 'Hallo {name}!'
}
},
};
2 changes: 1 addition & 1 deletion frontend/src/views/Dashboard/DashboardHome.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<Card v-if="user" class="text-4xl font-extrabold"
>Hello, {{ user.nickname }}!</Card
>{{ $t('dashboard.hello', { name: user.nickname }) }}</Card
>
</template>

Expand Down

0 comments on commit f08786e

Please sign in to comment.