]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/helpers/i18n-utils.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / helpers / i18n-utils.ts
CommitLineData
eaa52952 1import IntlMessageFormat from 'intl-messageformat'
42b40636
C
2import { logger } from '@root-helpers/logger'
3import { environment } from '../../environments/environment'
74b7c6d4 4
74b7c6d4
C
5function isOnDevLocale () {
6 return environment.production === false && window.location.search === '?lang=fr'
7}
8
9function getDevLocale () {
c0ffdd09 10 return 'fr-FR'
74b7c6d4
C
11}
12
eaa52952
C
13function 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 36export {
74b7c6d4 37 getDevLocale,
eaa52952 38 prepareIcu,
3dfa8494 39 isOnDevLocale
7ce44a74 40}