]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/helpers/i18n-utils.ts
Prevent player crash on safari
[github/Chocobozzz/PeerTube.git] / client / src / app / helpers / i18n-utils.ts
... / ...
CommitLineData
1import IntlMessageFormat from 'intl-messageformat'
2import { logger } from '@root-helpers/logger'
3import { environment } from '../../environments/environment'
4
5function isOnDevLocale () {
6 return environment.production === false && window.location.search === '?lang=fr'
7}
8
9function getDevLocale () {
10 return 'fr-FR'
11}
12
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) {
23 if (!alreadyWarned) logger.warn(`Cannot format ICU ${icu}.`, err)
24
25 alreadyWarned = true
26 return fallback
27 }
28 }
29 } catch (err) {
30 logger.warn(`Cannot build intl message ${icu}.`, err)
31
32 return (_context: unknown, fallback: string) => fallback
33 }
34}
35
36export {
37 getDevLocale,
38 prepareIcu,
39 isOnDevLocale
40}