Fix: conflicting strings issue in translations (#917)

* Fix conflicting strings issue in translations

* Preserve structure of `customTranslations`

* Use `deepmerge` to merge whole of `localized-strings`

* Simplify and make deep property access on an object safe

* Fix deep property accessor and rename it to idx
This commit is contained in:
Laxman 2018-08-28 21:34:02 +05:30 committed by Endilie Yacop Sucipto
parent d18b09954b
commit cfabaedc99
12 changed files with 94 additions and 66 deletions

View file

@ -16,6 +16,7 @@ const DocsSidebar = require('./DocsSidebar.js');
const OnPageNav = require('./nav/OnPageNav.js');
const Site = require('./Site.js');
const translation = require('../server/translation.js');
const {idx} = require('./utils.js');
// component used to generate whole webpage for docs, including sidebar/header/footer
class DocsLayout extends React.Component {
@ -35,16 +36,15 @@ class DocsLayout extends React.Component {
render() {
const metadata = this.props.metadata;
const content = this.props.children;
const i18n = translation[this.props.metadata.language];
const i18n = translation[metadata.language];
const id = metadata.localized_id;
const defaultTitle = metadata.title;
let DocComponent = Doc;
if (this.props.Doc) {
DocComponent = this.props.Doc;
}
const title = i18n
? translation[this.props.metadata.language]['localized-strings'][
this.props.metadata.localized_id
] || this.props.metadata.title
: this.props.metadata.title;
const title =
idx(i18n, ['localized-strings', 'docs', id, 'title']) || defaultTitle;
const hasOnPageNav = this.props.config.onPageNav === 'separate';
return (
<Site
@ -65,7 +65,7 @@ class DocsLayout extends React.Component {
content={content}
config={this.props.config}
source={metadata.source}
hideTitle={this.props.metadata.hide_title}
hideTitle={metadata.hide_title}
title={title}
version={metadata.version}
language={metadata.language}
@ -79,15 +79,10 @@ class DocsLayout extends React.Component {
metadata.previous_id
)}>
{' '}
{i18n
? translation[this.props.metadata.language][
'localized-strings'
][metadata.previous_id] ||
translation[this.props.metadata.language][
'localized-strings'
].previous ||
'Previous'
: metadata.previous_title || 'Previous'}
{idx(i18n, ['localized-strings', metadata.previous_id]) ||
idx(i18n, ['localized-strings', 'previous']) ||
metadata.previous_title ||
'Previous'}
</a>
)}
{metadata.next_id && (
@ -97,15 +92,10 @@ class DocsLayout extends React.Component {
metadata.localized_id,
metadata.next_id
)}>
{i18n
? translation[this.props.metadata.language][
'localized-strings'
][metadata.next_id] ||
translation[this.props.metadata.language][
'localized-strings'
].next ||
'Next'
: metadata.next_title || 'Next'}{' '}
{idx(i18n, ['localized-strings', metadata.next_id]) ||
idx(i18n, ['localized-strings', 'next']) ||
metadata.next_title ||
'Next'}{' '}
</a>
)}
@ -113,7 +103,7 @@ class DocsLayout extends React.Component {
</Container>
{hasOnPageNav && (
<nav className="onPageNav">
<OnPageNav rawContent={this.props.children} />
<OnPageNav rawContent={content} />
</nav>
)}
</div>