-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
1,502 additions
and
3,840 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
Checks: '-*, | ||
modernize-*, | ||
-modernize-use-trailing-return-type, | ||
-modernize-use-nodiscard' | ||
modernize-*, | ||
-modernize-use-trailing-return-type, | ||
-modernize-use-nodiscard, | ||
performance-*, | ||
-performance-avoid-endl, | ||
readability-*, | ||
-readability-identifier-length, | ||
-readability-implicit-bool-conversion, | ||
-readability-braces-around-statements, | ||
-readability-magic-numbers, | ||
-readability-avoid-nested-conditional-operator, | ||
-readability-use-anyofallof' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,42 @@ | ||
const gulp = require("gulp"); | ||
const through2 = require("gulp-through2"); | ||
|
||
const newer = require("../utils/newer"); | ||
const config = require("../config.json"); | ||
const order = require("../plugins/order"); | ||
|
||
function compile(t) { | ||
if(t.includes("{")) { | ||
t = t.replace(/\{(\d+)\}/g, "\",i(l($1)),\""); | ||
return "({normalize:n,interpolate:i,list:l})=>n([\"" + t + "\"])"; | ||
} | ||
return `_=>"${t}"`; | ||
// For sorting the locale file entries to the same ordering as the source locale | ||
|
||
function copyInOrderOf(source, order) { | ||
if(typeof source != "object" || Array.isArray(source)) return source; | ||
const result = {}; | ||
for(const key in order) result[key] = copyInOrderOf(source[key], order[key]); | ||
return result; | ||
} | ||
|
||
function order(sourceName) { | ||
let source; | ||
return through2({ | ||
name: "locale-order", | ||
filter: ".json", | ||
transform(_, file) { | ||
if(file.basename == sourceName) { | ||
source = file; | ||
return null; | ||
} | ||
}, | ||
flush(files) { | ||
if(!source) return; | ||
this.push(source); | ||
source = JSON.parse(through2.read(source)); | ||
for(const file of files) { | ||
const json = JSON.parse(through2.read(file)); | ||
const result = JSON.stringify(copyInOrderOf(json, source), null, "\t") + "\n"; | ||
through2.write(file, result); | ||
} | ||
}, | ||
}); | ||
}; | ||
|
||
gulp.task("locale", () => gulp.src(config.src.locale + "/*.json") | ||
.pipe(newer({ | ||
dest: config.src.app + "/gen/locale.ts", | ||
extra: [__filename, "../plugins/order.js"], | ||
})) | ||
.pipe(order("en.json")) | ||
.pipe(gulp.dest(config.src.locale)) | ||
.pipe(through2({ | ||
transform: (content, file) => `"${file.stem.toLowerCase()}": ${content},`, | ||
flush(files) { | ||
let content = files | ||
.map(f => through2.read(f)) | ||
.join("\n") | ||
.replace(/"((?:[^"\\]|\\.)+)"(.)/gs, ($0, $1, $2) => { | ||
if($2 == "]" || $2 == ":") return $0; | ||
return compile($1) + $2; | ||
}); | ||
content = `import type { BpsLocale } from "shared/frontend/locale";\n\nexport default {${content}} as Record<string, BpsLocale>;`; | ||
through2.write(files[0], content); | ||
files[0].basename = "locale.ts"; | ||
return [files[0]]; | ||
}, | ||
})) | ||
.pipe(gulp.dest(config.src.app + "/gen"))); | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
function compile(t) { | ||
if(t.includes("{")) { | ||
t = t.replace(/\{(\d+)\}/g, "\",i(l($1)),\""); | ||
return "({normalize:n,interpolate:i,list:l})=>n([\"" + t + "\"])"; | ||
} | ||
return `_=>"${t}"`; | ||
} | ||
|
||
/** | ||
* Locale loader | ||
* @type {import("@rspack/core").LoaderDefinitionFunction} | ||
*/ | ||
export default function(content, map, meta) { | ||
return "export default " + content.replace(/"((?:[^"\\]|\\.)+)"(.)/gs, ($0, $1, $2) => { | ||
if($2 == "]" || $2 == ":") return $0; | ||
return compile($1) + $2; | ||
}); | ||
}; |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.