]>
Commit | Line | Data |
---|---|---|
67ed6552 | 1 | import { environment } from '../../environments/environment' |
eaa52952 | 2 | import IntlMessageFormat from 'intl-messageformat' |
74b7c6d4 | 3 | |
74b7c6d4 C |
4 | function isOnDevLocale () { |
5 | return environment.production === false && window.location.search === '?lang=fr' | |
6 | } | |
7 | ||
8 | function getDevLocale () { | |
c0ffdd09 | 9 | return 'fr-FR' |
74b7c6d4 C |
10 | } |
11 | ||
eaa52952 C |
12 | function prepareIcu (icu: string) { |
13 | let alreadyWarned = false | |
14 | ||
15 | try { | |
16 | const msg = new IntlMessageFormat(icu, $localize.locale) | |
17 | ||
18 | return (context: { [id: string]: number | string }, fallback: string) => { | |
19 | try { | |
20 | return msg.format(context) as string | |
21 | } catch (err) { | |
22 | if (!alreadyWarned) console.warn('Cannot format ICU %s.', icu, err) | |
23 | ||
24 | alreadyWarned = true | |
25 | return fallback | |
26 | } | |
27 | } | |
28 | } catch (err) { | |
29 | console.warn('Cannot build intl message %s.', icu, err) | |
30 | ||
31 | return (_context: unknown, fallback: string) => fallback | |
32 | } | |
33 | } | |
34 | ||
7ce44a74 | 35 | export { |
74b7c6d4 | 36 | getDevLocale, |
eaa52952 | 37 | prepareIcu, |
3dfa8494 | 38 | isOnDevLocale |
7ce44a74 | 39 | } |