提交 91646f69 编写于 作者: B baiy 提交者: ninecents

ASCII i18n

上级 260008d9
...@@ -129,8 +129,9 @@ module.exports = { ...@@ -129,8 +129,9 @@ module.exports = {
if (matchString) { if (matchString) {
matchString.forEach((wildcard) => { matchString.forEach((wildcard) => {
if ((wildcard in values) && !(wildcard in replaceHash)) { let key = wildcard.replace("{","").replace("}",'')
replaceHash[wildcard] = values[wildcard] if ((key in values) && !(wildcard in replaceHash)) {
replaceHash[wildcard] = values[key]
} }
}); });
} }
......
...@@ -58,8 +58,9 @@ const translate = (code, key, values = {}) => { ...@@ -58,8 +58,9 @@ const translate = (code, key, values = {}) => {
if (matchString) { if (matchString) {
matchString.forEach((wildcard) => { matchString.forEach((wildcard) => {
if ((wildcard in values) && !(wildcard in replaceHash)) { let key = wildcard.replace("{","").replace("}",'')
replaceHash[wildcard] = values[wildcard] if ((key in values) && !(wildcard in replaceHash)) {
replaceHash[wildcard] = values[key]
} }
}); });
} }
......
{
"convent": "Convent",
"input_prompt": "Multiple characters are separated by space",
"input_10": "DEC",
"input_16": "HEX",
"input_8": "OCT",
"input_2": "BIN",
"input_string": "String",
"clear": "Clear",
"code_table": "ASCII table",
"yes": "Y",
"no": "N",
"input_null_prompt": "Please enter the corresponding code",
"convent_error": "Conversion exception: {0}",
"is_show": "Is Show",
"description": "Description",
"code_nul": "Null char",
"code_soh": "Start of Heading",
"code_stx": "Start of Text",
"code_etx": "End of Text",
"code_eot": "End of Transmission",
"code_enq": "Enquiry",
"code_ack": "Acknowledgment",
"code_bel": "Bell",
"code_bs": "Back Space",
"code_tab": "Horizontal Tab",
"code_lf": "Line Feed",
"code_vt": "Vertical Tab",
"code_ff": "Form Feed",
"code_cr": "Carriage Return",
"code_so": "Shift Out / X-On",
"code_si": "Shift In / X-Off",
"code_dle": "Data Line Escape",
"code_dc1": "Device Control 1 (oft. XON)",
"code_dc2": "Device Control 2",
"code_dc3": "Device Control 3 (oft. XOFF)",
"code_dc4": "Device Control 4",
"code_nak": "Negative Acknowledgement",
"code_syn": "Synchronous Idle",
"code_etb": "End of Transmit Block",
"code_can": "Cancel",
"code_em": "End of Medium",
"code_sub": "Substitute",
"code_esc": "Escape",
"code_fs": "File Separator",
"code_gs": "Group Separator",
"code_rs": "Record Separator",
"code_us": "Unit Separator",
"code_del": "Delete",
"code_space": "Space",
}
{
"convent": "转换",
"input_prompt": "多个字符用空格分隔",
"input_10": "十进制",
"input_16": "十六进制",
"input_8": "八进制",
"input_2": "二进制",
"input_string": "字符串",
"clear": "清空",
"code_table": "编码表",
"yes": "是",
"no": "否",
"input_null_prompt": "请输入对应的待转换编码",
"convent_error": "转换异常: {0}",
"is_show": "是否显示",
"description": "描述",
"code_nul": "空字符(Null)",
"code_soh": "标题开始",
"code_stx": "本文开始",
"code_etx": "本文结束",
"code_eot": "传输结束",
"code_enq": "请求",
"code_ack": "确认回应",
"code_bel": "响铃",
"code_bs": "退格",
"code_tab": "水平定位符号",
"code_lf": "换行键",
"code_vt": "垂直定位符号",
"code_ff": "换页键",
"code_cr": "归位键",
"code_so": "取消变换(Shift out)",
"code_si": "启用变换(Shift in)",
"code_dle": "跳出数据通讯",
"code_dc1": "设备控制一(XON 启用软件速度控制)",
"code_dc2": "设备控制二",
"code_dc3": "设备控制三(XOFF 停用软件速度控制)",
"code_dc4": "设备控制四",
"code_nak": "确认失败回应",
"code_syn": "同步用暂停",
"code_etb": "区块传输结束",
"code_can": "取消",
"code_em": "连接介质中断",
"code_sub": "替换",
"code_esc": "跳出",
"code_fs": "文件分割符",
"code_gs": "组群分隔符",
"code_rs": "记录分隔符",
"code_us": "单元分隔符",
"code_del": "删除",
"code_space": "空格"
}
<template> <template>
<div> <div>
<Tabs v-model="operation"> <Tabs v-model="operation">
<TabPane label="转换" name="convent"> <TabPane :label="$t('ascii_convent')" name="convent">
<option-block> <option-block>
<Input v-model="current.data.dec" placeholder="多个字符用空格分隔"> <Input v-model="current.data.dec" :placeholder="$t('ascii_input_prompt')">
<div slot="prepend" style="width: 100px"><strong>十进制</strong></div> <div slot="prepend" style="width: 100px"><strong>{{ $t('ascii_input_10') }}</strong></div>
</Input> </Input>
</option-block> </option-block>
<option-block> <option-block>
<Input v-model="current.data.hex" placeholder="多个字符用空格分隔"> <Input v-model="current.data.hex" :placeholder="$t('ascii_input_prompt')">
<div slot="prepend" style="width: 100px"><strong>十六进制</strong></div> <div slot="prepend" style="width: 100px"><strong>{{ $t('ascii_input_16') }}</strong></div>
</Input> </Input>
</option-block> </option-block>
<option-block> <option-block>
<Input v-model="current.data.oct" placeholder="多个字符用空格分隔"> <Input v-model="current.data.oct" :placeholder="$t('ascii_input_prompt')">
<div slot="prepend" style="width: 100px"><strong>八进制</strong></div> <div slot="prepend" style="width: 100px"><strong>{{ $t('ascii_input_8') }}</strong></div>
</Input> </Input>
</option-block> </option-block>
<option-block> <option-block>
<Input v-model="current.data.bin" placeholder="多个字符用空格分隔"> <Input v-model="current.data.bin" :placeholder="$t('ascii_input_prompt')">
<div slot="prepend" style="width: 100px"><strong>二进制</strong></div> <div slot="prepend" style="width: 100px"><strong>{{ $t('ascii_input_2') }}</strong></div>
</Input> </Input>
</option-block> </option-block>
<option-block> <option-block>
<Input v-model="current.data.str"> <Input v-model="current.data.str">
<div slot="prepend" style="width: 100px"><strong>字符串</strong></div> <div slot="prepend" style="width: 100px"><strong>{{ $t('ascii_input_string') }}</strong></div>
</Input> </Input>
</option-block> </option-block>
<option-block :style="{textAlign:'center'}"> <option-block :style="{textAlign:'center'}">
<FormItem> <FormItem>
<ButtonGroup> <ButtonGroup>
<Button type="primary" @click="handle()" style="margin-right: 5px">转换</Button> <Button type="primary" @click="handle()" style="margin-right: 5px">{{ $t('ascii_convent') }}</Button>
<Button type="primary" @click="clear()">清空</Button> <Button type="primary" @click="clear()">{{ $t('ascii_clear') }}</Button>
</ButtonGroup> </ButtonGroup>
</FormItem> </FormItem>
</option-block> </option-block>
</TabPane> </TabPane>
<TabPane label="编码表" name="reader"> <TabPane :label="$t('ascii_code_table')" name="reader">
<Table :columns="referenceColumns" :data="reference"> <Table :columns="referenceColumns" :data="reference">
</Table> </Table>
</TabPane> </TabPane>
...@@ -59,7 +59,7 @@ export default { ...@@ -59,7 +59,7 @@ export default {
oct:ob.oct(), oct:ob.oct(),
bin:ob.bin(), bin:ob.bin(),
str:ob.str(), str:ob.str(),
show:isShow ? "" : "", show:isShow ? this.$t('ascii_yes'): this.$t('ascii_no'),
explain:isShow ? ob.str() : ascii.ascii_hidden[ascii.ascii_map[index]] explain:isShow ? ob.str() : ascii.ascii_hidden[ascii.ascii_map[index]]
}) })
} }
...@@ -82,10 +82,12 @@ export default { ...@@ -82,10 +82,12 @@ export default {
} }
} }
if (!s){ if (!s){
throw "请输入对应的待转换编码" throw new Error(this.$t('ascii_input_null_prompt').toString())
} }
} catch (err) { } catch (err) {
return this.$Message.error("转换异常:" + err); return this.$Message.error(
this.$t('ascii_convent_error',[err.message]).toString()
);
} }
for (const type of this.types) { for (const type of this.types) {
this.current.data[type] = ascii.convent(s,currentType,type) this.current.data[type] = ascii.convent(s,currentType,type)
...@@ -113,40 +115,40 @@ export default { ...@@ -113,40 +115,40 @@ export default {
operation: "convent", operation: "convent",
referenceColumns: [ referenceColumns: [
{ {
title: '十进制', title: this.$t('ascii_input_10'),
key: 'dec', key: 'dec',
width:100 width:100
}, },
{ {
title: '十六进制', title: this.$t('ascii_input_16'),
key: 'hex', key: 'hex',
width:100 width:100
}, },
{ {
title: '八进制', title: this.$t('ascii_input_8'),
key: 'oct', key: 'oct',
width:100 width:100
}, },
{ {
title: '二进制', title: this.$t('ascii_input_2'),
key: 'bin', key: 'bin',
}, },
{ {
title: '字符', title: this.$t('ascii_input_string'),
key: 'str', key: 'str',
width:100 width:100
}, },
{ {
title: '是否可见', title: this.$t('ascii_is_show'),
key: 'show', key: 'show',
width:100 width:100
}, },
{ {
title: '字符说明', title: this.$t('ascii_description'),
key: 'explain', key: 'explain',
} }
], ],
} }
} }
} }
</script> </script>
\ No newline at end of file
...@@ -10,39 +10,39 @@ const ASCII_MAP = ['NUL', 'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS', ...@@ -10,39 +10,39 @@ const ASCII_MAP = ['NUL', 'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 'DEL'] 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 'DEL']
// ASCII 不可显示字符 // ASCII 不可显示字符
const ASCII_HIDDEN = { const ASCII_HIDDEN = {
'NUL': "空字符(Null)", 'NUL': __('ascii_code_nul'),
'SOH': "标题开始", 'SOH': __('ascii_code_soh'),
'STX': "本文开始", 'STX': __('ascii_code_stx'),
'ETX': "本文结束", 'ETX': __('ascii_code_etx'),
'EOT': "传输结束", 'EOT': __('ascii_code_eot'),
'ENQ': "请求", 'ENQ': __('ascii_code_enq'),
'ACK': "确认回应", 'ACK': __('ascii_code_ack'),
'BEL': "响铃", 'BEL': __('ascii_code_bel'),
'BS': "退格", 'BS': __('ascii_code_bs'),
'TAB': "水平定位符号", 'TAB': __('ascii_code_tab'),
'LF': "换行键", 'LF': __('ascii_code_lf'),
'VT': "垂直定位符号", 'VT': __('ascii_code_vt'),
'FF': "换页键", 'FF': __('ascii_code_ff'),
'CR': "归位键", 'CR': __('ascii_code_cr'),
'SO': "取消变换(Shift out)", 'SO': __('ascii_code_so'),
'SI': "启用变换(Shift in)", 'SI': __('ascii_code_si'),
'DLE': "跳出数据通讯", 'DLE': __('ascii_code_dle'),
'DC1': "设备控制一(XON 启用软件速度控制)", 'DC1': __('ascii_code_dc1'),
'DC2': "设备控制二", 'DC2': __('ascii_code_dc2'),
'DC3': "设备控制三(XOFF 停用软件速度控制)", 'DC3': __('ascii_code_dc3'),
'DC4': "设备控制四", 'DC4': __('ascii_code_dc4'),
'NAK': "确认失败回应", 'NAK': __('ascii_code_nak'),
'SYN': "同步用暂停", 'SYN': __('ascii_code_syn'),
'ETB': "区块传输结束", 'ETB': __('ascii_code_etb'),
'CAN': "取消", 'CAN': __('ascii_code_can'),
'EM': "连接介质中断", 'EM': __('ascii_code_em'),
'SUB': "替换", 'SUB': __('ascii_code_sub'),
'ESC': "跳出", 'ESC': __('ascii_code_esc'),
'FS': "文件分割符", 'FS': __('ascii_code_fs'),
'GS': "组群分隔符", 'GS': __('ascii_code_gs'),
'RS': "记录分隔符", 'RS': __('ascii_code_rs'),
'US': "单元分隔符", 'US': __('ascii_code_us'),
'DEL': "删除", 'DEL': __('ascii_code_del'),
} }
const radix = new Radix(); const radix = new Radix();
...@@ -50,7 +50,7 @@ class Ascii { ...@@ -50,7 +50,7 @@ class Ascii {
constructor(c, type = "str") { constructor(c, type = "str") {
let dec = -1; let dec = -1;
c = c + ""; c = c + "";
if (type !== "str"){ if (type !== "str") {
c = c.toLowerCase(); c = c.toLowerCase();
} }
switch (type) { switch (type) {
...@@ -95,7 +95,7 @@ class Ascii { ...@@ -95,7 +95,7 @@ class Ascii {
} }
str() { str() {
return ASCII_MAP[this.decData] return ASCII_MAP[this.decData] === " " ? __('ascii_code_space') : ASCII_MAP[this.decData]
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册