forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathi18n.config.js
More file actions
48 lines (39 loc) · 1.22 KB
/
i18n.config.js
File metadata and controls
48 lines (39 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { i18n } from '@lingui/core'
import { en, fr } from 'make-plural/plurals'
i18n.loadLocaleData('en', { plurals: en })
i18n.loadLocaleData('fr', { plurals: fr })
export const locales = {
en: 'English',
fr: 'Français',
}
export async function activate(locale) {
let catalog
try {
catalog = await import(
/* webpackChunkName: "i18n-[index]" */ `@lingui/loader!../locales/${locale}.po`
)
} catch (e) {
// this fails only during tests due to webpack errors.
catalog = { messages: {} }
}
i18n.load(locale, catalog.messages)
i18n.activate(locale)
}
let defaultLanguage
const acceptedLanguageCodeRegex = /^(fr|en).*/i
if (navigator.languages) {
// check navigator.languages for supported languages
navigator.languages.find((lang) => {
const found = lang.match(acceptedLanguageCodeRegex)
if (found) defaultLanguage = found[1].toLowerCase()
return found
})
} else if (navigator.language) {
// IE doesn't support navigator.languages, check navigator.language
const found = navigator.language.match(acceptedLanguageCodeRegex)
if (found) defaultLanguage = found[1].toLowerCase()
} else {
// default to 'en'
defaultLanguage = 'en'
}
export const defaultLocale = defaultLanguage