2024-08-27 20:02:38 +02:00

15 lines
576 B
TypeScript

import {addLocale, useLocale} from 'ttag'
const locale = navigator.language.split('-')[0]
export const regionNames = new Intl.DisplayNames([locale], {type: 'region'})
if (locale !== 'en') {
fetch(`/locales/${locale}.po.json`).then(response => {
if (!response.ok) throw new Error(`Failed to load translations for locale ${locale}`)
response.json().then(translationsObj => {
addLocale(locale, translationsObj)
useLocale(locale)
})
}).catch(() => console.error(`Unable to retrieve translation file ${locale}.po.json`))
}