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