mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-02 16:29:47 +02:00
Move references to languages and translated strings out of siteConfig.js into new translation.js module
This commit is contained in:
parent
48916d9f39
commit
099a13a264
9 changed files with 52 additions and 112 deletions
|
@ -12,12 +12,13 @@ const Container = require("./Container.js");
|
|||
const Doc = require("./Doc.js");
|
||||
const DocsSidebar = require("./DocsSidebar.js");
|
||||
const Site = require("./Site.js");
|
||||
const translation = require("../server/translation.js");
|
||||
|
||||
class DocsLayout extends React.Component {
|
||||
render() {
|
||||
const metadata = this.props.metadata;
|
||||
const content = this.props.children;
|
||||
const i18n = this.props.config[this.props.metadata.language];
|
||||
const i18n = translation[this.props.metadata.language];
|
||||
return (
|
||||
<Site
|
||||
config={this.props.config}
|
||||
|
@ -25,9 +26,9 @@ class DocsLayout extends React.Component {
|
|||
section="docs"
|
||||
title={
|
||||
i18n
|
||||
? this.props.config[this.props.metadata.language][
|
||||
"localized-strings"
|
||||
][this.props.metadata.localized_id] || this.props.metadata.title
|
||||
? translation[this.props.metadata.language]["localized-strings"][
|
||||
this.props.metadata.localized_id
|
||||
] || this.props.metadata.title
|
||||
: this.props.metadata.title
|
||||
}
|
||||
description={content.trim().split("\n")[0]}
|
||||
|
@ -42,7 +43,7 @@ class DocsLayout extends React.Component {
|
|||
source={metadata.source}
|
||||
title={
|
||||
i18n
|
||||
? this.props.config[this.props.metadata.language][
|
||||
? translation[this.props.metadata.language][
|
||||
"localized-strings"
|
||||
][this.props.metadata.localized_id] ||
|
||||
this.props.metadata.title
|
||||
|
@ -58,7 +59,7 @@ class DocsLayout extends React.Component {
|
|||
>
|
||||
←{" "}
|
||||
{i18n
|
||||
? this.props.config[this.props.metadata.language][
|
||||
? translation[this.props.metadata.language][
|
||||
"localized-strings"
|
||||
]["previous"] || "Previous"
|
||||
: "Previous"}
|
||||
|
@ -69,7 +70,7 @@ class DocsLayout extends React.Component {
|
|||
href={metadata.next_id + ".html#content"}
|
||||
>
|
||||
{i18n
|
||||
? this.props.config[this.props.metadata.language][
|
||||
? translation[this.props.metadata.language][
|
||||
"localized-strings"
|
||||
]["next"] || "Next"
|
||||
: "Next"}{" "}
|
||||
|
|
|
@ -11,6 +11,7 @@ const React = require("react");
|
|||
const HeaderNav = require("./nav/HeaderNav.js");
|
||||
const Head = require("./Head.js");
|
||||
const Footer = require(process.cwd() + "/core/Footer.js");
|
||||
const translation = require("../server/translation.js");
|
||||
|
||||
class Site extends React.Component {
|
||||
/*
|
||||
|
@ -48,8 +49,8 @@ class Site extends React.Component {
|
|||
*/
|
||||
|
||||
render() {
|
||||
const tagline = this.props.config[this.props.language]
|
||||
? this.props.config[this.props.language]["localized-strings"].tagline
|
||||
const tagline = translation[this.props.language]
|
||||
? translation[this.props.language]["localized-strings"].tagline
|
||||
: this.props.config.tagline;
|
||||
const title = this.props.title
|
||||
? this.props.title + " · " + this.props.config.title
|
||||
|
|
|
@ -10,13 +10,14 @@
|
|||
const React = require("react");
|
||||
|
||||
const siteConfig = require(process.cwd() + "/siteConfig.js");
|
||||
const translation = require("../../server/translation.js");
|
||||
|
||||
class LanguageDropDown extends React.Component {
|
||||
render() {
|
||||
const enabledLanguages = [];
|
||||
let currentLanguage = "English";
|
||||
|
||||
siteConfig["languages"].map(lang => {
|
||||
translation["languages"].map(lang => {
|
||||
if (lang.tag == this.props.language) {
|
||||
currentLanguage = lang.name;
|
||||
}
|
||||
|
@ -97,8 +98,8 @@ class HeaderNav extends React.Component {
|
|||
href={linkWithLang}
|
||||
className={link.section === this.props.section ? "active" : ""}
|
||||
>
|
||||
{siteConfig[this.props.language]
|
||||
? siteConfig[this.props.language]["localized-strings"][link.text]
|
||||
{translation[this.props.language]
|
||||
? translation[this.props.language]["localized-strings"][link.text]
|
||||
: link.text}
|
||||
</a>
|
||||
</li>
|
||||
|
|
|
@ -11,6 +11,7 @@ const React = require("react");
|
|||
const classNames = require("classnames");
|
||||
|
||||
const siteConfig = require(process.cwd() + "/siteConfig.js");
|
||||
const translation = require("../../server/translation.js");
|
||||
|
||||
class SideNav extends React.Component {
|
||||
render() {
|
||||
|
@ -61,15 +62,15 @@ class SideNav extends React.Component {
|
|||
);
|
||||
}
|
||||
getLocalizedCategoryString(category) {
|
||||
let categoryString = siteConfig[this.props.language]
|
||||
? siteConfig[this.props.language]["localized-strings"][category] ||
|
||||
let categoryString = translation[this.props.language]
|
||||
? translation[this.props.language]["localized-strings"][category] ||
|
||||
category
|
||||
: category;
|
||||
return categoryString;
|
||||
}
|
||||
getLocalizedString(metadata) {
|
||||
let localizedString = siteConfig[this.props.language]
|
||||
? siteConfig[this.props.language]["localized-strings"][
|
||||
let localizedString = translation[this.props.language]
|
||||
? translation[this.props.language]["localized-strings"][
|
||||
metadata.localized_id
|
||||
] || metadata.title
|
||||
: metadata.title;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue