Skip to content

Commit

Permalink
fix(i18n): Fix i18n utility locale fallback logic (#432)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
jstoffan and mergify[bot] authored Apr 16, 2020
1 parent 43f8c0e commit bde2de5
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/utils/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import annotationsLocaleData from 'box-annotations-locale-data'; // eslint-disable-line
import annotationsLocaleData from 'box-annotations-locale-data';
import boxElementsMessages from 'box-elements-messages';
import { createIntl, createIntlCache, IntlShape } from 'react-intl';
import { IntlOptions } from '../@types/i18n';
import { IntlOptions } from '../@types';

declare const __LANGUAGE__: string; // eslint-disable-line no-underscore-dangle

const language = __LANGUAGE__;
const getLocale = (lang: string = language): string => {
return lang.substr(0, lang.indexOf('-'));
const getLocale = (language: string = __LANGUAGE__): string => {
return language.substr(0, language.indexOf('-'));
};

if (!window.Intl.PluralRules) {
Expand All @@ -22,14 +21,14 @@ if (!window.Intl.RelativeTimeFormat) {

const annotationsMessages = { ...annotationsLocaleData, ...boxElementsMessages };
const intlCache = createIntlCache();
const createIntlProvider = ({ locale = getLocale(), messages = annotationsMessages }: IntlOptions = {}): IntlShape => {
const createIntlProvider = ({ language, locale, messages = annotationsMessages }: IntlOptions = {}): IntlShape => {
return createIntl(
{
messages,
locale,
locale: locale || getLocale(language),
},
intlCache,
);
};

export default { createIntlProvider, getLocale, language };
export default { createIntlProvider, getLocale };

0 comments on commit bde2de5

Please sign in to comment.