Skip to content

Commit 3f1b43e

Browse files
committed
update i18n
1 parent 328b1f5 commit 3f1b43e

File tree

4 files changed

+49
-33
lines changed

4 files changed

+49
-33
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-update-cli",
3-
"version": "1.42.1",
3+
"version": "1.42.2",
44
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
55
"main": "index.js",
66
"bin": {

src/app.ts

+20-32
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ import Table from 'tty-table';
44

55
import { post, get, doDelete } from './api';
66
import type { Platform } from './types';
7+
import { t } from './utils/i18n';
8+
9+
const validPlatforms = ['ios', 'android', 'harmony'];
710

8-
const validPlatforms = {
9-
ios: 1,
10-
android: 1,
11-
harmony: 1,
12-
};
1311

1412
export function checkPlatform(platform: Platform) {
15-
if (!validPlatforms[platform]) {
16-
throw new Error(`无法识别的平台 '${platform}'`);
13+
if (!validPlatforms.includes(platform)) {
14+
throw new Error(t('unsupportedPlatform', { platform }));
1715
}
1816
return platform;
1917
}
@@ -22,27 +20,23 @@ export function getSelectedApp(platform: Platform) {
2220
checkPlatform(platform);
2321

2422
if (!fs.existsSync('update.json')) {
25-
throw new Error(
26-
`App not selected. run 'pushy selectApp --platform ${platform}' first!`,
27-
);
23+
throw new Error(t('appNotSelected', { platform }));
2824
}
2925
const updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
3026
if (!updateInfo[platform]) {
31-
throw new Error(
32-
`App not selected. run 'pushy selectApp --platform ${platform}' first!`,
33-
);
27+
throw new Error(t('appNotSelected', { platform }));
3428
}
3529
return updateInfo[platform];
3630
}
3731

38-
export async function listApp(platform: Platform) {
32+
export async function listApp(platform: Platform | '' = '') {
3933
const { data } = await get('/app/list');
4034
const list = platform ? data.filter((v) => v.platform === platform) : data;
4135

4236
const header = [
43-
{ value: '应用 id' },
44-
{ value: '应用名称' },
45-
{ value: '平台' },
37+
{ value: t('appId') },
38+
{ value: t('appName') },
39+
{ value: t('platform') },
4640
];
4741
const rows = [];
4842
for (const app of list) {
@@ -51,19 +45,15 @@ export async function listApp(platform: Platform) {
5145

5246
console.log(Table(header, rows).render());
5347

54-
if (platform) {
55-
console.log(`\共 ${list.length} ${platform} 个应用`);
56-
} else {
57-
console.log(`\共 ${list.length} 个应用`);
58-
}
48+
console.log(`\n${t('totalApps', { count: list.length, platform })}`);
5949
return list;
6050
}
6151

6252
export async function chooseApp(platform: Platform) {
6353
const list = await listApp(platform);
6454

6555
while (true) {
66-
const id = await question('输入应用 id:');
56+
const id = await question(t('enterAppIdQuestion'));
6757
const app = list.find((v) => v.id === Number(id));
6858
if (app) {
6959
return app;
@@ -77,13 +67,13 @@ export const commands = {
7767
}: {
7868
options: { name: string; downloadUrl: string; platform: Platform };
7969
}) {
80-
const name = options.name || (await question('应用名称:'));
70+
const name = options.name || (await question(t('appNameQuestion')));
8171
const { downloadUrl } = options;
8272
const platform = checkPlatform(
83-
options.platform || (await question('平台(ios/android/harmony):')),
73+
options.platform || (await question(t('platformQuestion'))),
8474
);
8575
const { id } = await post('/app/create', { name, platform, downloadUrl });
86-
console.log(`已成功创建应用(id: ${id})`);
76+
console.log(t('createAppSuccess', { id }));
8777
await this.selectApp({
8878
args: [id],
8979
options: { platform },
@@ -93,18 +83,18 @@ export const commands = {
9383
const { platform } = options;
9484
const id = args[0] || chooseApp(platform);
9585
if (!id) {
96-
console.log('已取消');
86+
console.log(t('cancelled'));
9787
}
9888
await doDelete(`/app/${id}`);
99-
console.log('操作成功');
89+
console.log(t('operationSuccess'));
10090
},
10191
apps: async ({ options }: { options: { platform: Platform } }) => {
10292
const { platform } = options;
10393
listApp(platform);
10494
},
10595
selectApp: async ({ args, options }: { args: string[]; options: { platform: Platform } }) => {
10696
const platform = checkPlatform(
107-
options.platform || (await question('平台(ios/android/harmony):')),
97+
options.platform || (await question(t('platformQuestion'))),
10898
);
10999
const id = args[0]
110100
? Number.parseInt(args[0])
@@ -115,9 +105,7 @@ export const commands = {
115105
try {
116106
updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
117107
} catch (e) {
118-
console.error(
119-
'Failed to parse file `update.json`. Try to remove it manually.',
120-
);
108+
console.error(t('failedToParseUpdateJson'));
121109
throw e;
122110
}
123111
}

src/locales/en.ts

+14
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,18 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
2525
latestVersionTag: '(latest: {{version}})',
2626
rnuVersionNotFound:
2727
'react-native-update: Cannot get the version number. Please run the command in the project directory',
28+
unsupportedPlatform: 'Unsupported platform `{{platform}}`',
29+
appId: 'App ID',
30+
appName: 'App Name',
31+
platform: 'Platform',
32+
totalApps: 'Total {{count}} apps',
33+
appNotSelected:
34+
'App not selected. run `cresc selectApp --platform {{platform}}` first!',
35+
enterAppIdQuestion: 'Enter AppId:',
36+
appNameQuestion: 'App Name:',
37+
platformQuestion: 'Platform(ios/android/harmony):',
38+
createAppSuccess: 'App created successfully (id: {{id}})',
39+
cancelled: 'Cancelled',
40+
operationSuccess: 'Operation successful',
41+
failedToParseUpdateJson: 'Failed to parse file `update.json`. Try to remove it manually.',
2842
};

src/locales/zh.ts

+14
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,18 @@ export default {
2323
latestVersionTag: '(最新:{{version}})',
2424
rnuVersionNotFound:
2525
'react-native-update: 无法获取版本号。请在项目目录中运行命令',
26+
unsupportedPlatform: '无法识别的平台 `{{platform}}`',
27+
appId: '应用 id',
28+
appName: '应用名称',
29+
platform: '平台',
30+
totalApps: '共 {{count}} 个{{platform}}应用',
31+
appNotSelected:
32+
'尚未选择应用。请先运行 `pushy selectApp --platform {{platform}}` 来选择应用',
33+
enterAppIdQuestion: '输入应用 id:',
34+
appNameQuestion: '应用名称:',
35+
platformQuestion: '平台(ios/android/harmony):',
36+
createAppSuccess: '已成功创建应用(id: {{id}})',
37+
cancelled: '已取消',
38+
operationSuccess: '操作成功',
39+
failedToParseUpdateJson: '无法解析文件 `update.json`。请手动删除它。',
2640
};

0 commit comments

Comments
 (0)