Skip to content

Commit 0dd605e

Browse files
author
blucas.wu
committed
Merge branch 'main' into docs
2 parents 654040c + a9f0216 commit 0dd605e

File tree

25 files changed

+710
-140
lines changed

25 files changed

+710
-140
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"devDependencies": {
1919
"@babel/eslint-parser": "^7.19.1",
20-
"@huolala-tech/page-spy": "^1.3.0",
20+
"@huolala-tech/page-spy": "^1.3.1",
2121
"@mdx-js/rollup": "^2.3.0",
2222
"@types/lodash-es": "^4.17.7",
2323
"@types/mdx": "^2.0.4",
@@ -72,7 +72,7 @@
7272
"zustand": "^4.3.7"
7373
},
7474
"gitHooks": {
75-
"pre-commit": "lint-staged"
75+
"pre-commit": "lint-staged && node ./scripts/check-i18n.mjs"
7676
},
7777
"lint-staged": {
7878
"*.{js,jsx,less,md,json}": [

scripts/check-i18n.mjs

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* eslint-disable */
2+
import fs from 'node:fs';
3+
import { resolve, join } from 'node:path';
4+
import _ from 'lodash-es';
5+
6+
console.log('\n| Start checking i18n ...\n');
7+
8+
class FileNotFound extends Error {
9+
name = 'FileNotFound';
10+
}
11+
12+
const directory = resolve(process.cwd(), './src/assets/locales');
13+
14+
function flattenObject(obj, parentKey = '') {
15+
return _.transform(
16+
obj,
17+
(result, value, key) => {
18+
const newKey = parentKey ? `${parentKey}.${key}` : key;
19+
20+
if (_.isObject(value)) {
21+
_.assign(result, flattenObject(value, newKey));
22+
} else {
23+
result[newKey] = value;
24+
}
25+
},
26+
{},
27+
);
28+
}
29+
30+
fs.readdir(directory, (err, files) => {
31+
if (err) {
32+
throw new FileNotFound('The `/src/assets/locales` directory is not found');
33+
}
34+
35+
const locales = files
36+
.filter((i) => i.endsWith('.json'))
37+
.map((i) => {
38+
const file = join(directory, i);
39+
const content = JSON.parse(fs.readFileSync(file, 'utf-8'));
40+
const keys = _.keys(flattenObject(content));
41+
return {
42+
filename: file,
43+
keys,
44+
};
45+
});
46+
47+
const unionKeys = _.union(...locales.map((i) => i.keys));
48+
49+
for (let i = 0; i < locales.length; i++) {
50+
const diff = _.difference(unionKeys, locales[i].keys);
51+
if (diff.length) {
52+
console.error(
53+
`The "${diff.join(' / ')}" in the ${locales[i].filename} is not ready.`,
54+
);
55+
process.exit(1);
56+
}
57+
}
58+
process.exit(0);
59+
});

scripts/mv-sdk.js

-32
This file was deleted.

src/assets/image/device.svg

+6
Loading

src/assets/image/i18n.svg

+4-1
Loading

src/assets/locales/en.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,20 @@
8989
"fix-suggestion-2": "2. Troubleshoot network issues: If there are access restrictions on the server where your source files are located, it may lead to failed requests when trying to access the resources. You can open the devtool to check if the network is working properly."
9090
}
9191
},
92-
"network": {},
92+
"network": {
93+
"open-in-new-tab": "Open in new tab",
94+
"copy-link-address": "Copy link address",
95+
"copy-as-curl": "Copy as cURL"
96+
},
9397
"system": {
9498
"overview": "Overview",
9599
"feature": "Feature",
96100
"unsupport": "Unsupport list",
97101
"reference": "See detection rule"
98102
},
99103
"page": {
100-
"element": "Element"
104+
"element": "Element",
105+
"device": "Device"
101106
},
102107
"storage": {
103108
"empty-detail": "Select one to preview its value"

src/assets/locales/index.ts

+24-16
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
1-
import en from './en.json';
2-
import zh from './zh.json';
1+
// import zh from './zh.json';
2+
// import en from './en.json';
3+
// import ja from './ja.json';
4+
// import ko from './ko.json';
35
import { initReactI18next } from 'react-i18next';
4-
import i18next from 'i18next';
6+
import i18next, { InitOptions } from 'i18next';
57
import languageDetector from 'i18next-browser-languagedetector';
68

9+
const data = import.meta.glob('./*.json', { eager: true }) as Record<
10+
string,
11+
object
12+
>;
13+
14+
const resources = Object.entries(data).reduce((acc, cur) => {
15+
const [key, value] = cur;
16+
const result = key.match(/^\.\/(.*)\.json$/);
17+
if (!result) return acc;
18+
acc[result[1]] = {
19+
translation: {
20+
...value,
21+
},
22+
};
23+
return acc;
24+
}, {} as NonNullable<InitOptions['resources']>);
25+
726
i18next
827
.use(initReactI18next)
928
.use(languageDetector)
1029
.init({
11-
resources: {
12-
en: {
13-
translation: {
14-
...en,
15-
},
16-
},
17-
zh: {
18-
translation: {
19-
...zh,
20-
},
21-
},
22-
},
30+
resources,
2331
fallbackLng: 'en',
2432
interpolation: {
2533
escapeValue: false,
2634
},
2735
});
2836

2937
export const getTranslation = (key: string) => {
30-
const lang = i18next.resolvedLanguage;
38+
const lang = i18next.resolvedLanguage || 'zh';
3139
const res = i18next.getResource(lang, 'translation', key);
3240
return res || key;
3341
};

src/assets/locales/ja.json

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
{
2+
"common": {
3+
"cancel": "キャンセル",
4+
"OK": "OK",
5+
"clear": "クリア",
6+
"refresh": "リフレッシュ",
7+
"lang": "日本語",
8+
"doc": "ドキュメント",
9+
"connections": "接続",
10+
"inject-sdk": "SDKを注入",
11+
"submit": "送信",
12+
"reset": "リセット",
13+
"device-id": "デバイスID",
14+
"os": "オペレーティング システム",
15+
"browser": "ブラウザ",
16+
"project": "プロジェクト",
17+
"debug": "デバッグ"
18+
},
19+
"error": {
20+
"oops": "おっと!エラーが発生しました。",
21+
"actions": "<1>リフレッシュ</1>するか、<3><0>報告</0></3>してください。",
22+
"try-again": "リフレッシュ",
23+
"report": "報告"
24+
},
25+
"inject": {
26+
"load-script": "テストプロジェクトに <script> を読み込む;",
27+
"init-instance": "次に、(オプションで)構成して初期化します;",
28+
"pass-config": "設定を渡すこともでき、これによりデフォルトの値が上書きされます;",
29+
"end": "以上がすべてです。",
30+
"start-debug": "<1>接続</1>メニューからトップに移動し、デバッグを開始します!"
31+
},
32+
"banner": {
33+
"title": "多機能<br />リモートデバッグツール",
34+
"desc": "Google Chromeのコンソールのように簡単にリモートデバッグを開始します。",
35+
"goStart": "デバッグを開始",
36+
"goGithub": "Github リポジトリ"
37+
},
38+
"intro": {
39+
"does": "PageSpyでできること",
40+
"doesTitle": "ランタイムの検出、<br />リモート操作!",
41+
"provides": "提供するもの",
42+
"providesTitle": "使用準備の整った <1>SDK</1> および<br /> <4>クライアントデバッグ</4>",
43+
"welcome": "PageSpyへようこそ",
44+
"goStart": "開始"
45+
},
46+
"selConn": {
47+
"title": "接続を選択",
48+
"label": "接続",
49+
"placeholder": "接続を選択"
50+
},
51+
"devtool": {
52+
"device": "デバイス",
53+
"system": "システム",
54+
"browser": "ブラウザ",
55+
"version": "バージョン",
56+
"menu": {
57+
"Console": "コンソール",
58+
"Network": "ネットワーク",
59+
"System": "システム",
60+
"Page": "ページ",
61+
"Storage": "ストレージ"
62+
}
63+
},
64+
"shortcuts": {
65+
"title": "ショートカット",
66+
"enter": "コードを実行",
67+
"tab": "タブを挿入(2スペース)",
68+
"shift+enter": "改行",
69+
"cmd+k": "パネルをクリア",
70+
"ctrl+l": "パネルをクリア",
71+
"updown": "入力履歴を切り替え"
72+
},
73+
"console": {
74+
"run": "実行",
75+
"placeholder": "実行可能なコード",
76+
"newContent": "新しいメッセージ",
77+
"error-trace": {
78+
"title": "エラーの詳細",
79+
"hints": "使用のヒント",
80+
"message-title": "エラーメッセージ",
81+
"stack-title": "エラースタック",
82+
"source-filename": "ソースファイル",
83+
"fetch-minify-fail": "ソースファイルの取得に失敗",
84+
"none-sourcemap": "ソースマップが見つかりません",
85+
"fetch-sourcemap-fail": "ソースマップの取得に失敗",
86+
"failed-title": "ソースコードの特定中に問題が発生しました",
87+
"failed-advice": "以下は修正と改善の提案です:",
88+
"fix-suggestion-1": "<0>1. ファイルの存在を確認:各エラースタックでソースコードを特定するためには、2つのファイル(圧縮ファイルとソースマップファイル)が要求されます。ソースマップファイルの取得規則は圧縮ファイル内の</0><1>//# sourceMappingURL=*</1><2>に指定されたアドレスに従います;</2>",
89+
"fix-suggestion-2": "2. ネットワークの問題を除外:ソースファイルが存在するサーバーにアクセス制限がある場合、リソースの取得に失敗する可能性があるため、ネットワークリクエストが正常かどうかをコンソールで確認できます。"
90+
}
91+
},
92+
"network": {
93+
"open-in-new-tab": "新しいタブで開く",
94+
"copy-link-address": "リンクアドレスをコピー",
95+
"copy-as-curl": "cURLとしてコピー"
96+
},
97+
"system": {
98+
"overview": "概要",
99+
"feature": "機能",
100+
"unsupport": "サポートされていないリスト",
101+
"reference": "チェックルールを確認"
102+
},
103+
"page": {
104+
"element": "要素",
105+
"device": "デバイス"
106+
},
107+
"storage": {
108+
"empty-detail": "値を表示するアイテムを選択"
109+
},
110+
"socket": {
111+
"client-name": "クライアント",
112+
"client-not-in-connection": "現在の接続にクライアントが存在しません",
113+
"client-not-found": "クライアントが見つかりません",
114+
"client-offline": "クライアントがオフラインです",
115+
"client-fail": "クライアントの接続が切断されました。関連するテスターにお問い合わせください。",
116+
"debug-name": "あなた",
117+
"debug-offline": "あなたはオフラインです",
118+
"reconnect-fail": "接続が切断されました",
119+
"reconnect-fail-desc": "再接続に失敗しました。ページをリフレッシュするか、再選択してください。",
120+
"room-not-found": "ルームが存在しません",
121+
"network-timeout": "ネットワークエラー、接続がタイムアウトしました",
122+
"server-down": "サーバーエラー"
123+
},
124+
"connections": {
125+
"select-os": "オペレーティング システムを選択",
126+
"select-browser": "ブラウザを選択"
127+
}
128+
}

0 commit comments

Comments
 (0)