Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 6e8ee77

Browse files
committed
Feat: i18n editor
1 parent 4760a9f commit 6e8ee77

File tree

3 files changed

+123
-58
lines changed

3 files changed

+123
-58
lines changed

src/app/views/FileManagerEditor.vue

Lines changed: 75 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
<!--
22
Copyright (C) 2022 MCSManager <[email protected]>
33
-->
4-
54
<template>
65
<Panel>
76
<template #title>
87
{{ $t("fileManagerEditor.title") }}
98
{{ target }}
10-
<el-tag type="warning" effect="plain" size="small" v-if="editStatus === 'edit'">编辑中</el-tag>
11-
<el-tag type="success" effect="plain" size="small" v-if="editStatus === 'success'">已保存</el-tag>
9+
<el-tag type="warning" effect="plain" size="small" v-if="editStatus === 'edit'">{{
10+
$t("CommonText.032")
11+
}}</el-tag>
12+
<el-tag type="success" effect="plain" size="small" v-if="editStatus === 'success'">{{
13+
$t("CommonText.033")
14+
}}</el-tag>
1215
</template>
1316
<template #default>
1417
<div class="instance-table-wrapper">
@@ -23,14 +26,12 @@
2326
{{ $t("general.refresh") }}
2427
</el-button>
2528
<el-button size="small" @click="jumpToLine">
26-
<i class="el-icon-sort-down"></i>
27-
跳转行
28-
</el-button>
29+
<i class="el-icon-sort-down"></i>{{ $t("CommonText.034") }}</el-button
30+
>
2931
<el-dropdown :hide-on-click="false">
3032
<el-button type="default" size="small">
31-
<i class="el-icon-setting"></i>
32-
编辑器设置
33-
<i class="el-icon-arrow-down el-icon--right"></i>
33+
<i class="el-icon-setting"></i>{{ $t("views.FileManagerEditor.001")
34+
}}<i class="el-icon-arrow-down el-icon--right"></i>
3435
</el-button>
3536
<template #dropdown>
3637
<el-dropdown-menu>
@@ -40,62 +41,62 @@
4041
@change="setWrapMode($event)"
4142
active-color="#13ce66"
4243
inactive-color="#ff4949"
43-
active-text="自动换行"
44-
/>
44+
:active-text="$t('CommonText.035')"
45+
></el-switch>
4546
</el-dropdown-item>
4647
<el-dropdown-item>
4748
<el-switch
4849
v-model="editorSettings.behavioursEnabled"
4950
@change="setBehavioursEnabled($event)"
5051
active-color="#13ce66"
5152
inactive-color="#ff4949"
52-
active-text="自动补全"
53-
/>
53+
:active-text="$t('CommonText.036')"
54+
></el-switch>
5455
</el-dropdown-item>
5556
<el-dropdown-item>
5657
<el-switch
5758
v-model="editorSettings.highlightActiveLine"
5859
@change="setHighlightActiveLine($event)"
5960
active-color="#13ce66"
6061
inactive-color="#ff4949"
61-
active-text="高亮当前行"
62-
/>
62+
:active-text="$t('views.FileManagerEditor.002')"
63+
></el-switch>
6364
</el-dropdown-item>
6465
<el-dropdown-item>
6566
<el-switch
6667
v-model="editorSettings.readOnly"
6768
@change="setReadOnly($event)"
6869
active-color="#13ce66"
6970
inactive-color="#ff4949"
70-
active-text="只读模式"
71-
/>
71+
:active-text="$t('CommonText.037')"
72+
></el-switch>
7273
</el-dropdown-item>
7374
<el-dropdown-item>
7475
<el-switch
7576
v-model="editorSettings.showInvisibles"
7677
@change="setShowInvisibles($event)"
7778
active-color="#13ce66"
7879
inactive-color="#ff4949"
79-
active-text="显示隐藏字符"
80-
/>
80+
:active-text="$t('views.FileManagerEditor.003')"
81+
></el-switch>
8182
</el-dropdown-item>
8283
<el-dropdown-item>
8384
<el-switch
8485
v-model="editorSettings.enableMultiselect"
8586
@change="setEnableMultiselect($event)"
8687
active-color="#13ce66"
8788
inactive-color="#ff4949"
88-
active-text="选中多行"
89-
/>
89+
:active-text="$t('CommonText.038')"
90+
></el-switch>
9091
</el-dropdown-item>
9192
<el-dropdown-item>
9293
<el-switch
9394
v-model="editorSettings.showLineNumbers"
9495
@change="setShowLineNumbers($event)"
9596
active-color="#13ce66"
9697
inactive-color="#ff4949"
97-
active-text="显示行号"
98-
/>
98+
:active-text="$t('CommonText.039')"
99+
></el-switch>
99100
</el-dropdown-item>
100101
</el-dropdown-menu>
101102
</template>
@@ -104,16 +105,26 @@
104105
v-model="editorSettings.theme"
105106
filterable
106107
size="small"
107-
placeholder="编辑器主题"
108108
@change="changeEditorTheme($event)"
109+
:placeholder="$t('views.FileManagerEditor.004')"
109110
>
110-
<el-option v-for="item in editorThemes" :key="item" :label="item" :value="item"></el-option>
111+
<el-option
112+
v-for="item in editorThemes"
113+
:key="item"
114+
:label="item"
115+
:value="item"
116+
></el-option>
111117
</el-select>
112-
<el-input-number v-model="editorSettings.fontSize" @change="changeEditorFontsize($event)" :min="1" :max="114.514" size="small"></el-input-number>
118+
<el-input-number
119+
v-model="editorSettings.fontSize"
120+
@change="changeEditorFontsize($event)"
121+
:min="1"
122+
:max="114.514"
123+
size="small"
124+
></el-input-number>
113125
<el-button type="default" size="small" @click="toHotKey">
114-
<i class="el-icon-sort-down"></i>
115-
快捷键提示
116-
</el-button>
126+
<i class="el-icon-sort-down"></i>{{ $t("views.FileManagerEditor.005") }}</el-button
127+
>
117128
<el-button size="small" @click="back" v-if="!backType">
118129
<i class="el-icon-pie-chart"></i>
119130
{{ $t("fileManagerEditor.backToFileManager") }}
@@ -127,7 +138,8 @@
127138
type="primary"
128139
plain
129140
v-if="backType == 1"
130-
>{{ $t("fileManagerEditor.backViaHistory") }}</el-button>
141+
>{{ $t("fileManagerEditor.backViaHistory") }}</el-button
142+
>
131143
</div>
132144
</div>
133145
<div v-show="!error" style="overflow: auto">
@@ -149,14 +161,16 @@
149161
</template>
150162
</Panel>
151163
</template>
164+
152165
<script>
153166
import Panel from "../../components/Panel";
154167
import { API_FILE_URL } from "../service/common";
155168
import path from "path";
156169
import { request } from "../service/protocol";
157-
158170
export default {
159-
components: { Panel },
171+
components: {
172+
Panel
173+
},
160174
data() {
161175
return {
162176
serviceUuid: this.$route.params.serviceUuid,
@@ -224,7 +238,6 @@ export default {
224238
editorHotKey: false
225239
};
226240
},
227-
228241
async mounted() {
229242
await this.render();
230243
this.editor = window.ace.edit("editor");
@@ -244,7 +257,10 @@ export default {
244257
});
245258
this.editor.commands.addCommand({
246259
name: "saveFile",
247-
bindKey: { win: "Ctrl-S", mac: "Command-S" },
260+
bindKey: {
261+
win: "Ctrl-S",
262+
mac: "Command-S"
263+
},
248264
exec: () => {
249265
this.saveFile();
250266
this.editStatus = "success";
@@ -276,15 +292,15 @@ export default {
276292
},
277293
jumpToLine() {
278294
this.editor.find();
279-
this.$prompt("跳转到指定行", "提示", {
280-
confirmButtonText: "确定",
281-
cancelButtonText: "取消",
295+
this.$prompt(window.$t("views.FileManagerEditor.006"), window.$t("CommonText.040"), {
296+
confirmButtonText: window.$t("CommonText.041"),
297+
cancelButtonText: window.$t("CommonText.042"),
282298
inputPattern: /^[0-9]*$/,
283-
inputErrorMessage: "格式不正确"
299+
inputErrorMessage: window.$t("views.FileManagerEditor.007")
284300
}).then(({ value }) => {
285301
this.$message({
286302
type: "success",
287-
message: "已跳转到第 " + value + ""
303+
message: window.$t("views.FileManagerEditor.008") + value + window.$t("CommonText.043")
288304
});
289305
this.editor.gotoLine(value);
290306
});
@@ -315,11 +331,14 @@ export default {
315331
localStorage.setItem("editorTheme", val);
316332
},
317333
toHotKey() {
318-
window.open('https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts')
334+
window.open("https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts");
319335
},
320336
async refresh() {
321337
await this.render();
322-
this.$message({ message: this.$t("general.refreshFinish"), type: "success" });
338+
this.$message({
339+
message: this.$t("general.refreshFinish"),
340+
type: "success"
341+
});
323342
},
324343
async backTerminal() {
325344
this.$router.push({
@@ -328,19 +347,18 @@ export default {
328347
},
329348
async back() {
330349
if (this.editStatus === "edit") {
331-
this.$confirm("你还未保存文件, 是否继续返回?", "提示", {
332-
confirmButtonText: "确定",
333-
cancelButtonText: "取消",
350+
this.$confirm(window.$t("views.FileManagerEditor.009"), window.$t("CommonText.040"), {
351+
confirmButtonText: window.$t("CommonText.041"),
352+
cancelButtonText: window.$t("CommonText.042"),
334353
type: "warning"
335-
})
336-
.then(() => {
337-
this.$router.push({
338-
path: `/file/${this.serviceUuid}/${this.instanceUuid}/`,
339-
query: {
340-
path: path.dirname(this.target)
341-
}
342-
});
343-
})
354+
}).then(() => {
355+
this.$router.push({
356+
path: `/file/${this.serviceUuid}/${this.instanceUuid}/`,
357+
query: {
358+
path: path.dirname(this.target)
359+
}
360+
});
361+
});
344362
} else {
345363
this.$router.push({
346364
path: `/file/${this.serviceUuid}/${this.instanceUuid}/`,
@@ -353,7 +371,6 @@ export default {
353371
backViaHistory() {
354372
this.$router.go(-1);
355373
},
356-
357374
async render() {
358375
try {
359376
const text = await request({
@@ -375,7 +392,6 @@ export default {
375392
this.error = error.message;
376393
}
377394
},
378-
379395
async saveFile() {
380396
this.edit.text = this.editor.getValue();
381397
await request({
@@ -390,7 +406,10 @@ export default {
390406
target: this.target
391407
}
392408
});
393-
this.$message({ message: this.$t("fileManagerEditor.updateTextSuccess"), type: "success" });
409+
this.$message({
410+
message: this.$t("fileManagerEditor.updateTextSuccess"),
411+
type: "success"
412+
});
394413
}
395414
}
396415
};

src/language/en_us.json

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,19 @@
3030
"028": "Decompress (ZIP)",
3131
"029": "the host",
3232
"030": "container",
33-
"031": "tunnel-id"
33+
"031": "tunnel-id",
34+
"032": "Edit",
35+
"033": "Saved",
36+
"034": "jump line",
37+
"035": "word wrap",
38+
"036": "Autocomplete",
39+
"037": "read-only mode",
40+
"038": "Select multiple rows",
41+
"039": "show line number",
42+
"040": "hint",
43+
"041": "Sure",
44+
"042": "Cancel",
45+
"043": "Row"
3446
},
3547
"general": {
3648
"search": "Search",
@@ -1087,6 +1099,17 @@
10871099
"Terminal_TermSetting": {
10881100
"001": "Terminal font size",
10891101
"002": "The default value is 12px, and it will take effect after refreshing the webpage after the change. Changing this item may cause the emulation terminal text to be blocked."
1102+
},
1103+
"FileManagerEditor": {
1104+
"001": "editor settings",
1105+
"002": "highlight current line",
1106+
"003": "show hidden characters",
1107+
"004": "editor theme",
1108+
"005": "KeyTips",
1109+
"006": "jump to the specified line",
1110+
"007": "incorrect format",
1111+
"008": "Jumped to the",
1112+
"009": "You haven't saved the file yet, do you want to go back?"
10901113
}
10911114
},
10921115
"components": {

src/language/zh_cn.json

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,19 @@
3030
"028": "解压",
3131
"029": "主机",
3232
"030": "容器",
33-
"031": "隧道 ID"
33+
"031": "隧道 ID",
34+
"032": "编辑中",
35+
"033": "已保存",
36+
"034": "跳转行",
37+
"035": "自动换行",
38+
"036": "自动补全",
39+
"037": "只读模式",
40+
"038": "选中多行",
41+
"039": "显示行号",
42+
"040": "提示",
43+
"041": "确定",
44+
"042": "取消",
45+
"043": ""
3446
},
3547
"general": {
3648
"search": "搜索",
@@ -1086,6 +1098,17 @@
10861098
"Terminal_TermSetting": {
10871099
"001": "终端字体大小",
10881100
"002": "默认12px,更改后刷新网页生效,更改此项可能导致仿真终端文字被遮挡。"
1101+
},
1102+
"FileManagerEditor": {
1103+
"001": "编辑器设置",
1104+
"002": "高亮当前行",
1105+
"003": "显示隐藏字符",
1106+
"004": "编辑器主题",
1107+
"005": "快捷键提示",
1108+
"006": "跳转到指定行",
1109+
"007": "格式不正确",
1110+
"008": "已跳转到第 ",
1111+
"009": "你还未保存文件, 是否继续返回?"
10891112
}
10901113
},
10911114
"components": {

0 commit comments

Comments
 (0)