diff --git a/src/App.vue b/src/App.vue index 1434225b21d8faa2392d4cec0b8755aa98b88cdf..d53e69a0192e0b9e8b71a48d9f7b112084697ab7 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,35 +1,5 @@ <template> <v-app id="app"> - <div v-if="no_locale"> - <v-dialog overlay-opacity="1" overlay-color="tertiary" persistent max-width="600px" v-model="no_locale"> - <v-card> - <v-toolbar elevation="0" color="primary" text> - <v-toolbar-title class="language-dialog-title">Ordbøkene</v-toolbar-title></v-toolbar> - <v-card-text class="text--primary"> - <v-list three-line> - <v-list-item link v-on:click="choose_locale('nob')"> - <v-list-item-content> - <v-list-item-title>Norsk (bokmål)</v-list-item-title> - <v-list-item-subtitle>Vis overskrifter, knapper og menyer på bokmål</v-list-item-subtitle> - </v-list-item-content> - </v-list-item> - <v-list-item link v-on:click="choose_locale('nno')"> - <v-list-item-content> - <v-list-item-title>Norsk (nynorsk)</v-list-item-title> - <v-list-item-subtitle>Vis overskrifter, knappar og menyar på nynorsk</v-list-item-subtitle> - </v-list-item-content> - </v-list-item> - <v-list-item link v-on:click="choose_locale('eng')"> - <v-list-item-content> - <v-list-item-title>English</v-list-item-title> - <v-list-item-subtitle>Choose English as display language for headings, buttons and menus</v-list-item-subtitle> - </v-list-item-content> - </v-list-item> - </v-list> - </v-card-text> - </v-card> - </v-dialog> - </div> <header> <TopBar/> @@ -63,24 +33,10 @@ import TopBar from './components/TopBar.vue' export default { computed: { - no_locale: function() { - return !this.$store.state.currentLocale - }, show_banner_text: function() { return !this.$route.name || (window.innerHeight > 800 && this.$route.name != 'about' ) } }, - mounted: function(){ - if (this.no_locale) { - this._i18n.locale = this.$store.state.locale - } - }, - methods: { - choose_locale: function(locale) { - this.$store.commit("setLocale", {value: locale, i18n: this._i18n}) - } - }, - components: { TopBar } diff --git a/src/components/Header.vue b/src/components/Header.vue index 8bcebef9aef50434b650b78f2ace2bc38b80b04a..f6c226fb07902a7b5d4ba8ba64886747c9a67827 100644 --- a/src/components/Header.vue +++ b/src/components/Header.vue @@ -57,6 +57,7 @@ <span class="subheader"> <span class="header_group_list" v-if="lemma_group.description">{{lemma_group.description}}</span> + {{lemma_group.genus}} <span v-if="$store.state.showInflectionNo" class="inflection_classes">{{lemma_group.inflection_classes}}</span> </span> diff --git a/src/components/SearchToolbar.vue b/src/components/SearchToolbar.vue index cc931d62538243304309f90b36560996df402e02..d8672292e00c92888a689bf8ce6306ad49551808 100644 --- a/src/components/SearchToolbar.vue +++ b/src/components/SearchToolbar.vue @@ -8,7 +8,7 @@ v-model="$parent.pos_selected" hide-details :menu-props="{ offsetY: true }" - :placeholder="$t('options.pos')" + :aria-label="$t('options.pos')" :items="pos_items" append-icon="expand_more" @input="updatePos"> @@ -59,7 +59,7 @@ hide-details :menu-props="{ offsetY: true }" dense - :placeholder="$t('options.pos')" + :aria-label="$t('options.pos')" :items="pos_items" append-icon="expand_more" @input="updatePos"> diff --git a/src/components/TopBar.vue b/src/components/TopBar.vue index 04a35daabfb3a2b49b89a7622b0640107141c709..09d44c28fa13ff17bfcc8ef34267b33d3baee37b 100644 --- a/src/components/TopBar.vue +++ b/src/components/TopBar.vue @@ -5,10 +5,16 @@ <v-spacer/> <v-divider vertical/> - <v-toolbar-items v-if="$route.name == 'about'"> - <v-btn text @click.native="back">{{$t('close')}}<v-icon right>close</v-icon></v-btn> - </v-toolbar-items> + + + <v-toolbar-items> + <v-btn v-if="!$store.state.localeChosen" id="locale_button" + aria-haspopup="dialog" + aria-label="Locale | Visningsspråk" + icon @click.native="chooseLocale = !chooseLocale"> + <v-icon>language</v-icon></v-btn> + <v-divider v-if="!$store.state.localeChosen" vertical /> <v-btn id="top_menu" v-if="$route.name != 'about'" @@ -18,6 +24,8 @@ aria-labelledby="menu_label" text @click.native="menuOpen = !menuOpen"> <span id="menu_label">{{$t('menu.title')}}</span><v-icon right>{{menuOpen? 'close' : 'menu'}}</v-icon></v-btn> + + <v-btn v-if="$route.name == 'about'" text @click.native="back">{{$t('close')}}<v-icon right>close</v-icon></v-btn> </v-toolbar-items> <v-divider vertical/> </v-app-bar> @@ -25,6 +33,35 @@ :close-on-content-click="false" transition="dialog-top-transition"> <Menu @close="menuOpen=false"/> </v-dialog> + + <v-dialog max-width="600px" v-model="chooseLocale"> + <v-card> + <v-toolbar elevation="0" color="primary" text> + <v-toolbar-title class="language-dialog-title">Locale | Visningsspråk</v-toolbar-title></v-toolbar> + <v-card-text class="text--primary"> + <v-list three-line> + <v-list-item link v-on:click="choose_locale('nob')"> + <v-list-item-content> + <v-list-item-title>Norsk (bokmål)</v-list-item-title> + <v-list-item-subtitle>Vis overskrifter, knapper og menyer på bokmål</v-list-item-subtitle> + </v-list-item-content> + </v-list-item> + <v-list-item link v-on:click="choose_locale('nno')"> + <v-list-item-content> + <v-list-item-title>Norsk (nynorsk)</v-list-item-title> + <v-list-item-subtitle>Vis overskrifter, knappar og menyar på nynorsk</v-list-item-subtitle> + </v-list-item-content> + </v-list-item> + <v-list-item link v-on:click="choose_locale('eng')"> + <v-list-item-content> + <v-list-item-title>English</v-list-item-title> + <v-list-item-subtitle>Choose English as display language for headings, buttons and menus</v-list-item-subtitle> + </v-list-item-content> + </v-list-item> + </v-list> + </v-card-text> + </v-card> + </v-dialog> </div> </template> @@ -37,6 +74,7 @@ export default { return { version_label: process.env.VUE_APP_VERSION_LABEL, release: process.env.VUE_APP_RELEASE, + chooseLocale: false } }, computed: { @@ -55,6 +93,10 @@ export default { }, back: function() { this.$router.go(-1) + }, + choose_locale: function(locale) { + this.$store.commit("setLocale", {value: locale, i18n: this._i18n}) + this.chooseLocale = false } }, diff --git a/src/main.js b/src/main.js index dfdc4b5a9282a5b6a0bd497de5a0d834a3b968ab..9916159623bf521be00d01794a12d2543d063197 100644 --- a/src/main.js +++ b/src/main.js @@ -96,7 +96,7 @@ const store = new Vuex.Store({ state: { showSearchToolbar: null, showInflectionNo: null, - currentLocale: 'nno', + currentLocale: null, collapseArticles: 'auto', defaultDict: null, perPage: 20, @@ -104,7 +104,8 @@ const store = new Vuex.Store({ noMouse: null, searchRoute: null, fulltextHighlight: false, - unavailable: null + unavailable: null, + localeChosen: false }, mutations: { initStore(state) { @@ -115,21 +116,34 @@ const store = new Vuex.Store({ state.defaultDict = localStorage.getItem('defaultDict') || 'bm,nn' state.perPage = localStorage.getItem('perPage') || 20 state.collapseArticles = localStorage.getItem('collapseArticles') || 'auto' + state.localeChosen = localStorage.getItem('currentLocale') ? true : false } catch(e) { console.log("localStorage unavailable") state.unavailable = true } - state.noMouse = navigator.userAgentData? navigator.userAgentData.mobile : !window.matchMedia('(pointer: fine)').matches - if (state.currentLocale) { - i18n.locale = state.currentLocale + if (!state.currentLocale) { + let locales = navigator.languages.map(l => l.split("-")[0]) + if (locales.includes("nn")) state.currentLocale = "nno" + else if (locales.includes("nb")) state.currentLocale = "nob" + else { + state.currentLocale = Math.random() < 0.5 ? "nob" : "nno"; + if (!state.unavailable) { + localStorage.setItem('currentLocale', state.currentLocale) + } + } } + i18n.locale = state.currentLocale + state.noMouse = navigator.userAgentData? navigator.userAgentData.mobile : !window.matchMedia('(pointer: fine)').matches + }, setLocale(state, payload) { Vue.$plausible.trackEvent("set locale", {props: {from: state.currentLocale, to: payload.locale}}) state.currentLocale = payload.value i18n.locale = payload.value + state.localeChosen = true if (!state.unavailable) localStorage.setItem("currentLocale", payload.value); + }, setCollapse(state, value) { Vue.$plausible.trackEvent("set collapse", {props: {from: state.collapseArticles, to: value}})