Skip to content

Commit

Permalink
improved the addition of i18n phrase
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyhalight committed Jan 23, 2024
1 parent a3005ca commit a0b04cd
Showing 1 changed file with 24 additions and 41 deletions.
65 changes: 24 additions & 41 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@ const repo =
const dev = process.env.NODE_ENV === "development";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
let isBeta = getHeaders("headers.json").version.includes("beta");
let isBeta = getHeaders().version.includes("beta");

console.log("development mode: ", dev);

function getHeaders(file) {
const headersPath = path.resolve(__dirname, "src", file);
function getHeaders(lang) {
const headersPath = path.resolve(
__dirname,
"src",
lang ? `locales/${lang}` : "",
"headers.json",
);
return JSON.parse(fs.readFileSync(headersPath).toString());
}

const ru_headers = getHeaders("locales/ru/headers.json");
const zh_headers = getHeaders("locales/zh/headers.json");
const de_headers = getHeaders("locales/de/headers.json");
const es_headers = getHeaders("locales/es/headers.json");
const fr_headers = getHeaders("locales/fr/headers.json");
const it_headers = getHeaders("locales/it/headers.json");

export default (env) => {
const build_mode = env.build_mode;
const build_type = env.build_type;
Expand Down Expand Up @@ -101,7 +99,7 @@ export default (env) => {
}),
new UserscriptPlugin({
headers: async () => {
const headers = getHeaders("headers.json");
const headers = getHeaders();

let version = headers.version;

Expand Down Expand Up @@ -130,36 +128,21 @@ export default (env) => {
baseURL: "http://localhost:11945/",
},
i18n: {
ru: (headers) => ({
...headers,
name: get_name_by_build_mode(ru_headers["name"]),
description: ru_headers["description"],
}),
zh: (headers) => ({
...headers,
name: get_name_by_build_mode(zh_headers["name"]),
description: zh_headers["description"],
}),
de: (headers) => ({
...headers,
name: get_name_by_build_mode(de_headers["name"]),
description: de_headers["description"],
}),
es: (headers) => ({
...headers,
name: get_name_by_build_mode(es_headers["name"]),
description: es_headers["description"],
}),
fr: (headers) => ({
...headers,
name: get_name_by_build_mode(fr_headers["name"]),
description: fr_headers["description"],
}),
it: (headers) => ({
...headers,
name: get_name_by_build_mode(it_headers["name"]),
description: it_headers["description"],
}),
...(() => {
const files = fs.readdirSync(
path.resolve(__dirname, "src", "locales"),
);
const localedHeaders = {};
for (const file of files) {
const localeHeaders = getHeaders(file);
localedHeaders[file.substring(0, 2)] = {
name: get_name_by_build_mode(localeHeaders.name),
description: localeHeaders.description,
};
}

return localedHeaders;
})(),
},
strict: true,
}),
Expand Down

0 comments on commit a0b04cd

Please sign in to comment.