mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-02 02:42:41 +02:00
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:
parent
d18b09954b
commit
cfabaedc99
12 changed files with 94 additions and 66 deletions
|
@ -22,7 +22,7 @@ const readMetadata = require('../../server/readMetadata.js');
|
|||
|
||||
readMetadata.generateMetadataDocs();
|
||||
const Metadata = require('../metadata.js');
|
||||
const utils = require('../utils.js');
|
||||
const {idx, getPath} = require('../utils.js');
|
||||
|
||||
const extension = siteConfig.cleanUrl ? '' : '.html';
|
||||
|
||||
|
@ -56,7 +56,7 @@ class LanguageDropDown extends React.Component {
|
|||
}
|
||||
return (
|
||||
<li key={lang.tag}>
|
||||
<a href={utils.getPath(href, this.props.cleanUrl)}>{lang.name}</a>
|
||||
<a href={getPath(href, this.props.cleanUrl)}>{lang.name}</a>
|
||||
</li>
|
||||
);
|
||||
});
|
||||
|
@ -188,7 +188,7 @@ class HeaderNav extends React.Component {
|
|||
}
|
||||
href =
|
||||
this.props.config.baseUrl +
|
||||
utils.getPath(Metadata[id].permalink, this.props.config.cleanUrl);
|
||||
getPath(Metadata[id].permalink, this.props.config.cleanUrl);
|
||||
|
||||
const {id: currentID, sidebar} = this.props.current;
|
||||
docItemActive = currentID && currentID === id;
|
||||
|
@ -220,12 +220,11 @@ class HeaderNav extends React.Component {
|
|||
(link.blog && this.props.current.blogListing) ||
|
||||
(link.page && link.page === this.props.current.id),
|
||||
});
|
||||
const i18n = translation[this.props.language];
|
||||
return (
|
||||
<li key={`${link.label}page`} className={itemClasses}>
|
||||
<a href={href} target={link.external ? '_blank' : '_self'}>
|
||||
{translation[this.props.language]
|
||||
? translation[this.props.language]['localized-strings'][link.label]
|
||||
: link.label}
|
||||
{idx(i18n, ['localized-strings', 'links', link.label]) || link.label}
|
||||
</a>
|
||||
</li>
|
||||
);
|
||||
|
|
|
@ -10,15 +10,18 @@ const classNames = require('classnames');
|
|||
|
||||
const siteConfig = require(`${process.cwd()}/siteConfig.js`);
|
||||
const translation = require('../../server/translation.js');
|
||||
const utils = require('../utils.js');
|
||||
const {getPath, idx} = require('../utils.js');
|
||||
|
||||
class SideNav extends React.Component {
|
||||
// return appropriately translated category string
|
||||
getLocalizedCategoryString(category) {
|
||||
const categoryString = translation[this.props.language]
|
||||
? translation[this.props.language]['localized-strings'][category] ||
|
||||
category
|
||||
: category;
|
||||
const categoryString =
|
||||
idx(translation, [
|
||||
this.props.language,
|
||||
'localized-strings',
|
||||
'categories',
|
||||
category,
|
||||
]) || category;
|
||||
return categoryString;
|
||||
}
|
||||
|
||||
|
@ -26,17 +29,16 @@ class SideNav extends React.Component {
|
|||
getLocalizedString(metadata) {
|
||||
let localizedString;
|
||||
const i18n = translation[this.props.language];
|
||||
const id = metadata.localized_id;
|
||||
const sbTitle = metadata.sidebar_label;
|
||||
|
||||
if (sbTitle) {
|
||||
localizedString = i18n
|
||||
? i18n['localized-strings'][sbTitle] || sbTitle
|
||||
: sbTitle;
|
||||
localizedString =
|
||||
idx(i18n, ['localized-strings', 'docs', id, 'sidebar_label']) ||
|
||||
sbTitle;
|
||||
} else {
|
||||
const id = metadata.original_id || metadata.localized_id;
|
||||
localizedString = i18n
|
||||
? i18n['localized-strings'][id] || metadata.title
|
||||
: metadata.title;
|
||||
localizedString =
|
||||
idx(i18n, ['localized-strings', 'docs', id, 'title']) || metadata.title;
|
||||
}
|
||||
return localizedString;
|
||||
}
|
||||
|
@ -44,14 +46,14 @@ class SideNav extends React.Component {
|
|||
// return link to doc in sidebar
|
||||
getLink(metadata) {
|
||||
if (metadata.permalink) {
|
||||
const targetLink = utils.getPath(metadata.permalink, siteConfig.cleanUrl);
|
||||
const targetLink = getPath(metadata.permalink, siteConfig.cleanUrl);
|
||||
if (targetLink.match(/^https?:/)) {
|
||||
return targetLink;
|
||||
}
|
||||
return siteConfig.baseUrl + targetLink;
|
||||
}
|
||||
if (metadata.path) {
|
||||
return `${siteConfig.baseUrl}blog/${utils.getPath(
|
||||
return `${siteConfig.baseUrl}blog/${getPath(
|
||||
metadata.path,
|
||||
siteConfig.cleanUrl
|
||||
)}`;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue