Skip to content

Commit b0fa5b6

Browse files
committed
✨ feat(status l10n): 优化翻译和增加状态栏图标
1 parent 003e1e2 commit b0fa5b6

File tree

10 files changed

+123
-49
lines changed

10 files changed

+123
-49
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ vsc-extension-quickstart.md
77
**/.eslintrc.json
88
node_modules
99
package-lock.json
10+
.DS_Store

data/qsseditor.woff

1.52 KB
Binary file not shown.

l10n/bundle.l10n.zh-CN.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"Connected": "已连接",
3+
"Disconnected": "未连接",
4+
"Please input the port number": "请输入端口号",
5+
"Enter the connect port": "输入连接端口",
6+
"the value must be a number (0 < port < 65535)": "端口必须在0到65535之间"
7+
}

l10n/bundle.l10n.zh-TW.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"Connected": "已連接",
3+
"Disconnected": "未連接",
4+
"Please input the port number": "请输入端口号",
5+
"Enter the connect port": "输入连接端口",
6+
"the value must be a number (0 < port < 65535)": "端口必须在0到65535之间"
7+
}

package.json

Lines changed: 60 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "qsseditor",
33
"displayName": "QSSEditor",
44
"description": "Qt StyleSheet Editor",
5-
"version": "0.0.2",
5+
"version": "0.0.3",
66
"publisher": "Irony",
77
"author": {
88
"name": "Irony",
@@ -33,49 +33,57 @@
3333
"onCommand:qsseditor.setPort"
3434
],
3535
"main": "src/extension.js",
36+
"l10n": "./l10n",
3637
"contributes": {
3738
"css": {
3839
"customData": [
3940
"data/qss.json"
4041
]
4142
},
42-
"languages": [{
43-
"id": "css",
44-
"aliases": [
45-
"CSS",
46-
"QSS"
47-
],
48-
"extensions": [
49-
".qss",
50-
".css",
51-
".style"
52-
],
53-
"filenames": [
54-
".css",
55-
".qss",
56-
".style"
57-
]
58-
}],
59-
"commands": [{
43+
"languages": [
44+
{
45+
"id": "css",
46+
"aliases": [
47+
"CSS",
48+
"QSS"
49+
],
50+
"extensions": [
51+
".qss",
52+
".css",
53+
".style"
54+
],
55+
"filenames": [
56+
".css",
57+
".qss",
58+
".style"
59+
]
60+
}
61+
],
62+
"commands": [
63+
{
6064
"command": "qsseditor.applyStyle",
61-
"title": "%qsseditor.applyStyle.title%"
65+
"title": "%qsseditor.applyStyle.text%"
6266
},
6367
{
6468
"command": "qsseditor.setPort",
65-
"title": "%qsseditor.setPort.title%"
69+
"title": "%qsseditor.setPort.text%"
6670
}
6771
],
68-
"keybindings": [{
69-
"command": "qsseditor.applyStyle",
70-
"key": "Shift+Alt+P",
71-
"when": "editorTextFocus && editorLangId =~ /^css$|^qss$/"
72-
}],
73-
"menus": {
74-
"editor/context": [{
75-
"when": "editorTextFocus && editorLangId =~ /^css$|^qss$/",
72+
"keybindings": [
73+
{
7674
"command": "qsseditor.applyStyle",
77-
"group": "navigation"
78-
}]
75+
"key": "Shift+Alt+P",
76+
"when": "editorTextFocus && editorLangId =~ /^css$|^qss$/"
77+
}
78+
],
79+
"menus": {
80+
"editor/context": [
81+
{
82+
"when": "editorTextFocus && editorLangId =~ /^css$|^qss$/",
83+
"command": "qsseditor.applyStyle",
84+
"group": "navigation"
85+
}
86+
]
7987
},
8088
"configuration": {
8189
"type": "object",
@@ -84,19 +92,35 @@
8492
"qsseditor.autoApply": {
8593
"type": "boolean",
8694
"default": true,
87-
"description": "Auto apply style sheet"
95+
"description": "%qsseditor.autoApply.text%"
8896
},
8997
"qsseditor.serverHost": {
9098
"type": "string",
9199
"default": "127.0.0.1",
92-
"description": "DesignerProxy Host"
100+
"description": "%qsseditor.serverHost.text%"
93101
},
94102
"qsseditor.serverPort": {
95103
"type": "integer",
96104
"default": 61052,
97105
"minimum": 1,
98106
"maximum": 65535,
99-
"description": "DesignerProxy Port"
107+
"description": "%qsseditor.serverPort.text%"
108+
}
109+
}
110+
},
111+
"icons": {
112+
"qss-status-on": {
113+
"description": "QSSEditor Connected",
114+
"default": {
115+
"fontPath": "data/qsseditor.woff",
116+
"fontCharacter": "\\ea3e"
117+
}
118+
},
119+
"qss-status-off": {
120+
"description": "QSSEditor Disconnected",
121+
"default": {
122+
"fontPath": "data/qsseditor.woff",
123+
"fontCharacter": "\\ea3f"
100124
}
101125
}
102126
}
@@ -110,7 +134,7 @@
110134
"@types/glob": "^7.2.0",
111135
"@types/mocha": "^9.1.1",
112136
"@types/node": "14.x",
113-
"@types/vscode": "^1.67.0",
137+
"@types/vscode": "^1.73.0",
114138
"@vscode/test-electron": "^2.1.3",
115139
"eslint": "^8.14.0",
116140
"glob": "^8.0.1",
@@ -119,6 +143,7 @@
119143
"vscode": "^1.1.37"
120144
},
121145
"dependencies": {
146+
"@vscode/l10n": "^0.0.18",
122147
"rpc-websockets": "^7.4.18"
123148
}
124149
}

package.nls.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2-
"qsseditor.applyStyle.title": "Apply Style",
3-
"qsseditor.setPort.title": "Set Connect DesignerProxy Port"
2+
"qsseditor.applyStyle.text": "Apply Style",
3+
"qsseditor.setPort.text": "Set Connect DesignerProxy Port",
4+
"qsseditor.autoApply.text": "Auto apply style sheet",
5+
"qsseditor.serverHost.text": "DesignerProxy Host",
6+
"qsseditor.serverPort.text": "DesignerProxy Port"
47
}

package.nls.zh-cn.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2-
"qsseditor.applyStyle.title": "应用样式",
3-
"qsseditor.setPort.title": "设置连接DesignerProxy的端口"
2+
"qsseditor.applyStyle.text": "应用样式",
3+
"qsseditor.setPort.text": "设置连接DesignerProxy的端口",
4+
"qsseditor.autoApply.text": "自动应用样式",
5+
"qsseditor.serverHost.text": "Designer 代理地址",
6+
"qsseditor.serverPort.text": "Designer 代理端口"
47
}

package.nls.zh-tw.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2-
"qsseditor.applyStyle.title": "應用樣式",
3-
"qsseditor.setPort.title": "設定連接DesignerProxy的端口"
2+
"qsseditor.applyStyle.text": "應用樣式",
3+
"qsseditor.setPort.text": "設定連接DesignerProxy的端口",
4+
"qsseditor.autoApply.text": "自動應用樣式",
5+
"qsseditor.serverHost.text": "Designer 代理地址",
6+
"qsseditor.serverPort.text": "Designer 代理端口"
47
}

src/client.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@ const RpcWebSocket = require('rpc-websockets').Client;
33
const keywords = require('./keywords.js');
44

55
var g_client;
6+
var g_updateStatusBar;
67
var g_timerConnect; // 重连定时器
78
var g_timerApply; // 延迟应用样式
89
var g_autoApply = true; // 是否启用自动应用样式
910
var g_valid = true;
1011
var g_host = "localhost";
1112
var g_port = 61052;
12-
var g_zh = false;
13-
14-
// 判断当前语言是否中文
15-
const vsconfig = process.env['VSCODE_NLS_CONFIG'];
16-
if (vsconfig) g_zh = JSON.parse(vsconfig).locale.startsWith('zh');
1713

1814
/**
1915
* 初始化关键词
@@ -48,14 +44,17 @@ function startClient() {
4844
});
4945
g_client.on('open', function () {
5046
console.log('NodeClient::handleConnected');
47+
if (g_updateStatusBar) g_updateStatusBar(true);
5148
});
5249
g_client.on('close', function () {
5350
console.log('NodeClient::handleDisconnected');
5451
if (g_valid && g_timerConnect == undefined) g_timerConnect = setTimeout(startClient, 3000);
52+
if (g_updateStatusBar) g_updateStatusBar(false);
5553
});
5654
g_client.on('error', function (event) {
5755
console.error('NodeClient::handleError: ' + event.error);
5856
if (g_valid && g_timerConnect == undefined) g_timerConnect = setTimeout(startClient, 3000);
57+
if (g_updateStatusBar) g_updateStatusBar(false);
5958
});
6059
g_client.on('addKeywords', function (words) {
6160
console.log('NodeClient::handleKeywordAdd: name=' + words);
@@ -118,14 +117,14 @@ function applyStyle(doc) {
118117
function setPort() {
119118
vscode.window.showInputBox({
120119
ignoreFocusOut: false,
121-
placeHolder: g_zh ? '请输入端口号' : 'Please input the port number',
122-
title: g_zh ? '输入连接端口' : 'Enter the connect port',
120+
placeHolder: vscode.l10n.t('Please input the port number'),
121+
title: vscode.l10n.t('Enter the connect port'),
123122
value: '' + vscode.workspace.getConfiguration().get('qsseditor.serverPort', '61052'),
124123
validateInput: function (value) {
125124
let port = Number(value);
126125
if (!isNaN(port) && port != 0)
127126
return null;
128-
return g_zh ? '端口必须在0到65535之间' : 'the value must be a number (0 < port < 65535)';
127+
return vscode.l10n.t('the value must be a number (0 < port < 65535)');
129128
}
130129
}).then(port => {
131130
if (port == undefined) return;
@@ -176,6 +175,14 @@ function onDidSaveTextDocument(document) {
176175
onAutoApply(document);
177176
};
178177

178+
/**
179+
* 设置状态栏回调
180+
* @param {function} callback
181+
*/
182+
function setStatusBarCallback(callback) {
183+
g_updateStatusBar = callback;
184+
}
185+
179186
module.exports = {
180187
initKeywords,
181188
startClient,
@@ -185,4 +192,5 @@ module.exports = {
185192
setPort,
186193
onDidChangeTextDocument,
187194
onDidSaveTextDocument,
195+
setStatusBarCallback,
188196
}

src/extension.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const vscode = require('vscode');
22
const client = require('./client.js');
33

4+
var g_statusBar = null;
5+
46
/**
57
* 定义跳转
68
* @param {vscode.TextDocument} document
@@ -49,6 +51,13 @@ function activate(context) {
4951
vscode.workspace.onDidChangeTextDocument(client.onDidChangeTextDocument);
5052
vscode.workspace.onDidSaveTextDocument(client.onDidSaveTextDocument);
5153

54+
// 注册状态栏
55+
if (!g_statusBar) {
56+
g_statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 0);
57+
}
58+
updateStatusBar(false);
59+
client.setStatusBarCallback(updateStatusBar);
60+
5261
// 注册关键词
5362
require('./provider.js')(context);
5463

@@ -58,6 +67,14 @@ function activate(context) {
5867
client.startClient();
5968
}
6069

70+
function updateStatusBar(enabled) {
71+
if (g_statusBar) {
72+
g_statusBar.text = enabled ? `$(qss-status-on)` : `$(qss-status-off)`;
73+
g_statusBar.tooltip = enabled ? vscode.l10n.t("Connected") : vscode.l10n.t("Disconnected");
74+
g_statusBar.show();
75+
}
76+
}
77+
6178
/**
6279
* 插件被释放时触发
6380
*/

0 commit comments

Comments
 (0)