mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-02 10:52:35 +02:00
Merge branch 'master' of https://github.com/facebookexperimental/Docusaurus into website
This commit is contained in:
commit
63e3e31117
11 changed files with 277 additions and 120 deletions
|
@ -20,6 +20,7 @@ const path = require("path");
|
|||
const siteConfig = require(CWD + "/siteConfig.js");
|
||||
const babylon = require("babylon");
|
||||
const traverse = require("babel-traverse").default;
|
||||
const sidebar = require(CWD + "/sidebar.json");
|
||||
|
||||
function writeFileAndCreateFolder(file, content) {
|
||||
mkdirp.sync(file.replace(new RegExp("/[^/]*$"), ""));
|
||||
|
@ -37,16 +38,17 @@ function execute() {
|
|||
};
|
||||
|
||||
/* look through front matter of docs for titles and categories to translate */
|
||||
let files = glob.sync(CWD + "/../docs/en/**");
|
||||
let files = glob.sync(CWD + "/../docs/**");
|
||||
files.forEach(file => {
|
||||
const extension = path.extname(file);
|
||||
if (extension === ".md" || extension === ".markdown") {
|
||||
const metadata = readMetadata.extractMetadata(
|
||||
fs.readFileSync(file, "utf8")
|
||||
).metadata;
|
||||
const res = readMetadata.processMetadata(file);
|
||||
if (!res) {
|
||||
return;
|
||||
}
|
||||
const metadata = res.metadata;
|
||||
|
||||
translations["localized-strings"][metadata.id] = metadata.title;
|
||||
translations["localized-strings"][metadata.category] = metadata.category;
|
||||
translations["localized-strings"][metadata.localized_id] = metadata.title;
|
||||
|
||||
if (metadata.sidebar_title) {
|
||||
translations["localized-strings"][metadata.sidebar_title] =
|
||||
|
@ -64,6 +66,14 @@ function execute() {
|
|||
siteConfig.headerLinksExternal[i].text;
|
||||
}
|
||||
|
||||
/* find sidebar category titles to translate */
|
||||
Object.keys(sidebar).forEach(sb => {
|
||||
const categories = sidebar[sb];
|
||||
Object.keys(categories).forEach(category => {
|
||||
translations["localized-strings"][category] = category;
|
||||
});
|
||||
});
|
||||
|
||||
/* go through pages to look for text inside translate tags */
|
||||
files = glob.sync(CWD + "/pages/en/**");
|
||||
files.forEach(file => {
|
||||
|
@ -94,7 +104,10 @@ function execute() {
|
|||
});
|
||||
}
|
||||
});
|
||||
writeFileAndCreateFolder(CWD + "/i18n/en.json", JSON.stringify(translations));
|
||||
writeFileAndCreateFolder(
|
||||
CWD + "/i18n/en.json",
|
||||
JSON.stringify(translations, null, 2)
|
||||
);
|
||||
}
|
||||
|
||||
execute();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue