mirror of
https://github.com/lutinglt/gitea-github-theme.git
synced 2025-12-21 14:16:28 +00:00
add translate
This commit is contained in:
14
.github/workflows/build.yml
vendored
14
.github/workflows/build.yml
vendored
@@ -28,8 +28,6 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
npm install
|
npm install
|
||||||
npm run build
|
npm run build
|
||||||
env:
|
|
||||||
GH_TOKEN: ${{ github.token }}
|
|
||||||
|
|
||||||
- name: Upload css assets
|
- name: Upload css assets
|
||||||
if: steps.build.outcome == 'success'
|
if: steps.build.outcome == 'success'
|
||||||
@@ -44,3 +42,15 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: templates
|
name: templates
|
||||||
path: templates
|
path: templates
|
||||||
|
|
||||||
|
- name: Build locales
|
||||||
|
id: locales
|
||||||
|
if: steps.build.outcome =='success'
|
||||||
|
run: npm run tr
|
||||||
|
|
||||||
|
- name: Upload locales assets
|
||||||
|
if: steps.locales.outcome =='success'
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: locales
|
||||||
|
path: dist/options/locale
|
||||||
7
.github/workflows/release.yml
vendored
7
.github/workflows/release.yml
vendored
@@ -14,7 +14,7 @@ jobs:
|
|||||||
- name: Build theme
|
- name: Build theme
|
||||||
run: |
|
run: |
|
||||||
npm install
|
npm install
|
||||||
npm run build
|
npm run release
|
||||||
- name: Create release
|
- name: Create release
|
||||||
run: |
|
run: |
|
||||||
tar -zcf dist/theme-github-base.tar.gz --remove-files \
|
tar -zcf dist/theme-github-base.tar.gz --remove-files \
|
||||||
@@ -29,8 +29,9 @@ jobs:
|
|||||||
tar -zcf dist/theme-github-extra-pink.tar.gz --remove-files \
|
tar -zcf dist/theme-github-extra-pink.tar.gz --remove-files \
|
||||||
dist/theme-github-pink-auto.css dist/theme-github-pink-light.css dist/theme-github-pink-dark.css dist/theme-github-pink-soft-dark.css
|
dist/theme-github-pink-auto.css dist/theme-github-pink-light.css dist/theme-github-pink-dark.css dist/theme-github-pink-soft-dark.css
|
||||||
|
|
||||||
tar -zcf dist/theme-github-templates.tar.gz templates options
|
tar -zcf dist/theme-github-templates.tar.gz templates
|
||||||
|
tar -zcf dist/theme-github-translations.tar.gz --remove-files dist/options
|
||||||
TAG="v$(npm run -s version)"
|
TAG="v$(npm run -s version)"
|
||||||
gh release create "$TAG" dist/* --notes-file CHANGELOG.md --draft -t $TAG
|
gh release create "$TAG" dist/*.tar.gz --notes-file CHANGELOG.md --draft -t $TAG
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ github.token }}
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gitea-github-theme",
|
"name": "gitea-github-theme",
|
||||||
"version": "1.25.3",
|
"version": "1.25.3.rc",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite build --mode dev",
|
"dev": "vite build --mode dev",
|
||||||
@@ -9,8 +9,9 @@
|
|||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"commit": "npm run lint && npm run format && npm run build",
|
"commit": "npm run lint && npm run format && npm run build",
|
||||||
"version": "node scripts/version.cjs",
|
"version": "node scripts/version.cjs",
|
||||||
"install:clean": "npm cache clean --force && rm -rf node_modules package-lock.json && npm install",
|
"tr": "node scripts/translate.cjs",
|
||||||
"tr": "node scripts/translate.ts"
|
"release": "npm run build && npm run tr",
|
||||||
|
"install:clean": "npm cache clean --force && rm -rf node_modules package-lock.json && npm install"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/preset-typescript": "^7.28.4",
|
"@babel/preset-typescript": "^7.28.4",
|
||||||
|
|||||||
56
scripts/translate.cjs
vendored
Normal file
56
scripts/translate.cjs
vendored
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
const child_process = require("child_process");
|
||||||
|
const dotenv = require("dotenv");
|
||||||
|
|
||||||
|
dotenv.config({ quiet: true });
|
||||||
|
const rootDir = path.join(__dirname, "..");
|
||||||
|
|
||||||
|
const pkgPath = path.join(rootDir, "package.json");
|
||||||
|
const pkg = JSON.parse(fs.readFileSync(pkgPath));
|
||||||
|
|
||||||
|
const githubSite = "https://raw.githubusercontent.com";
|
||||||
|
const giteaRepo = "go-gitea/gitea";
|
||||||
|
const githubBranchPath = "refs/heads/release";
|
||||||
|
const githubTagPath = "refs/tags";
|
||||||
|
const localePath = "options/locale";
|
||||||
|
|
||||||
|
const [major, minor, patch, tag = ""] = pkg.version.split(".");
|
||||||
|
|
||||||
|
console.log("Version: ", pkg.version);
|
||||||
|
let versionPath = "";
|
||||||
|
if (tag.includes("rc") || patch.includes("latest")) {
|
||||||
|
versionPath = `${githubBranchPath}/v${major}.${minor}`;
|
||||||
|
} else {
|
||||||
|
versionPath = `${githubTagPath}/v${major}.${minor}.${patch}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const githubUrl = `${githubSite}/${giteaRepo}/${versionPath}/${localePath}`;
|
||||||
|
|
||||||
|
const locales = fs.readdirSync(path.join(rootDir, localePath)).filter(file => file.endsWith(".ini"));
|
||||||
|
|
||||||
|
// 使用立即执行异步函数
|
||||||
|
(async () => {
|
||||||
|
for (const locale of locales) {
|
||||||
|
const localUrl = `${githubUrl}/${locale}`;
|
||||||
|
console.log("LocaleUrl: ", localUrl);
|
||||||
|
const themeLocale = fs.readFileSync(path.join(rootDir, localePath, locale), "utf-8");
|
||||||
|
|
||||||
|
const response = await fetch(localUrl);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
let content = await response.text();
|
||||||
|
if (locale.includes("zh-CN")) {
|
||||||
|
content = content.replaceAll("工单", "议题").replaceAll("合并请求", "拉取请求");
|
||||||
|
}
|
||||||
|
fs.mkdirSync(path.join(rootDir, "dist", localePath), { recursive: true });
|
||||||
|
fs.writeFileSync(path.join(rootDir, "dist", localePath, locale), content + themeLocale);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.SSH_SERVER && process.env.GITEA_PATH && process.env.SSH_USER) {
|
||||||
|
const cmd = `scp -r dist/options ${process.env.SSH_USER}@${process.env.SSH_SERVER}:${process.env.GITEA_PATH}`;
|
||||||
|
console.log("[translate] exec:", cmd);
|
||||||
|
child_process.execSync(cmd, { stdio: "inherit" });
|
||||||
|
}
|
||||||
|
})();
|
||||||
5
scripts/translate.ts
vendored
5
scripts/translate.ts
vendored
@@ -1,5 +0,0 @@
|
|||||||
import * as dotenv from "dotenv";
|
|
||||||
|
|
||||||
dotenv.config({ quiet: true });
|
|
||||||
//
|
|
||||||
console.log(process.env.GITEA_PATH);
|
|
||||||
Reference in New Issue
Block a user