diff --git a/src/App.vue b/src/App.vue index d29169b..7e58ff8 100644 --- a/src/App.vue +++ b/src/App.vue @@ -11,15 +11,18 @@ import MainContainer from './components/App/MainContainer.vue'; import { onMounted } from 'vue'; import { useApiStore } from './stores/api.store'; import { useGlobalStore } from './stores/global.store'; +import { useI18n } from 'vue-i18n'; const originalDocumentTitle = document.title; const apiStore = useApiStore(); const globalStore = useGlobalStore(); +const i18n = useI18n(); onMounted(() => { apiStore.setupAPIData(); + setupLocale(); setupDarkMode(); loadStorageTimetables(); setupAfterPrintClose(); @@ -45,4 +48,14 @@ function setupAfterPrintClose() { document.title = originalDocumentTitle; }); } + +function setupLocale() { + if (window.localStorage.getItem('locale') == null) { + const browserLang = window.navigator.language; + if (browserLang == 'pl-PL') i18n.locale.value = browserLang == 'pl-PL' ? 'pl' : 'en'; + window.localStorage.setItem('locale', i18n.locale.value); + } else { + i18n.locale.value = window.localStorage.getItem('locale')!; + } +} diff --git a/src/components/App/Navbar.vue b/src/components/App/Navbar.vue index 36ac27f..275e37e 100644 --- a/src/components/App/Navbar.vue +++ b/src/components/App/Navbar.vue @@ -1,18 +1,31 @@ - + Rozkładownik TD2 {{ version }} - API mocking + + + + {{ i18n.locale.value == 'pl' ? 'POL' : 'ENG' }} + + + diff --git a/src/components/App/SettingsCard.vue b/src/components/App/SettingsCard.vue new file mode 100644 index 0000000..430b7bb --- /dev/null +++ b/src/components/App/SettingsCard.vue @@ -0,0 +1,42 @@ + + + + + + + + + + POLSKI + + + ENGLISH + + + + + + + + + diff --git a/src/components/Timetable/TimetableSelect.vue b/src/components/Timetable/TimetableSelect.vue index ea35cc3..2b142ac 100644 --- a/src/components/Timetable/TimetableSelect.vue +++ b/src/components/Timetable/TimetableSelect.vue @@ -32,7 +32,7 @@ type="text" v-if="globalStore.viewMode == 'storage'" class="bg-zinc-800 p-1 rounded-md print:hidden w-full" - :placeholder="$t('train-select-placeholder')" + :placeholder="$t('train-search-placeholder')" /> diff --git a/src/main.ts b/src/main.ts index ced584e..dccc357 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import { createApp } from 'vue'; +import { createApp, type Directive } from 'vue'; import App from './App.vue'; import { createPinia } from 'pinia'; @@ -7,4 +7,16 @@ import i18n from './i18n'; const pinia = createPinia(); -createApp(App).use(i18n).use(pinia).mount('#app'); +const clickOutsideDirective: Directive = { + mounted(el, binding) { + el.clickOutsideEvent = (event: Event) => { + if (!(el == event.target || el.contains(event.target))) { + binding.value(); + } + }; + + document.addEventListener('click', el.clickOutsideEvent); + }, +}; + +createApp(App).use(i18n).use(pinia).directive('click-outside', clickOutsideDirective).mount('#app'); diff --git a/src/stores/global.store.ts b/src/stores/global.store.ts index 9e63044..59f6a55 100644 --- a/src/stores/global.store.ts +++ b/src/stores/global.store.ts @@ -16,6 +16,8 @@ export const useGlobalStore = defineStore('global', { generatedDate: null as Date | null, generatedMs: 0, + + showSettings: false, }), getters: { activeTimetableTrains() {