2019-05-06 20:10:03 +10:00
|
|
|
const fs = require("fs")
|
2019-10-11 02:04:31 +11:00
|
|
|
let ver = "Usamin (18.11.1)"
|
2019-08-26 01:09:01 +10:00
|
|
|
const execSync = require('child_process').execSync;
|
|
|
|
let gitHash = execSync("git rev-parse HEAD").toString().trim()
|
|
|
|
fs.writeFileSync("../../git", gitHash)
|
|
|
|
if (process.argv.indexOf("--automatic") === -1) {
|
2019-09-13 00:35:13 +10:00
|
|
|
let input = require('readline-sync').question('version string [empty: ' + ver + ' (default)]? ');
|
2019-08-26 01:09:01 +10:00
|
|
|
if (input) {
|
|
|
|
ver = input
|
|
|
|
}
|
2019-06-05 00:01:04 +10:00
|
|
|
}
|
|
|
|
console.log("Constructing view files " + ver + ": make sure to update package.json")
|
2019-10-05 04:50:49 +10:00
|
|
|
const langs = ["ja", "en", "bg", "cs", "de", "es-AR", "ps"]
|
|
|
|
const langsh = ["日本語", "English", "български", "Česky", "Deutsch", "Spanish, Argentina", "Crowdin translate system(beta)"]
|
2019-05-19 17:39:30 +10:00
|
|
|
const simples = ["acct", "index", "setting", "update", "setting"]
|
|
|
|
const samples = ["acct.sample.html", "index.sample.html", "setting.sample.html", "update.sample.html", "setting.sample.js"]
|
|
|
|
const pages = ["acct.html", "index.html", "setting.html", "update.html", "setting.vue.js"]
|
|
|
|
let langstr = ""
|
2019-10-05 02:57:34 +10:00
|
|
|
let refKey = []
|
2019-05-19 17:39:30 +10:00
|
|
|
for (let n = 0; n < langs.length; n++) {
|
|
|
|
let lang = langs[n]
|
2019-09-01 01:02:34 +10:00
|
|
|
let targetDir = '../' + lang
|
|
|
|
if (!fs.existsSync(targetDir)) {
|
|
|
|
fs.mkdirSync(targetDir);
|
|
|
|
}
|
2019-10-05 04:50:49 +10:00
|
|
|
langstr = langstr + '<a onclick="changelang(\'' + lang + '\')" class="pointer" style="margin:4px;border: 1px solid var(--color); padding: 3px">' + langsh[n] + '</a>'
|
2019-10-05 01:07:15 +10:00
|
|
|
fs.writeFileSync("../" + lang + "/main.js", fs.readFileSync("language/" + lang + "/main.json", 'utf8').replace(/^{/, "var lang = {"))
|
2019-05-07 01:42:06 +10:00
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
for (let i = 0; i < samples.length; i++) {
|
|
|
|
let sample = samples[i]
|
2019-05-07 01:42:06 +10:00
|
|
|
let sourceParent = fs.readFileSync(sample, 'utf8')
|
2019-10-05 02:57:34 +10:00
|
|
|
let englishRefer = JSON.parse(fs.readFileSync("language/en/" + simples[i] + ".json", 'utf8'))
|
2019-05-19 17:39:30 +10:00
|
|
|
for (let j = 0; j < langs.length; j++) {
|
|
|
|
let source = sourceParent
|
|
|
|
let lang = langs[j]
|
2019-08-26 01:09:01 +10:00
|
|
|
let target = JSON.parse(fs.readFileSync("language/" + lang + "/" + simples[i] + ".json", 'utf8'))
|
2019-10-05 02:57:34 +10:00
|
|
|
if (lang == "ja") {
|
|
|
|
Object.keys(target).forEach(function (key) {
|
|
|
|
refKey.push(key)
|
|
|
|
let str = target[key]
|
2019-10-09 01:25:44 +11:00
|
|
|
if(pages[i]=="setting.vue.js"){
|
|
|
|
str = str.replace(/"/g, '\\"')
|
|
|
|
}
|
2019-10-05 02:57:34 +10:00
|
|
|
var regExp = new RegExp("@@" + key + "@@", "g")
|
|
|
|
source = source.replace(regExp, str)
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
for (let k = 0; k < refKey.length; k++) {
|
|
|
|
let tarKey = refKey[k]
|
|
|
|
if (target[tarKey]) {
|
|
|
|
var str = target[tarKey]
|
|
|
|
} else {
|
|
|
|
var str = englishRefer[tarKey]
|
|
|
|
}
|
|
|
|
var regExp = new RegExp("@@" + tarKey + "@@", "g")
|
|
|
|
source = source.replace(regExp, str)
|
|
|
|
}
|
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
if (lang == "ps") {
|
2019-05-06 20:10:03 +10:00
|
|
|
source = source.replace(/@@comment-start@@/g, "")
|
|
|
|
source = source.replace(/@@comment-end@@/g, "")
|
2019-05-19 17:39:30 +10:00
|
|
|
} else {
|
2019-05-06 20:10:03 +10:00
|
|
|
source = source.replace(/@@comment-start@@/g, "<!--")
|
|
|
|
source = source.replace(/@@comment-end@@/g, "-->")
|
|
|
|
}
|
|
|
|
source = source.replace(/@@versionLetter@@/g, ver)
|
2019-08-26 01:09:01 +10:00
|
|
|
source = source.replace(/@@gitHash@@/g, gitHash)
|
2019-08-26 22:06:07 +10:00
|
|
|
source = source.replace(/@@gitHashShort@@/g, gitHash.slice(0, 7))
|
2019-05-06 20:10:03 +10:00
|
|
|
source = source.replace(/@@lang@@/g, lang)
|
2019-05-07 01:42:06 +10:00
|
|
|
source = source.replace(/@@langlist@@/g, langstr)
|
2019-05-19 17:39:30 +10:00
|
|
|
fs.writeFileSync("../" + lang + "/" + pages[i], source)
|
2019-05-06 20:10:03 +10:00
|
|
|
}
|
|
|
|
}
|