feat: add translation support (#2870)

* feat: add translation support

* test(cypress): fix locale import

* docs: add locale documentation

* feat: add german translation (#2877)

* fix: locales package version, register all locales in netlify-cms
This commit is contained in:
Erez Rokah
2019-11-14 11:25:04 +02:00
committed by GitHub
parent 4833f33728
commit 096b067d45
22 changed files with 660 additions and 191 deletions

View File

@ -1,12 +1,13 @@
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { Provider, connect } from 'react-redux';
import { Route } from 'react-router-dom';
import { ConnectedRouter } from 'react-router-redux';
import history from 'Routing/history';
import store from 'ReduxStore';
import { mergeConfig } from 'Actions/config';
import { getPhrases } from 'Constants/defaultPhrases';
import { getPhrases } from 'Lib/phrases';
import { selectLocale } from 'Selectors/config';
import { I18n } from 'react-polyglot';
import { GlobalStyles } from 'netlify-cms-ui-default';
import { ErrorBoundary } from 'UI';
@ -17,6 +18,24 @@ import 'what-input';
const ROOT_ID = 'nc-root';
const TranslatedApp = ({ locale }) => {
return (
<I18n locale={locale} messages={getPhrases(locale)}>
<ErrorBoundary showBackup>
<ConnectedRouter history={history}>
<Route component={App} />
</ConnectedRouter>
</ErrorBoundary>
</I18n>
);
};
const mapDispatchToProps = state => {
return { locale: selectLocale(state.config) };
};
const ConnectedTranslatedApp = connect(mapDispatchToProps)(TranslatedApp);
function bootstrap(opts = {}) {
const { config } = opts;
@ -63,15 +82,9 @@ function bootstrap(opts = {}) {
const Root = () => (
<>
<GlobalStyles />
<I18n locale={'en'} messages={getPhrases()}>
<ErrorBoundary showBackup>
<Provider store={store}>
<ConnectedRouter history={history}>
<Route component={App} />
</ConnectedRouter>
</Provider>
</ErrorBoundary>
</I18n>
<Provider store={store}>
<ConnectedTranslatedApp />
</Provider>
</>
);