forked from L1Z0/NoN-Translations
make.ts: split meme/nomeme, add KEEP_SAME_OVERRIDE_LINES env for disable merge same key feature
This commit is contained in:
@@ -9,6 +9,8 @@ const targetLangFiles: LanguageInstance[] = [
|
|||||||
{suffix: "en_us_nsfw", file: "NSFW (Default Pack)/en_us.json", overrideSuffix: "en_us_sfw", ro: true},
|
{suffix: "en_us_nsfw", file: "NSFW (Default Pack)/en_us.json", overrideSuffix: "en_us_sfw", ro: true},
|
||||||
{suffix: "en_us_sfw", file: "SFW (baked in NoN)/en_us.json", ro: true},
|
{suffix: "en_us_sfw", file: "SFW (baked in NoN)/en_us.json", ro: true},
|
||||||
{suffix: "zh_cn_nsfw", file: "NSFW (Default Pack)/zh_cn.json", overrideSuffix: "zh_cn_sfw"},
|
{suffix: "zh_cn_nsfw", file: "NSFW (Default Pack)/zh_cn.json", overrideSuffix: "zh_cn_sfw"},
|
||||||
|
{suffix: "zh_cn_nsfw_nomeme", file: "zh_cn_nomeme.json", overrideSuffix: "zh_cn_nsfw_nomeme"},
|
||||||
|
{suffix: "zh_cn_nsfw_meme", file: "zh_cn_meme.json", overrideSuffix: "zh_cn_nsfw_meme"},
|
||||||
{suffix: "zh_cn_sfw", file: "SFW (baked in NoN)/zh_cn.json"}
|
{suffix: "zh_cn_sfw", file: "SFW (baked in NoN)/zh_cn.json"}
|
||||||
]
|
]
|
||||||
const workFile = "zh_cn.json"
|
const workFile = "zh_cn.json"
|
||||||
@@ -17,6 +19,7 @@ type LanguageInstance = {
|
|||||||
suffix: string,
|
suffix: string,
|
||||||
file: string,
|
file: string,
|
||||||
data?: Record<string, string>,
|
data?: Record<string, string>,
|
||||||
|
outputBuffer?: KVPair[];
|
||||||
overrideSuffix?: string,
|
overrideSuffix?: string,
|
||||||
override?: LanguageInstance,
|
override?: LanguageInstance,
|
||||||
ro?: boolean // read only, don't edit.
|
ro?: boolean // read only, don't edit.
|
||||||
@@ -24,6 +27,8 @@ type LanguageInstance = {
|
|||||||
|
|
||||||
const mainLangFile = "SFW (baked in NoN)/en_us.json";
|
const mainLangFile = "SFW (baked in NoN)/en_us.json";
|
||||||
|
|
||||||
|
const KEEP_SAME_OVERRIDE_LINES = !(process.env.KEEP_SAME_OVERRIDE_LINES ?? "").match(/^(0|false)$/i)
|
||||||
|
|
||||||
const targetLangFilesBySuffix: Record<string, LanguageInstance> = {}
|
const targetLangFilesBySuffix: Record<string, LanguageInstance> = {}
|
||||||
for (let l of targetLangFiles) {
|
for (let l of targetLangFiles) {
|
||||||
if (!l.suffix.match(/^[a-z0-9-_]+$/i)) throw new Error(`bad Suffix: ${JSON.stringify(l.suffix)} that not match ^[a-z0-9-_]+$ (ignore case)`)
|
if (!l.suffix.match(/^[a-z0-9-_]+$/i)) throw new Error(`bad Suffix: ${JSON.stringify(l.suffix)} that not match ^[a-z0-9-_]+$ (ignore case)`)
|
||||||
@@ -66,6 +71,7 @@ function genMergedLang(): void {
|
|||||||
for (let l of targetLangFiles) {
|
for (let l of targetLangFiles) {
|
||||||
let value = l.data?.[key];
|
let value = l.data?.[key];
|
||||||
if (l.override?.data?.[key] === value) value = undefined
|
if (l.override?.data?.[key] === value) value = undefined
|
||||||
|
if (typeof value === "undefined" && KEEP_SAME_OVERRIDE_LINES) value = l.override?.data?.[key]
|
||||||
if (value) output.push([`${key}.${l.suffix}`, value])
|
if (value) output.push([`${key}.${l.suffix}`, value])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,21 +79,22 @@ function genMergedLang(): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function writeBackLang() {
|
function writeBackLang() {
|
||||||
let mixed = parseOrdered(fs.readFileSync(workFile, "utf-8"));
|
const mergedKeys: Record<string, string> = JSON.parse(fs.readFileSync(workFile, "utf-8"));
|
||||||
const buffer: Record<string, KVPair[]> = {}
|
for (let l of targetLangFiles) {
|
||||||
for (const key of Object.keys(targetLangFilesBySuffix)) buffer[key] = []
|
l.outputBuffer = []
|
||||||
|
}
|
||||||
for (const [k, v] of mixed) {
|
for (let key of keyOrder) {
|
||||||
const [key, suffix] = k.split(/\.(?=[^.]*$)/);
|
for (let l of targetLangFiles) {
|
||||||
if (!buffer[suffix]) throw new Error(`can't parse the suffix: ${JSON.stringify(suffix)} from key: ${JSON.stringify(k)}`)
|
let s = mergedKeys[`${key}.${l.suffix}`]
|
||||||
buffer[suffix].push([key, v])
|
if (typeof s !== "string" && KEEP_SAME_OVERRIDE_LINES && l.override?.suffix) s = mergedKeys[`${key}.${l.override.suffix}`]
|
||||||
|
if (typeof s === "string") l.outputBuffer?.push([key, s])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let suffix in buffer) {
|
for (let l of targetLangFiles) {
|
||||||
if (targetLangFilesBySuffix[suffix].ro) continue
|
if (l.ro || !l.outputBuffer) continue
|
||||||
fs.writeFileSync(targetLangFilesBySuffix[suffix].file, stringify(buffer[suffix]))
|
fs.writeFileSync(l.file, stringify(l.outputBuffer))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
;(() => {
|
;(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user