mirror of
https://github.com/Pomax/BezierInfo-2.git
synced 2025-08-29 19:20:39 +02:00
?locale=ja-JP
This commit is contained in:
93
article.ja-JP.js
Normal file
93
article.ja-JP.js
Normal file
File diff suppressed because one or more lines are too long
1315
locales/ja-JP/content.js
Normal file
1315
locales/ja-JP/content.js
Normal file
File diff suppressed because it is too large
Load Diff
140
make-locales.js
140
make-locales.js
@@ -150,73 +150,91 @@ function chunk(data) {
|
|||||||
return chunks;
|
return chunks;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then get the section map. This will try to load .jsx code, which will fail,
|
|
||||||
// but the above shim makes a failure simply return an empty object instead.
|
|
||||||
// This is good: we only care about the keys, not the content.
|
|
||||||
var index = require("./components/sections");
|
|
||||||
var sections = Object.keys(index);
|
|
||||||
var content = {};
|
|
||||||
sections.forEach((cname, number) => {
|
|
||||||
|
|
||||||
// Grab locale file, or defaultLocale file if the chosen locale has
|
/**
|
||||||
// has no translated content (yet)...
|
* Process a single locale, with `en-GB` fallback for missing files.
|
||||||
var localeCode = locale;
|
*/
|
||||||
var loc = `./components/sections/${cname}/content.${localeCode}.md`;
|
function processLocale(locale) {
|
||||||
if (!fs.existsSync(loc)) {
|
// Get the section map. This will try to load .jsx code, which will fail,
|
||||||
localeCode = defaultLocale;
|
// but the above shim makes a failure simply return an empty object instead.
|
||||||
loc = `./components/sections/${cname}/content.${localeCode}.md`;
|
// This is good: we only care about the keys, not the content.
|
||||||
}
|
var index = require("./components/sections");
|
||||||
|
var sections = Object.keys(index);
|
||||||
|
var content = {};
|
||||||
|
sections.forEach((cname, number) => {
|
||||||
|
|
||||||
// Read in the content.{lang}.md file
|
// Grab locale file, or defaultLocale file if the chosen locale has
|
||||||
var data, title;
|
// has no translated content (yet)...
|
||||||
try {
|
var localeCode = locale;
|
||||||
data = fs.readFileSync(loc).toString();
|
var loc = `./components/sections/${cname}/content.${localeCode}.md`;
|
||||||
data = chunk(data).map(block => {
|
if (!fs.existsSync(loc)) {
|
||||||
// preserver is simple
|
localeCode = defaultLocale;
|
||||||
if (!block.convert) return block.data;
|
loc = `./components/sections/${cname}/content.${localeCode}.md`;
|
||||||
|
}
|
||||||
|
|
||||||
// markdown conversion is a little more work
|
// Read in the content.{lang}.md file
|
||||||
let d = marked(block.data.trim());
|
var data, title;
|
||||||
|
try {
|
||||||
|
data = fs.readFileSync(loc).toString();
|
||||||
|
data = chunk(data).map(block => {
|
||||||
|
// preserver is simple
|
||||||
|
if (!block.convert) return block.data;
|
||||||
|
|
||||||
// serious can we fucking not, please.
|
// markdown conversion is a little more work
|
||||||
d = d.replace('<p></div></p>', '</div>')
|
let d = marked(block.data.trim());
|
||||||
.replace(/&/g, '&')
|
|
||||||
.replace(/'/g, "'")
|
|
||||||
.replace(/"/g, '"')
|
|
||||||
|
|
||||||
// ``` conversion does odd things with <code> tags inside <pre> tags.
|
// serious can we fucking not, please.
|
||||||
d = d.replace(/<pre>(\r?\n)*<code>/g,'<pre>')
|
d = d.replace('<p></div></p>', '</div>')
|
||||||
.replace(/<\/code>(\r?\n)*<\/pre>/g,'</pre>');
|
.replace(/&/g, '&')
|
||||||
|
.replace(/'/g, "'")
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
|
||||||
// And then title extraction/rewriting
|
// ``` conversion does odd things with <code> tags inside <pre> tags.
|
||||||
d = d.replace(/<h1[^>]+>([^<]+)<\/h1>/,function(_,t) {
|
d = d.replace(/<pre>(\r?\n)*<code>/g,'<pre>')
|
||||||
title = t;
|
.replace(/<\/code>(\r?\n)*<\/pre>/g,'</pre>');
|
||||||
return `<SectionHeader name="${cname}" title="` + t + `"${ number ? ' number="'+number+'"': ''}/>`;
|
|
||||||
});
|
|
||||||
|
|
||||||
return d;
|
// And then title extraction/rewriting
|
||||||
}).join('');
|
d = d.replace(/<h1[^>]+>([^<]+)<\/h1>/,function(_,t) {
|
||||||
} catch (e) { data = ''; title = `Unknown title (${cname})`; }
|
title = t;
|
||||||
|
return `<SectionHeader name="${cname}" title="` + t + `"${ number ? ' number="'+number+'"': ''}/>`;
|
||||||
|
});
|
||||||
|
|
||||||
content[cname] = {
|
return d;
|
||||||
locale: localeCode,
|
}).join('');
|
||||||
title: title,
|
} catch (e) { data = ''; title = `Unknown title (${cname})`; }
|
||||||
getContent: "<section>" + data + "</section>"
|
|
||||||
};
|
content[cname] = {
|
||||||
|
locale: localeCode,
|
||||||
|
title: title,
|
||||||
|
getContent: "<section>" + data + "</section>"
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
var bcode = JSON.stringify(content, false, 2);
|
||||||
|
bcode = bcode.replace(/"<section>/g, "function(handler) { return <section>")
|
||||||
|
.replace(/this\.(\w)/g, "handler.$1")
|
||||||
|
.replace(/<\/section>"(,?)/g, "</section>; }$1\n")
|
||||||
|
.replace(/\\"/g,'"')
|
||||||
|
.replace(/\\n/g,'\n')
|
||||||
|
.replace(/></g,'>\n<')
|
||||||
|
.replace(/\\\\/g, '\\');
|
||||||
|
|
||||||
|
var bundle = `var React = require('react');\nvar Graphic = require("../../components/Graphic.jsx");\nvar SectionHeader = require("../../components/SectionHeader.jsx");\n\nmodule.exports = ${bcode};\n`;
|
||||||
|
|
||||||
|
var dir = `./locales/${locale}`;
|
||||||
|
fs.ensureDir(dir);
|
||||||
|
fs.writeFileSync(`${dir}/content.js`, bundle);
|
||||||
|
}
|
||||||
|
|
||||||
|
// find all locales used
|
||||||
|
var glob = require('glob');
|
||||||
|
glob("components/sections/**/content*md", (err, files) => {
|
||||||
|
var locales = [];
|
||||||
|
files.forEach(file => {
|
||||||
|
let locale = file.match(/content\.([^.]+)\.md/)[1];
|
||||||
|
if (locales.indexOf(locale) === -1) {
|
||||||
|
locales.push(locale);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
locales.forEach( processLocale);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Now, form a JSX resource for this locale.
|
|
||||||
var bcode = JSON.stringify(content, false, 2);
|
|
||||||
bcode = bcode.replace(/"<section>/g, "function(handler) { return <section>")
|
|
||||||
.replace(/this\.(\w)/g, "handler.$1")
|
|
||||||
.replace(/<\/section>"(,?)/g, "</section>; }$1\n")
|
|
||||||
.replace(/\\"/g,'"')
|
|
||||||
.replace(/\\n/g,'\n')
|
|
||||||
.replace(/></g,'>\n<')
|
|
||||||
.replace(/\\\\/g, '\\');
|
|
||||||
|
|
||||||
var bundle = `var React = require('react');\nvar Graphic = require("../../components/Graphic.jsx");\nvar SectionHeader = require("../../components/SectionHeader.jsx");\n\nmodule.exports = ${bcode};\n`;
|
|
||||||
|
|
||||||
var dir = `./locales/${locale}`;
|
|
||||||
fs.ensureDir(dir);
|
|
||||||
fs.writeFileSync(`${dir}/content.js`, bundle);
|
|
||||||
|
@@ -6,10 +6,10 @@
|
|||||||
"localize": "node make-locales",
|
"localize": "node make-locales",
|
||||||
"build": "npm run localize && npm run less && webpack -p",
|
"build": "npm run localize && npm run less && webpack -p",
|
||||||
"build:zh-CN": "npm run localize && npm run less && cross-env LOCALE=zh-CN webpack -p",
|
"build:zh-CN": "npm run localize && npm run less && cross-env LOCALE=zh-CN webpack -p",
|
||||||
|
"build:ja-JP": "npm run localize && npm run less && cross-env LOCALE=ja-JP webpack -p",
|
||||||
"dev": "npm run localize && npm run less && webpack-dev-server --progress --colors --hot --inline",
|
"dev": "npm run localize && npm run less && webpack-dev-server --progress --colors --hot --inline",
|
||||||
"dev:zh-CN": "npm run localize && npm run less && cross-env LOCALE=zh-CN webpack-dev-server --progress --colors --hot --inline",
|
"dev:zh-CN": "npm run localize && npm run less && cross-env LOCALE=zh-CN webpack-dev-server --progress --colors --hot --inline",
|
||||||
|
"dev:ja-JP": "npm run localize && npm run less && cross-env LOCALE=ja-JP webpack-dev-server --progress --colors --hot --inline",
|
||||||
"latex": "node tools/mathjax",
|
"latex": "node tools/mathjax",
|
||||||
"less": "lessc stylesheets/style.less > stylesheets/style.css",
|
"less": "lessc stylesheets/style.less > stylesheets/style.css",
|
||||||
"singles": "npm run dev -- --singles",
|
"singles": "npm run dev -- --singles",
|
||||||
@@ -76,5 +76,8 @@
|
|||||||
"uglify-loader": "^1.3.0",
|
"uglify-loader": "^1.3.0",
|
||||||
"webpack": "^2.0.0",
|
"webpack": "^2.0.0",
|
||||||
"webpack-dev-server": "^2.0.0"
|
"webpack-dev-server": "^2.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"glob": "^7.1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user