Skip to content

Commit 6e431d3

Browse files
committed
增加 i18n 支持
1 parent f913542 commit 6e431d3

File tree

12 files changed

+116
-23
lines changed

12 files changed

+116
-23
lines changed

.vscode/tasks.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "0.1.0",
5+
"command": "npm",
6+
"isShellCommand": true,
7+
"showOutput": "always",
8+
"suppressTaskName": true,
9+
"tasks": [
10+
{
11+
"taskName": "install",
12+
"args": ["install"]
13+
},
14+
{
15+
"taskName": "update",
16+
"args": ["update"]
17+
},
18+
{
19+
"taskName": "i18n",
20+
"args": ["run", "i18n"]
21+
}
22+
]
23+
}

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
1111
and this project adheres to [Semantic Versioning](http://semver.org/).
1212

1313

14+
## 0.0.1-alpha.06
15+
ADDED:
16+
- 增加i18n支持
17+
1418
## 0.0.1-alpha.05
1519
ADDED:
1620
- injectComponent 支持

i18n/en_US/global.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"sidebar": "Access URL",
3+
"port": "Port",
4+
"generate": "Generate",
5+
"handleDelete": {
6+
"header": "Are you sure to delete this port?",
7+
"message": "You're trying to delete port {port}",
8+
"okText": "Delete"
9+
},
10+
"message": {
11+
"createFailed": "Create failed: {msg}",
12+
"createSuccess": "Create success!",
13+
"deleteFailed": "Delete failed: {msg}",
14+
"deleteSuccess": "Delete success!"
15+
}
16+
}

i18n/en_US/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*eslint-disable*/
2+
const contents = ['global'];
3+
4+
export default contents.reduce((p, v) => {
5+
p[v] = require(`./${v}.json`);
6+
return p
7+
}, {});

i18n/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import enUS from './en_US';
2+
import zhCN from './zh_CN';
3+
4+
5+
const cache = {
6+
en_US: enUS,
7+
zh_CN: zhCN,
8+
};
9+
10+
export default cache;

i18n/zh_CN/global.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"sidebar": "访问链接",
3+
"port": "端口",
4+
"generate": "生成",
5+
"handleDelete": {
6+
"header": "你确定删除此端口吗",
7+
"message": "你正在删除端口 {port}",
8+
"okText": "删除"
9+
},
10+
"message": {
11+
"createFailed": "创建失败: {msg}",
12+
"createSuccess": "创建成功!",
13+
"deleteFailed": "删除失败: {msg}",
14+
"deleteSuccess": "删除成功!"
15+
}
16+
}

i18n/zh_CN/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*eslint-disable*/
2+
const contents = ['global'];
3+
4+
export default contents.reduce((p, v) => {
5+
p[v] = require(`./${v}.json`);
6+
return p
7+
}, {});

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "WebIDE-Plugin-AccessUrl",
3-
"version": "0.0.1-alpha.05",
3+
"version": "0.0.1-alpha.06",
44
"description": "WebIDE-Plugin-AccessUrl for Coding WebIDE",
55
"repository": {
66
"url": "git@github.com:Coding/WebIDE-Plugin-Env.git"
@@ -9,7 +9,8 @@
99
"author": "candy <candy.zhengxq@gmail.com>",
1010
"main": "server.js",
1111
"scripts": {
12-
"dev": "PLUGIN=$(pwd) NODE_ENV=development babel-node node_modules/codingSDK/server.js"
12+
"dev": "PLUGIN=$(pwd) NODE_ENV=development babel-node node_modules/codingSDK/server.js",
13+
"i18n": "I18nTargetRoot=$(pwd)/i18n/en_US babel-node node_modules/codingSDK/.script/generateI18n $(pwd)/src"
1314
},
1415
"codingIdePackage": {
1516
"name": "access-url",
@@ -36,6 +37,7 @@
3637
"eslint-plugin-react": "^6.3.0",
3738
"extract-text-webpack-plugin": "^2.0.0-rc.3",
3839
"git-url-parse": "^6.0.1",
40+
"immutable": "^3.8.1",
3941
"jsdom": "^9.5.0",
4042
"mocha": "^3.0.2",
4143
"react": "^15.3.2",
@@ -54,11 +56,11 @@
5456
"react": "^0.14.7 || ^15.0.0"
5557
},
5658
"dependencies": {
57-
"codingSDK": "https://github.com/Coding/WebIDE-Plugin-SDK.git#0.0.1-alpha.06",
5859
"babel-preset-env": "^1.1.8",
5960
"babel-runtime": "^6.11.6",
6061
"body-parser": "^1.15.2",
6162
"classnames": "^2.2.5",
63+
"codingSDK": "https://github.com/Coding/WebIDE-Plugin-SDK.git#0.0.1-alpha.10",
6264
"cors": "^2.8.1",
6365
"express": "^4.14.0",
6466
"fs-promise": "^1.0.0",

src/AccessUrl.jsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { global } from './manager';
88
import QRCode from 'qrcode.react';
99

1010
const Modal = global.sdk.Modal;
11+
const i18n = global.i18n;
1112

1213
class AccessUrl extends Component {
1314
constructor(props) {
@@ -38,10 +39,10 @@ class AccessUrl extends Component {
3839
<div className="access-url-container" >
3940
<div className="access-url-panel">
4041
<div className="panel-heading">
41-
Port
42+
{i18n`global.port`}
4243
<input type="number" min="0" max="65535" defaultValue="8080" ref={(input) => { this.portInput = input; }} />
4344
<button type="submit" className="btn btn-primary btn-xs" disabled={generateDisabled} onClick={this.handleGenerate} >
44-
Generate
45+
{i18n`global.generate`}
4546
</button>
4647
<i className="fa fa-refresh" onClick={this.handleRefrash} />
4748
</div>
@@ -138,9 +139,9 @@ class AccessUrl extends Component {
138139
}
139140
handleDelete = async (port) => {
140141
var confirmed = await Modal.showModal('Confirm', {
141-
header: 'Are you sure to delete this port?',
142-
message: `You're trying to delete port ${port}`,
143-
okText: 'Delete'
142+
header: i18n`global.handleDelete.header`,
143+
message: i18n`global.handleDelete.message${port}`,
144+
okText: i18n`global.handleDelete.okText`
144145
})
145146
Modal.dismissModal()
146147
if (confirmed) {

src/actions.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createAction } from 'redux-actions';
33
import * as api from './api';
44
import { global } from './manager';
55

6+
const i18n = global.i18n;
67
const { notify, NOTIFY_TYPE } = global.sdk.Notify;
78

89
export const PORT_OPERATING = 'PORT_OPERATING';
@@ -18,8 +19,8 @@ export function listPorts() {
1819
api.listPorts()
1920
.then((res) => {
2021
dispatch(updatePortList({ portList: res }));
21-
})
22-
}
22+
});
23+
};
2324
}
2425

2526
export function createPort({ port }) {
@@ -30,15 +31,15 @@ export function createPort({ port }) {
3031
if (res.error) {
3132
notify({
3233
notifyType: NOTIFY_TYPE.ERROR,
33-
message: `Create failed: ${res.msg}`,
34+
message: i18n`global.message.createFailed${{ msg: res.msg }}`,
3435
});
3536
} else {
36-
notify({ message: 'Create success!' });
37+
notify({ message: i18n`global.message.createSuccess` });
3738
}
3839
dispatch(listPorts());
3940
dispatch(portOperating({ operating: false }));
40-
})
41-
}
41+
});
42+
};
4243
}
4344

4445
export function deletePort({ port }) {
@@ -49,14 +50,14 @@ export function deletePort({ port }) {
4950
if (res.error) {
5051
notify({
5152
notifyType: NOTIFY_TYPE.ERROR,
52-
message: `Delete failed: ${res.msg}`,
53+
message: i18n`global.message.deleteFailed${{ msg: res.msg }}`,
5354
});
5455
} else {
55-
notify({ message: 'Delete success!' });
56+
notify({ message: i18n`global.message.deleteSuccess` });
5657
}
5758
dispatch(listPorts());
5859
dispatch(portOperating({ operating: false }));
59-
})
60-
}
60+
});
61+
};
6162
}
6263

0 commit comments

Comments
 (0)