15 lines
576 B
TypeScript
Raw Normal View History

2024-07-28 15:36:22 +02:00
import {addLocale, useLocale} from 'ttag'
2024-07-30 00:55:36 +02:00
const locale = navigator.language.split('-')[0]
export const regionNames = new Intl.DisplayNames([locale], {type: 'region'})
2024-07-28 15:36:22 +02:00
if (locale !== 'en') {
fetch(`/locales/${locale}.po.json`).then(response => {
2024-08-27 20:02:38 +02:00
if (!response.ok) throw new Error(`Failed to load translations for locale ${locale}`)
2024-07-28 15:36:22 +02:00
response.json().then(translationsObj => {
2024-08-27 20:02:38 +02:00
addLocale(locale, translationsObj)
useLocale(locale)
2024-07-28 15:36:22 +02:00
})
2024-08-27 20:02:38 +02:00
}).catch(() => console.error(`Unable to retrieve translation file ${locale}.po.json`))
2024-07-28 15:36:22 +02:00
}