resolve language from navigator langs (#139)
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
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 }) => {
|
||||
try {
|
||||
const res = await preloadFetch('/api/v1/instance')
|
||||
|
@ -61,7 +75,7 @@ const getInstanceConfig = async ({ store }) => {
|
|||
store.dispatch('setInstanceOption', { name: 'accountApprovalRequired', value: data.approval_required })
|
||||
// don't override cookie if set
|
||||
if (!Cookies.get('userLanguage')) {
|
||||
store.dispatch('setOption', { name: 'interfaceLanguage', value: data.languages[0] })
|
||||
store.dispatch('setOption', { name: 'interfaceLanguage', value: resolveLanguage(data.languages) })
|
||||
}
|
||||
|
||||
if (vapidPublicKey) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<template>
|
||||
<div>
|
||||
<FAIcon icon="globe" style="color: white;" /> {{ ' ' }}
|
||||
<label for="interface-language-switcher">
|
||||
{{ promptText }}
|
||||
</label>
|
||||
|
|
Loading…
Reference in a new issue