Merge remote-tracking branch 'origin/master' into v3

This commit is contained in:
Miroslav Šedivý 2025-03-30 22:52:14 +02:00
commit 9e9cd6f486
2 changed files with 29 additions and 3 deletions

View file

@ -60,8 +60,9 @@
</style>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { Component, Vue, Watch } from 'vue-property-decorator'
import { messages } from '~/locale'
import { set } from '~/utils/localstorage'
@Component({ name: 'neko-menu' })
export default class extends Vue {
@ -77,6 +78,11 @@
this.$accessor.client.toggleAbout()
}
@Watch('$i18n.locale')
onLanguageChange(newLang: string) {
set('lang', newLang)
}
mounted() {
const default_lang = new URL(location.href).searchParams.get('lang')
if (default_lang && this.langs.includes(default_lang)) {

View file

@ -1,11 +1,31 @@
import Vue from 'vue'
import VueI18n from 'vue-i18n'
import { messages } from '~/locale'
import { get } from '~/utils/localstorage'
Vue.use(VueI18n)
const fallbackLocale = 'en'
function detectBrowserLanguage(): string {
const browserLang = navigator.language.toLowerCase()
const supportedLangs = Object.keys(messages)
if (supportedLangs.includes(browserLang)) {
return browserLang
}
const baseLang = browserLang.split('-')[0]
const matchingLang = supportedLangs.find((lang) => lang.startsWith(baseLang))
if (matchingLang) {
return matchingLang
}
return fallbackLocale
}
export const i18n = new VueI18n({
locale: 'en',
fallbackLocale: 'en',
locale: get<string>('lang', detectBrowserLanguage()),
fallbackLocale,
messages,
})