Use country code for national party in results

This commit is contained in:
Moritz Kröger 2019-05-05 12:29:34 +02:00
parent 3112a09985
commit 6dcec82e05
5 changed files with 16 additions and 11 deletions

View file

@ -83,7 +83,7 @@
</template>
<script>
import { getCurrentLocale, getTranslatedUrl } from '@/i18n/helper'
import { getUserLanguage, getTranslatedUrl } from '@/i18n/helper'
import {
MAX_POINTS,
BASE_POINTS,
@ -236,7 +236,7 @@
score: this.scores
.map(t => t.scores.find(s => s.party === party.id).score)
.reduce(addUp, 0),
nationalParty: party['national_parties'][getCurrentLocale()]
nationalParty: party['national_parties'][getUserLanguage().country]
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,8 @@
import { DEFAULT_LOCALE, SUPPORTED_LOCALES } from '@/config'
import i18n from './index'
console.log('i18n', i18n)
export const isLangSupported = lang =>
SUPPORTED_LOCALES.some(([locale]) => locale === lang)
@ -18,11 +20,14 @@ export function getUserLanguage () {
window.navigator.userLanguage ||
DEFAULT_LOCALE
)
return lang.split('-')[0]
return {
language: lang.split('-')[0],
country: lang.split('-')[1].toLowerCase()
}
}
export function getUserSupportedLanguage () {
const language = getUserLanguage()
const { language } = getUserLanguage()
return isLangSupported(language)
? language
: DEFAULT_LOCALE

View file

@ -11,7 +11,7 @@ export function getPageTitle (data = {}) {
export function beforeEnter (to, from, next) {
const lang = to.params.locale
if (!i18n.isLangSupported(lang)) {
return next(i18n.getUserLanguage())
return next(i18n.getUserLanguage().language)
}
i18n.setCurrentLocale(lang)