diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 651a182..6c1bdde 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -13,6 +13,7 @@ "@fullcalendar/interaction": "^6.1.9", "@fullcalendar/timegrid": "^6.1.9", "@fullcalendar/vue3": "^6.1.9", + "@vueuse/core": "^10.6.1", "pinia": "^2.1.6", "primeflex": "^3.3.1", "primeicons": "^6.0.1", @@ -770,6 +771,11 @@ "integrity": "sha512-7aqorHYgdNO4DM36stTiGO3DvKoex9TQRwsJU6vMaFGyqpBA1MNZkz+PG3gaNUPpTAOYhT1WR7M1JyA3fbS9Cw==", "dev": true }, + "node_modules/@types/web-bluetooth": { + "version": "0.0.20", + "resolved": "https://registry.npmjs.org/@types/web-bluetooth/-/web-bluetooth-0.0.20.tgz", + "integrity": "sha512-g9gZnnXVq7gM7v3tJCWV/qw7w+KeOlSHAhgF9RytFyifW6AF61hdT2ucrYhPq9hLs5JIryeupHV3qGk95dH9ow==" + }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "6.7.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.7.0.tgz", @@ -1164,6 +1170,89 @@ "@vue/language-core": "1.8.8" } }, + "node_modules/@vueuse/core": { + "version": "10.6.1", + "resolved": "https://registry.npmjs.org/@vueuse/core/-/core-10.6.1.tgz", + "integrity": "sha512-Pc26IJbqgC9VG1u6VY/xrXXfxD33hnvxBnKrLlA2LJlyHII+BSrRoTPJgGYq7qZOu61itITFUnm6QbacwZ4H8Q==", + "dependencies": { + "@types/web-bluetooth": "^0.0.20", + "@vueuse/metadata": "10.6.1", + "@vueuse/shared": "10.6.1", + "vue-demi": ">=0.14.6" + }, + "funding": { + "url": "https://github.com/sponsors/antfu" + } + }, + "node_modules/@vueuse/core/node_modules/vue-demi": { + "version": "0.14.6", + "resolved": "https://registry.npmjs.org/vue-demi/-/vue-demi-0.14.6.tgz", + "integrity": "sha512-8QA7wrYSHKaYgUxDA5ZC24w+eHm3sYCbp0EzcDwKqN3p6HqtTCGR/GVsPyZW92unff4UlcSh++lmqDWN3ZIq4w==", + "hasInstallScript": true, + "bin": { + "vue-demi-fix": "bin/vue-demi-fix.js", + "vue-demi-switch": "bin/vue-demi-switch.js" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/antfu" + }, + "peerDependencies": { + "@vue/composition-api": "^1.0.0-rc.1", + "vue": "^3.0.0-0 || ^2.6.0" + }, + "peerDependenciesMeta": { + "@vue/composition-api": { + "optional": true + } + } + }, + "node_modules/@vueuse/metadata": { + "version": "10.6.1", + "resolved": "https://registry.npmjs.org/@vueuse/metadata/-/metadata-10.6.1.tgz", + "integrity": "sha512-qhdwPI65Bgcj23e5lpGfQsxcy0bMjCAsUGoXkJ7DsoeDUdasbZ2DBa4dinFCOER3lF4gwUv+UD2AlA11zdzMFw==", + "funding": { + "url": "https://github.com/sponsors/antfu" + } + }, + "node_modules/@vueuse/shared": { + "version": "10.6.1", + "resolved": "https://registry.npmjs.org/@vueuse/shared/-/shared-10.6.1.tgz", + "integrity": "sha512-TECVDTIedFlL0NUfHWncf3zF9Gc4VfdxfQc8JFwoVZQmxpONhLxFrlm0eHQeidHj4rdTPL3KXJa0TZCk1wnc5Q==", + "dependencies": { + "vue-demi": ">=0.14.6" + }, + "funding": { + "url": "https://github.com/sponsors/antfu" + } + }, + "node_modules/@vueuse/shared/node_modules/vue-demi": { + "version": "0.14.6", + "resolved": "https://registry.npmjs.org/vue-demi/-/vue-demi-0.14.6.tgz", + "integrity": "sha512-8QA7wrYSHKaYgUxDA5ZC24w+eHm3sYCbp0EzcDwKqN3p6HqtTCGR/GVsPyZW92unff4UlcSh++lmqDWN3ZIq4w==", + "hasInstallScript": true, + "bin": { + "vue-demi-fix": "bin/vue-demi-fix.js", + "vue-demi-switch": "bin/vue-demi-switch.js" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/antfu" + }, + "peerDependencies": { + "@vue/composition-api": "^1.0.0-rc.1", + "vue": "^3.0.0-0 || ^2.6.0" + }, + "peerDependenciesMeta": { + "@vue/composition-api": { + "optional": true + } + } + }, "node_modules/@webassemblyjs/ast": { "version": "1.11.6", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.6.tgz", diff --git a/frontend/package.json b/frontend/package.json index fcf1f21..e6cd731 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -16,6 +16,7 @@ "@fullcalendar/interaction": "^6.1.9", "@fullcalendar/timegrid": "^6.1.9", "@fullcalendar/vue3": "^6.1.9", + "@vueuse/core": "^10.6.1", "pinia": "^2.1.6", "primeflex": "^3.3.1", "primeicons": "^6.0.1", diff --git a/frontend/src/components/CourseSelection.vue b/frontend/src/components/CourseSelection.vue index d2c1b15..178b8be 100644 --- a/frontend/src/components/CourseSelection.vue +++ b/frontend/src/components/CourseSelection.vue @@ -1,11 +1,14 @@ \ No newline at end of file + diff --git a/frontend/src/components/MenuBar.vue b/frontend/src/components/MenuBar.vue index be33bd1..ae2129e 100644 --- a/frontend/src/components/MenuBar.vue +++ b/frontend/src/components/MenuBar.vue @@ -1,58 +1,50 @@ diff --git a/frontend/src/i18n/index.ts b/frontend/src/i18n/index.ts index a048b1a..747e9f4 100644 --- a/frontend/src/i18n/index.ts +++ b/frontend/src/i18n/index.ts @@ -1,23 +1,25 @@ import { createI18n } from "vue-i18n"; -import { nextTick } from "vue"; -import defaultMessages from './translations/en.json' +import en from './translations/en.json' +import de from './translations/de.json' +import localeStore from "../store/localeStore.ts"; export const supportedLocales= { 'en': { name: 'English'}, 'de': { name: 'Deutsch'}, } -export let defaultLocale = 'en' // Private instance of VueI18n object let _i18n: any // Initializer -function setup(options = { locale: defaultLocale }) { +function setup() { _i18n = createI18n({ legacy: false, - locale: options.locale, - fallbackLocale: defaultLocale, - messages: { [defaultLocale]: defaultMessages }, + locale: localeStore().locale, + fallbackLocale: "en", + messages: { + en, + de + }, }) - setLocale(options.locale) return _i18n } @@ -27,16 +29,6 @@ function setLocale(newLocale : any) { setDocumentAttributesFor(newLocale) } -async function loadMessagesFor(locale: any) { - const messages = await import( - `./translations/${locale}.json` - ) - - _i18n.global.setLocaleMessage(locale, messages.default) - - return nextTick() -} - function setDocumentAttributesFor(locale: any) { const htmlElement = document.querySelector('html') @@ -51,5 +43,4 @@ export default { }, setup, setLocale, - loadMessagesFor, } \ No newline at end of file diff --git a/frontend/src/i18n/translations/de.json b/frontend/src/i18n/translations/de.json index 93783bc..f4d6c68 100644 --- a/frontend/src/i18n/translations/de.json +++ b/frontend/src/i18n/translations/de.json @@ -4,5 +4,12 @@ "roomFinder": "Raumfinder", "faq": "FAQ", "imprint": "Impressum", - "privacy": "Datenschutz" + "privacy": "Datenschutz", + "english": "Englisch", + "german": "Deutsch", + "courseSelection": { + "winterSemester": "Wintersemester", + "summerSemester": "Sommersemester", + "selectCourse": "Bitte wähle eine Gruppe und das Semester aus" + } } \ No newline at end of file diff --git a/frontend/src/i18n/translations/en.json b/frontend/src/i18n/translations/en.json index d9a1164..4746e46 100644 --- a/frontend/src/i18n/translations/en.json +++ b/frontend/src/i18n/translations/en.json @@ -4,5 +4,12 @@ "roomFinder": "Room Finder", "faq": "FAQ", "imprint": "Imprint", - "privacy": "Privacy" + "privacy": "Privacy", + "english": "English", + "german": "German", + "courseSelection": { + "winterSemester": "winter semester", + "summerSemester": "summer semester", + "selectCourse": "Please select a course and semester" + } } \ No newline at end of file diff --git a/frontend/src/main.ts b/frontend/src/main.ts index 328181a..3c4bc9b 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -35,13 +35,13 @@ import i18n from "./i18n"; const app = createApp(App); const pinia = createPinia(); -i18n.setup(); -app.use(i18n.vueI18n); app.use(PrimeVue); app.use(router); app.use(ToastService); app.use(pinia); app.use(DialogService); +i18n.setup(); +app.use(i18n.vueI18n); app.component("Button", Button); app.component("Menu", Menu); app.component("Menubar", Menubar); diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 8e6ce2d..7bf3038 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -10,75 +10,66 @@ import EditCalendarView from "../view/editCalendarView.vue"; import EditAdditionalModules from "../components/editCalendar/EditAdditionalModules.vue"; import EditModules from "../components/editCalendar/EditModules.vue"; import CourseSelection from "../components/CourseSelection.vue"; -import i18n, { defaultLocale } from "../i18n"; +import i18n from "../i18n"; const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes: [ - { - path: "/", - redirect: `/${defaultLocale}`, - }, - { - path: "/:locale", - children: [ { - path: "", + path: "/", name: "course-selection", component: CourseSelection, }, { - path: "rooms", + path: "/rooms", name: "room-finder", component: RoomFinder, }, { - path: "faq", + path: "/faq", name: "faq", component: Faq, }, { - path: "additional-modules", + path: "/additional-modules", name: "additional-modules", component: AdditionalModules, }, { - path: "edit-additional-modules", + path: "/edit-additional-modules", name: "edit-additional-modules", component: EditAdditionalModules, }, { - path: "edit-calendar", + path: "/edit-calendar", name: "edit-calendar", component: EditModules, }, { - path: "calendar-link", + path: "/calendar-link", name: "calendar-link", component: CalendarLink, }, { - path: "edit", + path: "/edit", name: "edit", component: EditCalendarView, }, { - path: "privacy-policy", + path: "/privacy-policy", name: "privacy-policy", component: PrivacyPolicy, }, { - path: "imprint", + path: "/imprint", name: "imprint", component: Imprint, }, { - path: "rename-modules", + path: "/rename-modules", name: "rename-modules", component: RenameModules, - }, - ], - }, + } ], }); @@ -89,8 +80,6 @@ router.beforeEach(async (to, from) => { if (newLocale === prevLocale) { return } - - await i18n.loadMessagesFor(newLocale) i18n.setLocale(newLocale) }) diff --git a/frontend/src/store/localeStore.ts b/frontend/src/store/localeStore.ts new file mode 100644 index 0000000..c67cb4f --- /dev/null +++ b/frontend/src/store/localeStore.ts @@ -0,0 +1,17 @@ +import { defineStore } from "pinia"; +import { useLocalStorage } from "@vueuse/core" + +const localeStore = defineStore("localeStore", { + state: () => { + return { + locale: useLocalStorage('locale', "en"), //useLocalStorage takes in a key of 'count' and default value of 0 + }; + }, + actions: { + setLocale(locale: string) { + this.locale = locale; + }, + }, +}); + +export default localeStore;