From 560ab278d2924d79f728e249e1215ce884c181ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Mon, 7 Aug 2023 17:32:54 +0200 Subject: [PATCH] Allow to set the prefered locale --- src/components/NavBarComponent.vue | 1 + src/locales/en.json | 7 ++++++ src/main.js | 11 +++++++-- src/router/index.js | 6 +++++ src/views/ConfigView.vue | 38 ++++++++++++++++++++++++++++++ 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/views/ConfigView.vue diff --git a/src/components/NavBarComponent.vue b/src/components/NavBarComponent.vue index cd70e71..deb4a73 100644 --- a/src/components/NavBarComponent.vue +++ b/src/components/NavBarComponent.vue @@ -24,6 +24,7 @@ const toggleBurger = () => { diff --git a/src/locales/en.json b/src/locales/en.json index a7a71e1..3ccd1fc 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1,4 +1,5 @@ { + "locale_name": "English", "invariants": { "controls": { "cancel": "Cancel", @@ -10,6 +11,7 @@ "navbar": { "addAccount": "New account", "manageAccounts": "Accounts", + "config": "Preferences", "about": "About" }, "about": { @@ -41,6 +43,11 @@ "unknown": "Unknown error." } }, + "config": { + "title": "Preferences", + "language": "Language", + "close": "@:invariants.controls.close" + }, "deleteAccount": { "title": "Delete account", "account": "You are about to delete the following account:", diff --git a/src/main.js b/src/main.js index a48a420..c7b114b 100644 --- a/src/main.js +++ b/src/main.js @@ -2,17 +2,24 @@ import './assets/main.sass'; import { createApp } from 'vue'; import { createI18n } from 'vue-i18n' +import { useStorage } from '@vueuse/core' import App from './App.vue'; import router from './router'; import msg_en from './locales/en.json'; +const default_locale = 'en' +const stored_locale = useStorage('sake-locale', ''); +if (!stored_locale.value) { + stored_locale.value = default_locale +} + const messages = { en: msg_en, }; const i18n = createI18n({ - locale: 'en', - fallbackLocale: 'en', + locale: stored_locale.value, + fallbackLocale: default_locale, messages, }); diff --git a/src/router/index.js b/src/router/index.js index 6068e97..fdfd4b1 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -4,6 +4,7 @@ import { useStorage } from '@vueuse/core' import MainView from '../views/MainView.vue'; import AboutView from '../views/AboutView.vue'; import AddAccountView from '../views/AddAccountView.vue'; +import ConfigView from '../views/ConfigView.vue'; import DeleteAccountView from '../views/DeleteAccountView.vue'; import ManageAccountsView from '../views/ManageAccountsView.vue'; @@ -32,6 +33,11 @@ const router = createRouter({ name: 'add-account', component: AddAccountView }, + { + path: '/config', + name: 'config', + component: ConfigView, + }, { path: '/delete-account/:id', name: 'delete-account', diff --git a/src/views/ConfigView.vue b/src/views/ConfigView.vue new file mode 100644 index 0000000..094634e --- /dev/null +++ b/src/views/ConfigView.vue @@ -0,0 +1,38 @@ + + +