forked from AkkomaGang/akkoma-fe
resolve language from navigator langs (#139)
Co-authored-by: FloatingGhost <hannah@coffee-and-dreams.uk> Reviewed-on: AkkomaGang/pleroma-fe#139
This commit is contained in:
parent
df70b1e4be
commit
c1c40d72da
2 changed files with 16 additions and 1 deletions
|
@ -49,6 +49,20 @@ const preloadFetch = async (request) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const resolveLanguage = (instanceLanguages) => {
|
||||||
|
// First language in navigator.languages that is listed as an instance language
|
||||||
|
// falls back to first instance language
|
||||||
|
const navigatorLanguages = navigator.languages.map((x) => x.split('-')[0])
|
||||||
|
|
||||||
|
for (const navLanguage of navigatorLanguages) {
|
||||||
|
if (instanceLanguages.includes(navLanguage)) {
|
||||||
|
return navLanguage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return instanceLanguages[0]
|
||||||
|
}
|
||||||
|
|
||||||
const getInstanceConfig = async ({ store }) => {
|
const getInstanceConfig = async ({ store }) => {
|
||||||
try {
|
try {
|
||||||
const res = await preloadFetch('/api/v1/instance')
|
const res = await preloadFetch('/api/v1/instance')
|
||||||
|
@ -61,7 +75,7 @@ const getInstanceConfig = async ({ store }) => {
|
||||||
store.dispatch('setInstanceOption', { name: 'accountApprovalRequired', value: data.approval_required })
|
store.dispatch('setInstanceOption', { name: 'accountApprovalRequired', value: data.approval_required })
|
||||||
// don't override cookie if set
|
// don't override cookie if set
|
||||||
if (!Cookies.get('userLanguage')) {
|
if (!Cookies.get('userLanguage')) {
|
||||||
store.dispatch('setOption', { name: 'interfaceLanguage', value: data.languages[0] })
|
store.dispatch('setOption', { name: 'interfaceLanguage', value: resolveLanguage(data.languages) })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vapidPublicKey) {
|
if (vapidPublicKey) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
|
<FAIcon icon="globe" style="color: white;" /> {{ ' ' }}
|
||||||
<label for="interface-language-switcher">
|
<label for="interface-language-switcher">
|
||||||
{{ promptText }}
|
{{ promptText }}
|
||||||
</label>
|
</label>
|
||||||
|
|
Loading…
Reference in a new issue