Skip to content

Commit 460088a

Browse files
committed
✨ 添加i18n所见即所得模式
1 parent aabc959 commit 460088a

File tree

11 files changed

+139
-1
lines changed

11 files changed

+139
-1
lines changed

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ npm start
7979
- `src/locales`[扩展](https://github.com/scriptscat/scriptcat)翻译文件目录
8080
- `public/locales`[脚本站](https://github.com/scriptscat/scriptlist-frontend)的翻译文件目录
8181

82+
#### 扩展开启所见即所得模式
83+
84+
扩展开启所见即所得模式需要使用`npm run i18n`模式进行构建,然后通过控制台设置伪语言`localStorage['language']='ach-UG';`,然后刷新页面。
85+
86+
#### 脚本站开启所见即所得模式
87+
88+
脚本站访问:[https://scriptcat.org/ach-UG](https://scriptcat.org/ach-UG) 即可开启所见即所得模式
89+
8290
## 参与开发
8391

8492
ScriptCat 使用 ESLint 来规范代码风格,使用 Jest

build/assets/_locales/i18n.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// eslint-disable-next-line no-underscore-dangle, no-var
2+
var _jipt = [];
3+
_jipt.push(["project", "scriptcat"]);

build/assets/template/confirm.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,11 @@
2121
color: var(--color-text-1);
2222
}
2323
</style>
24+
<% if (htmlWebpackPlugin.options.mode === 'i18n') { %>
25+
<script type="text/javascript" src="/_locales/i18n.js"></script>
26+
<script
27+
type="text/javascript"
28+
src="https://cdn.crowdin.com/jipt/jipt.js"
29+
></script>
30+
<% } %>
2431
</html>

build/assets/template/import.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,11 @@
2121
color: var(--color-text-1);
2222
}
2323
</style>
24+
<% if (htmlWebpackPlugin.options.mode === 'i18n') { %>
25+
<script type="text/javascript" src="/_locales/i18n.js"></script>
26+
<script
27+
type="text/javascript"
28+
src="https://cdn.crowdin.com/jipt/jipt.js"
29+
></script>
30+
<% } %>
2431
</html>

build/assets/template/install.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,11 @@
2121
color: var(--color-text-1);
2222
}
2323
</style>
24+
<% if (htmlWebpackPlugin.options.mode === 'i18n') { %>
25+
<script type="text/javascript" src="/_locales/i18n.js"></script>
26+
<script
27+
type="text/javascript"
28+
src="https://cdn.crowdin.com/jipt/jipt.js"
29+
></script>
30+
<% } %>
2431
</html>

build/assets/template/options.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,11 @@
2222
color: var(--color-text-1);
2323
}
2424
</style>
25+
<% if (htmlWebpackPlugin.options.mode === 'i18n') { %>
26+
<script type="text/javascript" src="/_locales/i18n.js"></script>
27+
<script
28+
type="text/javascript"
29+
src="https://cdn.crowdin.com/jipt/jipt.js"
30+
></script>
31+
<% } %>
2532
</html>

build/assets/template/popup.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,11 @@
2626
/* overflow: hidden; */
2727
}
2828
</style>
29+
<% if (htmlWebpackPlugin.options.mode === 'i18n') { %>
30+
<script type="text/javascript" src="/_locales/i18n.js"></script>
31+
<script
32+
type="text/javascript"
33+
src="https://cdn.crowdin.com/jipt/jipt.js"
34+
></script>
35+
<% } %>
2936
</html>

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"dev:linter": "webpack --mode development --config ./webpack/webpack.linter.dev.ts",
1616
"pack": "node ./build/pack.js",
1717
"changlog": "gitmoji-changelog",
18-
"crowdin": "crowdin"
18+
"crowdin": "crowdin",
19+
"i18n": "concurrently \"webpack --mode development --config ./webpack/webpack.i18n.ts\" \"webpack --mode development --config ./webpack/webpack.inject.dev.ts\""
1920
},
2021
"dependencies": {
2122
"@arco-design/web-react": "^2.51.1",

src/locales/locales.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Metadata } from "@App/app/repo/scripts";
66
import enUS from "./en/translation.json";
77
import zhCN from "./zh-CN/translation.json";
88
import zhTW from "./zh-TW/translation.json";
9+
import achUG from "./ach-UG/translation.json";
910
import "dayjs/locale/zh-cn";
1011

1112
i18n.use(initReactI18next).init({
@@ -18,6 +19,7 @@ i18n.use(initReactI18next).init({
1819
"en-US": { title: "English", translation: enUS },
1920
"zh-CN": { title: "简体中文", translation: zhCN },
2021
"zh-TW": { title: "繁体中文", translation: zhTW },
22+
"ach-UG": { title: "伪语言", translation: achUG },
2123
},
2224
});
2325

src/pages/options/routes/Setting.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ function Setting() {
4242
const languageList: { key: string; title: string }[] = [];
4343
const { t } = useTranslation();
4444
Object.keys(i18n.store.data).forEach((key) => {
45+
if (key === "ach-UG") {
46+
return;
47+
}
4548
languageList.push({
4649
key,
4750
title: i18n.store.data[key].title as string,

0 commit comments

Comments
 (0)