From 3c72960bd10325ac5f5aea2227ddfbdbb7bd6f6f Mon Sep 17 00:00:00 2001 From: Manuel Stahl Date: Fri, 7 Feb 2020 16:29:11 +0100 Subject: [PATCH] Add translation support Change-Id: I8cc38cd00683ce6f0ef8f62eb9eeddfc84c52a34 --- package.json | 1 + src/App.js | 17 +++++++++++++++-- src/i18n/de.js | 5 +++++ src/i18n/en.js | 5 +++++ yarn.lock | 5 +++++ 5 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/i18n/de.js create mode 100644 src/i18n/en.js diff --git a/package.json b/package.json index 321383a..a167252 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ }, "dependencies": { "prop-types": "^15.7.2", + "ra-language-german": "^2.1.2", "react": "^16.12.0", "react-admin": "^3.1.3", "react-dom": "^16.12.0", diff --git a/src/App.js b/src/App.js index db7aa68..2dc16d6 100644 --- a/src/App.js +++ b/src/App.js @@ -1,9 +1,22 @@ import React from "react"; -import { Admin, Resource } from "react-admin"; +import { Admin, Resource, resolveBrowserLocale } from "react-admin"; +import polyglotI18nProvider from "ra-i18n-polyglot"; import dataProvider from "./dataProvider"; +import germanMessages from "./i18n/de"; +import englishMessages from "./i18n/en"; + +// TODO: Can we use lazy loading together with browser locale? +const messages = { + de: germanMessages, + en: englishMessages, +}; +const i18nProvider = polyglotI18nProvider( + locale => (messages[locale] ? messages[locale] : messages.en), + resolveBrowserLocale() +); const App = () => ( - + ); diff --git a/src/i18n/de.js b/src/i18n/de.js new file mode 100644 index 0000000..1de8dd9 --- /dev/null +++ b/src/i18n/de.js @@ -0,0 +1,5 @@ +import germanMessages from "ra-language-german"; + +export default { + ...germanMessages, +}; diff --git a/src/i18n/en.js b/src/i18n/en.js new file mode 100644 index 0000000..fcee097 --- /dev/null +++ b/src/i18n/en.js @@ -0,0 +1,5 @@ +import englishMessages from "ra-language-english"; + +export default { + ...englishMessages, +}; diff --git a/yarn.lock b/yarn.lock index 814ab1d..c1a23ab 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8974,6 +8974,11 @@ ra-language-english@^3.2.0: resolved "https://registry.yarnpkg.com/ra-language-english/-/ra-language-english-3.2.0.tgz#2ca13b767d834b43fefd128f48e452449f812b61" integrity sha512-/XmwYWoQoB4MBkkzBCbg/ykCuRGjHQOHLk2ik6n1aM10AWHxiiJNyRw2aoLzH7Vc5rcp4BBJQCuhT+DgfYIJ2Q== +ra-language-german@^2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/ra-language-german/-/ra-language-german-2.1.2.tgz#d183093d470ab499ece91838cb67222db88f2e4f" + integrity sha512-N+BaBP0z98ujaKVlAMIKTfWHgmTiWD8sPQrU5vA3+b5zY9U0mMB4VjvU8sQQPR7rZE0gsRgS/X4V6ycDtNL6iQ== + ra-ui-materialui@^3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/ra-ui-materialui/-/ra-ui-materialui-3.2.1.tgz#8e0d9b74c36e9f800b8b766d67dfc720b821f561"