add translateable strings and allow overriding of english strings (#158)

This commit is contained in:
Ricky Vetter 2017-10-23 15:01:26 -07:00 committed by Joel Marcey
parent 65a5e02ec2
commit 58613545b6
2 changed files with 35 additions and 2 deletions

View file

@ -8,6 +8,15 @@
const React = require("react"); const React = require("react");
const Marked = require("./Marked.js"); const Marked = require("./Marked.js");
const translate = require("../server/translate.js").translate;
const editThisDoc = translate(
"Edit this Doc|recruitment message asking to edit the doc source"
);
const translateThisDoc = translate(
"Translate this Doc|recruitment message asking to translate the docs"
);
// inner doc component for article itself // inner doc component for article itself
class Doc extends React.Component { class Doc extends React.Component {
render() { render() {
@ -17,7 +26,7 @@ class Doc extends React.Component {
className="edit-page-link button" className="edit-page-link button"
href={this.props.config.editUrl + this.props.source} href={this.props.config.editUrl + this.props.source}
target="_blank"> target="_blank">
Edit this Doc {editThisDoc}
</a> </a>
); );
if (this.props.language != "en") { if (this.props.language != "en") {
@ -31,7 +40,7 @@ class Doc extends React.Component {
this.props.language this.props.language
} }
target="_blank"> target="_blank">
Translate this Doc {translateThisDoc}
</a> </a>
); );
} }

View file

@ -20,6 +20,14 @@ const babylon = require("babylon");
const traverse = require("babel-traverse").default; const traverse = require("babel-traverse").default;
const sidebars = require(CWD + "/sidebars.json"); const sidebars = require(CWD + "/sidebars.json");
let currentTranslations = {
"localized-strings": {},
"pages-strings": {}
};
if (fs.existsSync(path)) {
currentTranslations = JSON.parse(fs.readFileSync(CWD + "/i18n/en.json", "utf8"));
}
function writeFileAndCreateFolder(file, content) { function writeFileAndCreateFolder(file, content) {
mkdirp.sync(file.replace(new RegExp("/[^/]*$"), "")); mkdirp.sync(file.replace(new RegExp("/[^/]*$"), ""));
fs.writeFileSync(file, content); fs.writeFileSync(file, content);
@ -121,6 +129,22 @@ function execute() {
"Help Translate|recruit community translators for your project" "Help Translate|recruit community translators for your project"
] = ] =
"Help Translate"; "Help Translate";
translations["pages-strings"][
"Edit this Doc|recruitment message asking to edit the doc source"
] =
"Edit";
translations["pages-strings"][
"Translate this Doc|recruitment message asking to translate the docs"
] =
"Translate";
translations["pages-strings"] = Object.assign(
translations["pages-strings"],
currentTranslations["pages-strings"],
);
translations["localized-strings"] = Object.assign(
translations["localized-strings"],
currentTranslations["localized-strings"],
);
writeFileAndCreateFolder( writeFileAndCreateFolder(
CWD + "/i18n/en.json", CWD + "/i18n/en.json",
JSON.stringify(translations, null, 2) JSON.stringify(translations, null, 2)