mirror of
https://github.com/ZwareBear/awx.git
synced 2026-05-13 15:58:41 -05:00
updates the method of loading locales
This commit is contained in:
Generated
+12
-2
@@ -5389,6 +5389,11 @@
|
|||||||
"q": "^1.1.2"
|
"q": "^1.1.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"codemirror": {
|
||||||
|
"version": "5.60.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.60.0.tgz",
|
||||||
|
"integrity": "sha512-AEL7LhFOlxPlCL8IdTcJDblJm8yrAGib7I+DErJPdZd4l6imx8IMgKK3RblVgBQqz3TZJR4oknQ03bz+uNjBYA=="
|
||||||
|
},
|
||||||
"collection-visit": {
|
"collection-visit": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/collection-visit/-/collection-visit-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/collection-visit/-/collection-visit-1.0.0.tgz",
|
||||||
@@ -6670,6 +6675,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"diff": {
|
||||||
|
"version": "4.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
|
||||||
|
"integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"diff-match-patch": {
|
"diff-match-patch": {
|
||||||
"version": "1.0.5",
|
"version": "1.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/diff-match-patch/-/diff-match-patch-1.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/diff-match-patch/-/diff-match-patch-1.0.5.tgz",
|
||||||
@@ -11743,8 +11754,7 @@
|
|||||||
"lodash.get": {
|
"lodash.get": {
|
||||||
"version": "4.4.2",
|
"version": "4.4.2",
|
||||||
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
|
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
|
||||||
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=",
|
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"lodash.isequal": {
|
"lodash.isequal": {
|
||||||
"version": "4.5.0",
|
"version": "4.5.0",
|
||||||
|
|||||||
+7
-37
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import {
|
import {
|
||||||
useRouteMatch,
|
useRouteMatch,
|
||||||
useLocation,
|
useLocation,
|
||||||
@@ -10,20 +10,13 @@ import {
|
|||||||
import { I18nProvider } from '@lingui/react';
|
import { I18nProvider } from '@lingui/react';
|
||||||
import { i18n } from '@lingui/core';
|
import { i18n } from '@lingui/core';
|
||||||
|
|
||||||
import { en, es, fr, nl, zh, ja, zu } from 'make-plural/plurals';
|
|
||||||
import AppContainer from './components/AppContainer';
|
import AppContainer from './components/AppContainer';
|
||||||
import Background from './components/Background';
|
import Background from './components/Background';
|
||||||
import NotFound from './screens/NotFound';
|
import NotFound from './screens/NotFound';
|
||||||
import Login from './screens/Login';
|
import Login from './screens/Login';
|
||||||
|
|
||||||
import japanese from './locales/ja/messages';
|
|
||||||
import english from './locales/en/messages';
|
|
||||||
import zulu from './locales/zu/messages';
|
|
||||||
import french from './locales/fr/messages';
|
|
||||||
import dutch from './locales/nl/messages';
|
|
||||||
import chinese from './locales/zh/messages';
|
|
||||||
import spanish from './locales/es/messages';
|
|
||||||
import { isAuthenticated } from './util/auth';
|
import { isAuthenticated } from './util/auth';
|
||||||
|
import { locales, dynamicActivate } from './i18nLoader';
|
||||||
|
|
||||||
import { getLanguageWithoutRegionCode } from './util/language';
|
import { getLanguageWithoutRegionCode } from './util/language';
|
||||||
|
|
||||||
@@ -80,42 +73,19 @@ const ProtectedRoute = ({ children, ...rest }) =>
|
|||||||
);
|
);
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const catalogs = {
|
|
||||||
en: english,
|
|
||||||
ja: japanese,
|
|
||||||
zu: zulu,
|
|
||||||
fr: french,
|
|
||||||
es: spanish,
|
|
||||||
zh: chinese,
|
|
||||||
nl: dutch,
|
|
||||||
};
|
|
||||||
let language = getLanguageWithoutRegionCode(navigator);
|
let language = getLanguageWithoutRegionCode(navigator);
|
||||||
if (!Object.keys(catalogs).includes(language)) {
|
if (!Object.keys(locales).includes(language)) {
|
||||||
// If there isn't a string catalog available for the browser's
|
// If there isn't a string catalog available for the browser's
|
||||||
// preferred language, default to one that has strings.
|
// preferred language, default to one that has strings.
|
||||||
language = 'en';
|
language = 'en';
|
||||||
}
|
}
|
||||||
const { hash, search, pathname } = useLocation();
|
const { hash, search, pathname } = useLocation();
|
||||||
|
useEffect(() => {
|
||||||
i18n.loadLocaleData('en', { plurals: en });
|
dynamicActivate(language);
|
||||||
i18n.loadLocaleData('es', { plurals: es });
|
}, [language]);
|
||||||
i18n.loadLocaleData('fr', { plurals: fr });
|
|
||||||
i18n.loadLocaleData('nl', { plurals: nl });
|
|
||||||
i18n.loadLocaleData('zh', { plurals: zh });
|
|
||||||
i18n.loadLocaleData('ja', { plurals: ja });
|
|
||||||
i18n.loadLocaleData('zu', { plurals: zu });
|
|
||||||
i18n.load({
|
|
||||||
en: english.messages,
|
|
||||||
ja: japanese.messages,
|
|
||||||
zu: zulu.messages,
|
|
||||||
fr: french.messages,
|
|
||||||
nl: dutch.messages,
|
|
||||||
zh: chinese.messages,
|
|
||||||
es: spanish.messages,
|
|
||||||
});
|
|
||||||
i18n.activate(language);
|
i18n.activate(language);
|
||||||
return (
|
return (
|
||||||
<I18nProvider i18n={i18n} catalogs={catalogs}>
|
<I18nProvider i18n={i18n}>
|
||||||
<Background>
|
<Background>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route exact strict path="/*/">
|
<Route exact strict path="/*/">
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { i18n } from '@lingui/core';
|
||||||
|
import { en, fr, es, nl, ja, zh, zu } from 'make-plural/plurals';
|
||||||
|
|
||||||
|
export const locales = {
|
||||||
|
en: 'English',
|
||||||
|
ja: 'Japanese',
|
||||||
|
zu: 'Zulu',
|
||||||
|
fr: 'French',
|
||||||
|
es: 'Spanish',
|
||||||
|
zh: 'Chinese',
|
||||||
|
nl: 'Dutch',
|
||||||
|
};
|
||||||
|
|
||||||
|
i18n.loadLocaleData({
|
||||||
|
en: { plurals: en },
|
||||||
|
fr: { plurals: fr },
|
||||||
|
es: { plurals: es },
|
||||||
|
nl: { plurals: nl },
|
||||||
|
ja: { plurals: ja },
|
||||||
|
zh: { plurals: zh },
|
||||||
|
zu: { plurals: zu },
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We do a dynamic import of just the catalog that we need
|
||||||
|
* @param locale any locale string
|
||||||
|
*/
|
||||||
|
export async function dynamicActivate(locale) {
|
||||||
|
const { messages } = await import(`./locales/${locale}/messages`);
|
||||||
|
i18n.load(locale, messages);
|
||||||
|
}
|
||||||
+5008
-3616
File diff suppressed because it is too large
Load Diff
+4729
-3571
File diff suppressed because it is too large
Load Diff
+4729
-3571
File diff suppressed because it is too large
Load Diff
+4729
-3571
File diff suppressed because it is too large
Load Diff
+4729
-3571
File diff suppressed because it is too large
Load Diff
+4729
-3571
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user