mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-11-21 05:53:11 -05:00
Use a postinstall script to generate translation list
This commit is contained in:
parent
61708857af
commit
951ae955ed
@ -5,8 +5,9 @@ WORKDIR /app
|
|||||||
RUN apt update && apt install -y nodejs && rm /usr/local/bun-node-fallback-bin/node
|
RUN apt update && apt install -y nodejs && rm /usr/local/bun-node-fallback-bin/node
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
COPY package.json bun.lock scripts .
|
COPY package.json bun.lock .
|
||||||
COPY scripts scripts
|
COPY scripts scripts
|
||||||
|
COPY public public
|
||||||
RUN bun install --production
|
RUN bun install --production
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|||||||
@ -3,6 +3,7 @@ WORKDIR /app
|
|||||||
|
|
||||||
COPY package.json bun.lock .
|
COPY package.json bun.lock .
|
||||||
COPY scripts scripts
|
COPY scripts scripts
|
||||||
|
COPY public public
|
||||||
RUN bun install --frozen-lockfile
|
RUN bun install --frozen-lockfile
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
{
|
{
|
||||||
"extends": "//",
|
"extends": "//",
|
||||||
"files": {
|
"files": {
|
||||||
"includes": ["src/**"]
|
"includes": [
|
||||||
|
"src/**",
|
||||||
|
"scripts/**"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { readdir , mkdir } from 'node:fs/promises';
|
import { mkdir, readdir } from "node:fs/promises";
|
||||||
|
|
||||||
|
async function jassub() {
|
||||||
const srcDir = new URL("../node_modules/jassub/dist/", import.meta.url);
|
const srcDir = new URL("../node_modules/jassub/dist/", import.meta.url);
|
||||||
const destDir = new URL("../public/jassub/", import.meta.url);
|
const destDir = new URL("../public/jassub/", import.meta.url);
|
||||||
|
|
||||||
@ -10,3 +11,45 @@ for (const file of files) {
|
|||||||
const src = await Bun.file(new URL(file, srcDir)).arrayBuffer();
|
const src = await Bun.file(new URL(file, srcDir)).arrayBuffer();
|
||||||
await Bun.write(new URL(file, destDir), src);
|
await Bun.write(new URL(file, destDir), src);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function translations() {
|
||||||
|
const srcDir = new URL("../public/translations/", import.meta.url);
|
||||||
|
const dest = new URL(
|
||||||
|
"../src/providers/translations.compile.ts",
|
||||||
|
import.meta.url,
|
||||||
|
);
|
||||||
|
|
||||||
|
const translations = (await readdir(srcDir))
|
||||||
|
.map((x) => ({
|
||||||
|
file: x,
|
||||||
|
lang: x.replace(".json", ""),
|
||||||
|
var: x.replace(".json", "").replace("-", "_"),
|
||||||
|
}))
|
||||||
|
.map((x) => ({
|
||||||
|
...x,
|
||||||
|
quotedLang: x.lang.includes("-") ? `"${x.lang}"` : x.lang,
|
||||||
|
}))
|
||||||
|
.sort((a, b) => a.lang.localeCompare(b.lang));
|
||||||
|
await Bun.write(
|
||||||
|
dest,
|
||||||
|
`// this file is auto-generated via a postinstall script.
|
||||||
|
|
||||||
|
${translations
|
||||||
|
.map((x) => `import ${x.var} from "../../public/translations/${x.file}";`)
|
||||||
|
.join("\n")}
|
||||||
|
|
||||||
|
export const resources = {
|
||||||
|
${translations
|
||||||
|
.map((x) => `${x.quotedLang}: { translation: ${x.var} },`)
|
||||||
|
.join("\n\t")}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const supportedLanguages = [
|
||||||
|
${translations.map((x) => `"${x.lang}",`).join("\n\t")}
|
||||||
|
];`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await jassub();
|
||||||
|
await translations();
|
||||||
|
|||||||
@ -1,22 +1,71 @@
|
|||||||
// this file is run at compile time thanks to a vite plugin
|
// this file is auto-generated via a postinstall script.
|
||||||
|
|
||||||
// import { readFile, readdir } from "node:fs/promises";
|
|
||||||
// import type { Resource } from "i18next";
|
|
||||||
|
|
||||||
// const translationDir = new URL("../../public/translations/", import.meta.url);
|
|
||||||
// const langs = await readdir(translationDir);
|
|
||||||
|
|
||||||
// export const resources: Resource = Object.fromEntries(
|
|
||||||
// await Promise.all(
|
|
||||||
// langs.map(async (x) => [
|
|
||||||
// x.replace(".json", ""),
|
|
||||||
// { translation: JSON.parse(await readFile(new URL(x, translationDir), "utf8")) },
|
|
||||||
// ]),
|
|
||||||
// ),
|
|
||||||
// );
|
|
||||||
|
|
||||||
|
import am from "../../public/translations/am.json";
|
||||||
|
import ar from "../../public/translations/ar.json";
|
||||||
|
import de from "../../public/translations/de.json";
|
||||||
import en from "../../public/translations/en.json";
|
import en from "../../public/translations/en.json";
|
||||||
|
import es from "../../public/translations/es.json";
|
||||||
|
import fr from "../../public/translations/fr.json";
|
||||||
|
import gl from "../../public/translations/gl.json";
|
||||||
|
import is from "../../public/translations/is.json";
|
||||||
|
import it from "../../public/translations/it.json";
|
||||||
|
import ko from "../../public/translations/ko.json";
|
||||||
|
import ml from "../../public/translations/ml.json";
|
||||||
|
import nl from "../../public/translations/nl.json";
|
||||||
|
import pl from "../../public/translations/pl.json";
|
||||||
|
import pt from "../../public/translations/pt.json";
|
||||||
|
import pt_BR from "../../public/translations/pt-BR.json";
|
||||||
|
import ro from "../../public/translations/ro.json";
|
||||||
|
import ru from "../../public/translations/ru.json";
|
||||||
|
import ta from "../../public/translations/ta.json";
|
||||||
|
import tr from "../../public/translations/tr.json";
|
||||||
|
import uk from "../../public/translations/uk.json";
|
||||||
|
import zh from "../../public/translations/zh.json";
|
||||||
|
|
||||||
export const resources = { en };
|
export const resources = {
|
||||||
|
am: { translation: am },
|
||||||
|
ar: { translation: ar },
|
||||||
|
de: { translation: de },
|
||||||
|
en: { translation: en },
|
||||||
|
es: { translation: es },
|
||||||
|
fr: { translation: fr },
|
||||||
|
gl: { translation: gl },
|
||||||
|
is: { translation: is },
|
||||||
|
it: { translation: it },
|
||||||
|
ko: { translation: ko },
|
||||||
|
ml: { translation: ml },
|
||||||
|
nl: { translation: nl },
|
||||||
|
pl: { translation: pl },
|
||||||
|
pt: { translation: pt },
|
||||||
|
"pt-BR": { translation: pt_BR },
|
||||||
|
ro: { translation: ro },
|
||||||
|
ru: { translation: ru },
|
||||||
|
ta: { translation: ta },
|
||||||
|
tr: { translation: tr },
|
||||||
|
uk: { translation: uk },
|
||||||
|
zh: { translation: zh },
|
||||||
|
};
|
||||||
|
|
||||||
export const supportedLanguages = Object.keys(resources);
|
export const supportedLanguages = [
|
||||||
|
"am",
|
||||||
|
"ar",
|
||||||
|
"de",
|
||||||
|
"en",
|
||||||
|
"es",
|
||||||
|
"fr",
|
||||||
|
"gl",
|
||||||
|
"is",
|
||||||
|
"it",
|
||||||
|
"ko",
|
||||||
|
"ml",
|
||||||
|
"nl",
|
||||||
|
"pl",
|
||||||
|
"pt",
|
||||||
|
"pt-BR",
|
||||||
|
"ro",
|
||||||
|
"ru",
|
||||||
|
"ta",
|
||||||
|
"tr",
|
||||||
|
"uk",
|
||||||
|
"zh",
|
||||||
|
];
|
||||||
Loading…
x
Reference in New Issue
Block a user