@applica-software-guru/react-admin 1.5.331 → 1.5.332
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/i18n/createI18nProvider.d.ts +2 -1
- package/dist/i18n/createI18nProvider.d.ts.map +1 -1
- package/dist/i18n/en.json +8 -0
- package/{public/i18n/messages.json → dist/i18n/it.json} +446 -446
- package/dist/i18n/it.json.gz +0 -0
- package/dist/react-admin.cjs.js +1 -1
- package/dist/react-admin.cjs.js.gz +0 -0
- package/dist/react-admin.cjs.js.map +1 -1
- package/dist/react-admin.es.js +16 -11
- package/dist/react-admin.es.js.gz +0 -0
- package/dist/react-admin.es.js.map +1 -1
- package/dist/react-admin.umd.js +1 -1
- package/dist/react-admin.umd.js.gz +0 -0
- package/dist/react-admin.umd.js.map +1 -1
- package/package.json +1 -1
- package/public/i18n/en.json +8 -0
- package/{dist/i18n/messages.json → public/i18n/it.json} +446 -446
- package/src/i18n/createI18nProvider.tsx +24 -19
- package/src/playground/App.jsx +12 -1
- package/dist/i18n/languages.json +0 -1
- package/dist/i18n/messages.json.gz +0 -0
- package/public/i18n/languages.json +0 -1
|
@@ -20,6 +20,7 @@ type ICreateI18nProviderData = {
|
|
|
20
20
|
};
|
|
21
21
|
type ICreateJsonI18nProviderData = {
|
|
22
22
|
path: string;
|
|
23
|
+
locales: Locale[];
|
|
23
24
|
defaultLocale: string;
|
|
24
25
|
};
|
|
25
26
|
type IPolyglotOptions = {
|
|
@@ -100,18 +101,11 @@ function createI18nProvider(data: ICreateI18nProviderData): Promise<any> {
|
|
|
100
101
|
* @returns {Promise<I18nProvider>} - The I18nProvider
|
|
101
102
|
*/
|
|
102
103
|
function createJsonI18nProvider(data: ICreateJsonI18nProviderData): Promise<I18nProvider> {
|
|
103
|
-
const { defaultLocale, path } = data;
|
|
104
|
-
const defaultLanguages: Array<Locale> = [{ locale: defaultLocale, name: defaultLocale }];
|
|
104
|
+
const { locales, defaultLocale, path } = data;
|
|
105
105
|
const headers = new Headers({ Accept: 'application/json', 'Content-Type': 'application/json' });
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
.catch(() => {
|
|
110
|
-
return Promise.resolve(defaultLanguages);
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
function getMessages(): Promise<ITranslations> {
|
|
114
|
-
return fetch(`${path}/messages.json`, { headers: headers, method: 'get' })
|
|
106
|
+
|
|
107
|
+
function getMessages(locale: Locale): Promise<ITranslations> {
|
|
108
|
+
return fetch(`${path}/${locale.locale}.json`, { headers: headers, method: 'get' })
|
|
115
109
|
.then((response) => response.json())
|
|
116
110
|
.then((response: Array<IMessage>): ITranslations => {
|
|
117
111
|
return response.reduce(
|
|
@@ -126,15 +120,26 @@ function createJsonI18nProvider(data: ICreateJsonI18nProviderData): Promise<I18n
|
|
|
126
120
|
);
|
|
127
121
|
});
|
|
128
122
|
}
|
|
129
|
-
return Promise.all(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
123
|
+
return Promise.all(locales.map(getMessages))
|
|
124
|
+
.then((responses: ITranslations[]) =>
|
|
125
|
+
_.reduce(
|
|
126
|
+
responses,
|
|
127
|
+
(acc, messages) =>
|
|
128
|
+
({
|
|
129
|
+
...acc,
|
|
130
|
+
...messages
|
|
131
|
+
} as ITranslations),
|
|
132
|
+
{}
|
|
133
|
+
)
|
|
134
|
+
)
|
|
135
|
+
.then((messages) => {
|
|
136
|
+
function getMessages(locale: string): TranslationMessages {
|
|
137
|
+
return _.get(messages, locale, {}) as TranslationMessages;
|
|
138
|
+
}
|
|
139
|
+
return polyglotI18nProvider(getMessages, defaultLocale, locales, {
|
|
140
|
+
allowMissing: true
|
|
141
|
+
});
|
|
136
142
|
});
|
|
137
|
-
});
|
|
138
143
|
}
|
|
139
144
|
|
|
140
145
|
export type { ICreateI18nProviderData };
|
package/src/playground/App.jsx
CHANGED
|
@@ -20,7 +20,17 @@ const dataProvider = new ApplicaDataProvider({
|
|
|
20
20
|
attachmentsParser: createAttachmentsParser(),
|
|
21
21
|
HttpErrorClass: HttpError
|
|
22
22
|
});
|
|
23
|
-
const
|
|
23
|
+
const useJson = false;
|
|
24
|
+
const i18nProvider = useJson
|
|
25
|
+
? createJsonI18nProvider({
|
|
26
|
+
path: '/i18n',
|
|
27
|
+
defaultLocale: 'it',
|
|
28
|
+
locales: [
|
|
29
|
+
{ locale: 'it', name: 'Italiano' },
|
|
30
|
+
{ locale: 'en', name: 'English' }
|
|
31
|
+
]
|
|
32
|
+
})
|
|
33
|
+
: createI18nProvider({ apiUrl: API_URL, allowMissing: true, defaultLocale: 'it' });
|
|
24
34
|
function App() {
|
|
25
35
|
return (
|
|
26
36
|
<ApplicaAdmin
|
|
@@ -44,6 +54,7 @@ function App() {
|
|
|
44
54
|
oauth={{
|
|
45
55
|
google: { clientId: 'YOUR_CLIENT_ID' }
|
|
46
56
|
}}
|
|
57
|
+
enableLocaleSwitcher
|
|
47
58
|
>
|
|
48
59
|
<CustomRoutes>
|
|
49
60
|
<Route path="/custom-page" element={<CustomPage />} />
|
package/dist/i18n/languages.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
[{ "locale": "en", "name": "English" }]
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
[{ "locale": "en", "name": "English" }]
|