Commit 124f6420 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

fix: lazy load en-us (#3626)

parent 91f5fc08
...@@ -35,10 +35,7 @@ export const SUPPORTED_LOCALES = [ ...@@ -35,10 +35,7 @@ export const SUPPORTED_LOCALES = [
] ]
export type SupportedLocale = typeof SUPPORTED_LOCALES[number] | 'pseudo' export type SupportedLocale = typeof SUPPORTED_LOCALES[number] | 'pseudo'
// eslint-disable-next-line import/first
import * as enUS from 'locales/en-US'
export const DEFAULT_LOCALE: SupportedLocale = 'en-US' export const DEFAULT_LOCALE: SupportedLocale = 'en-US'
export const DEFAULT_CATALOG = enUS
export const LOCALE_LABEL: { [locale in SupportedLocale]: string } = { export const LOCALE_LABEL: { [locale in SupportedLocale]: string } = {
'af-ZA': 'Afrikaans', 'af-ZA': 'Afrikaans',
......
import { i18n } from '@lingui/core' import { i18n } from '@lingui/core'
import { I18nProvider } from '@lingui/react' import { I18nProvider } from '@lingui/react'
import { DEFAULT_CATALOG, DEFAULT_LOCALE, SupportedLocale } from 'constants/locales' import { SupportedLocale } from 'constants/locales'
import { import {
af, af,
ar, ar,
...@@ -78,12 +78,13 @@ const plurals: LocalePlural = { ...@@ -78,12 +78,13 @@ const plurals: LocalePlural = {
export async function dynamicActivate(locale: SupportedLocale) { export async function dynamicActivate(locale: SupportedLocale) {
i18n.loadLocaleData(locale, { plurals: () => plurals[locale] }) i18n.loadLocaleData(locale, { plurals: () => plurals[locale] })
// There are no default messages in production; instead, bundle the default to save a network request: try {
// There are no default messages in production,
// see https://github.com/lingui/js-lingui/issues/388#issuecomment-497779030 // see https://github.com/lingui/js-lingui/issues/388#issuecomment-497779030
const catalog = const catalog = await import(`${process.env.REACT_APP_LOCALES}/${locale}.js`)
locale === DEFAULT_LOCALE ? DEFAULT_CATALOG : await import(`${process.env.REACT_APP_LOCALES}/${locale}.js`)
// Bundlers will either export it as default or as a named export named default. // Bundlers will either export it as default or as a named export named default.
i18n.load(locale, catalog.messages || catalog.default.messages) i18n.load(locale, catalog.messages || catalog.default.messages)
} catch {}
i18n.activate(locale) i18n.activate(locale)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment