mirror of
https://codeberg.org/SafeTwitch/safetwitch.git
synced 2024-12-22 13:22:58 -05:00
Add oersistent language change, and send language header
This commit is contained in:
parent
607b36b95e
commit
5b046024b6
4 changed files with 28 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<select v-model="$i18n.locale" class="my-auto p-0 pr-9 bg-transparent border-0" :selected="$i18n.locale">
|
<select v-model="$i18n.locale" @change="onChange()" class="my-auto p-0 pr-9 bg-transparent border-0" :selected="$i18n.locale">
|
||||||
<option v-for="(lang, i) in langs" :key="`Lang${i}`" :value="lang">
|
<option v-for="(lang, i) in langs" :key="`Lang${i}`" :value="lang">
|
||||||
{{ names[i] }}
|
{{ names[i] }}
|
||||||
</option>
|
</option>
|
||||||
|
@ -12,8 +12,20 @@
|
||||||
export default {
|
export default {
|
||||||
setup() {
|
setup() {
|
||||||
return {
|
return {
|
||||||
langs: ['en'],
|
langs: ['en', 'es'],
|
||||||
names: ['English']
|
names: ['English', 'Español']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
const langs = ['en', 'es']
|
||||||
|
const savedLocale = localStorage.getItem("language")
|
||||||
|
if (savedLocale != null && langs.includes(savedLocale)) {
|
||||||
|
this.$i18n.locale = savedLocale
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onChange() {
|
||||||
|
localStorage.setItem("language", this.$i18n.locale)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { createI18n } from 'vue-i18n'
|
import { createI18n } from 'vue-i18n'
|
||||||
import en from '@/locales/en.json'
|
import en from '@/locales/en.json'
|
||||||
|
import es from '@/locales/es.json'
|
||||||
|
|
||||||
export default createI18n({
|
export default createI18n({
|
||||||
legacy: false,
|
legacy: false,
|
||||||
|
@ -8,5 +9,6 @@ export default createI18n({
|
||||||
globalInjection: true,
|
globalInjection: true,
|
||||||
messages: {
|
messages: {
|
||||||
'en': en,
|
'en': en,
|
||||||
|
'es': es
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 63c03e1dc2fdbc3fa8a2555454c34801c08374ec
|
Subproject commit f1a274ec29b072aef7064a33781fdd3e5f1357f5
|
|
@ -20,9 +20,18 @@ const rootBackendUrl = `${protocol}${import.meta.env.SAFETWITCH_BACKEND_DOMAIN}/
|
||||||
|
|
||||||
export async function getEndpoint(endpoint: string) {
|
export async function getEndpoint(endpoint: string) {
|
||||||
let data
|
let data
|
||||||
|
let language = localStorage.getItem("language")
|
||||||
|
if (language === null) {
|
||||||
|
language = "en"
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(rootBackendUrl + endpoint)
|
const res = await fetch(rootBackendUrl + endpoint, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
"Accept-Language": language
|
||||||
|
}
|
||||||
|
})
|
||||||
const rawData = await res.json()
|
const rawData = await res.json()
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
|
|
Loading…
Reference in a new issue