mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-26 04:57:50 +02:00
Merge branch 'deltice' of https://github.com/facebookexperimental/Docusaurus into deltice
This commit is contained in:
commit
6e1d5579fc
3 changed files with 48 additions and 0 deletions
45
lib/server/find-strings-plugin.js
Normal file
45
lib/server/find-strings-plugin.js
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2017-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* find all strings with their descriptions that need to be translated and write
|
||||||
|
to i18n/en.json file */
|
||||||
|
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
|
module.exports = function findStringsPlugin(babel) {
|
||||||
|
const { types: t } = babel;
|
||||||
|
|
||||||
|
const translationsFile = process.cwd() + "/i18n/en.json";
|
||||||
|
let currentTranslations = JSON.parse(
|
||||||
|
fs.readFileSync(translationsFile, "utf8")
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
visitor: {
|
||||||
|
JSXElement(path) {
|
||||||
|
if (path.node.openingElement.name.name !== "Translate") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const text = path.node.children[0].value.trim();
|
||||||
|
let description;
|
||||||
|
const attributes = path.node.openingElement.attributes;
|
||||||
|
for (let i = 0; i < attributes.length; i++) {
|
||||||
|
if (attributes[i].name.name === "desc") {
|
||||||
|
description = attributes[i].value.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!currentTranslations["pages-strings"]) {
|
||||||
|
currentTranslations["pages-strings"] = {};
|
||||||
|
}
|
||||||
|
currentTranslations["pages-strings"][text + "|" + description] = text;
|
||||||
|
fs.writeFileSync(translationsFile, JSON.stringify(currentTranslations));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -18,6 +18,7 @@ const path = require("path");
|
||||||
const siteConfig = require(CWD + "/siteConfig.js");
|
const siteConfig = require(CWD + "/siteConfig.js");
|
||||||
const babylon = require("babylon");
|
const babylon = require("babylon");
|
||||||
const traverse = require("babel-traverse").default;
|
const traverse = require("babel-traverse").default;
|
||||||
|
const siteConfig = require(CWD + "/siteConfig.js");
|
||||||
|
|
||||||
function writeFileAndCreateFolder(file, content) {
|
function writeFileAndCreateFolder(file, content) {
|
||||||
mkdirp.sync(file.replace(new RegExp("/[^/]*$"), ""));
|
mkdirp.sync(file.replace(new RegExp("/[^/]*$"), ""));
|
||||||
|
@ -88,6 +89,7 @@ function execute() {
|
||||||
});
|
});
|
||||||
|
|
||||||
writeFileAndCreateFolder(CWD + "/i18n/en.json", JSON.stringify(translations));
|
writeFileAndCreateFolder(CWD + "/i18n/en.json", JSON.stringify(translations));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = execute;
|
module.exports = execute;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
"examples": "./lib/copy-examples.js"
|
"examples": "./lib/copy-examples.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"babel-cli": "^6.24.1",
|
||||||
"babel-preset-react": "^6.24.1",
|
"babel-preset-react": "^6.24.1",
|
||||||
"babel-register": "^6.24.1",
|
"babel-register": "^6.24.1",
|
||||||
"babel-traverse": "^6.25.0",
|
"babel-traverse": "^6.25.0",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue