Skip to content

Commit cecdbb8

Browse files
committed
feat: update locale file and change i18n funtion name
1 parent 5626991 commit cecdbb8

File tree

4 files changed

+51
-45
lines changed

4 files changed

+51
-45
lines changed

src/locale/locale.json

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/locale/locale.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const zh_CN = {
2+
stmtInComplete: '语句不完整',
3+
noValidPosition: '在此位置无效',
4+
expecting: ',期望',
5+
unfinishedMultilineComment: '未完成的多行注释',
6+
unfinishedDoubleQuoted: '未完成的双引号字符串字变量',
7+
unfinishedSingleQuoted: '未完成的单引号字符串字变量',
8+
unfinishedTickQuoted: '未完成的反引号引用字符串字变量',
9+
noValidInput: '没有有效的输入',
10+
newObj: '一个新的对象',
11+
existingObj: '一个存在的对象',
12+
new: '一个新的',
13+
existing: '一个存在的',
14+
orKeyword: '或者一个关键字',
15+
keyword: '一个关键字',
16+
missing: '缺少',
17+
at: '在',
18+
or: '或者',
19+
};
20+
21+
const en_US: typeof zh_CN = {
22+
stmtInComplete: 'Statement is incomplete',
23+
noValidPosition: 'is not valid at this position',
24+
expecting: ', expecting ',
25+
unfinishedMultilineComment: 'Unfinished multiline comment',
26+
unfinishedDoubleQuoted: 'Unfinished double quoted string literal',
27+
unfinishedSingleQuoted: 'Unfinished single quoted string literal',
28+
unfinishedTickQuoted: 'Unfinished back tick quoted string literal',
29+
noValidInput: 'is no valid input at all',
30+
newObj: 'a new object',
31+
existingObj: 'an existing object',
32+
new: 'a new ',
33+
existing: 'an existing ',
34+
orKeyword: ' or a keyword',
35+
keyword: 'a keyword',
36+
missing: 'missing ',
37+
at: ' at ',
38+
or: ' or ',
39+
};
40+
41+
const i18n = {
42+
zh_CN,
43+
en_US,
44+
};
45+
46+
export { i18n };

src/parser/common/parseErrorListener.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
NoViableAltException,
1212
} from 'antlr4ng';
1313
import { LOCALE_TYPE } from './types';
14-
import { transformToI18n } from './transformToI18n';
14+
import { transform } from './transform';
1515

1616
/**
1717
* Converted from {@link SyntaxError}.
@@ -151,7 +151,7 @@ export abstract class ParseErrorListener implements ANTLRErrorListener {
151151
}
152152
}
153153
}
154-
message = transformToI18n(message, this.locale);
154+
message = transform(message, this.locale);
155155
let endCol = charPositionInLine + 1;
156156
if (offendingSymbol && offendingSymbol.text !== null) {
157157
endCol = charPositionInLine + offendingSymbol.text.length;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { LOCALE_TYPE } from './types';
2-
import i18n from '../../locale/locale.json';
2+
import { i18n } from '../../locale/locale';
33

44
/**
55
* transform message to locale language
66
* @param message error msg
77
* @param locale language setting
88
*/
9-
function transformToI18n(message: string, locale: LOCALE_TYPE) {
9+
function transform(message: string, locale: LOCALE_TYPE) {
1010
const regex = /{([^}]+)}/g;
1111
return message.replace(
1212
regex,
1313
(_, key: keyof (typeof i18n)[typeof locale]) => i18n[locale][key] || ''
1414
);
1515
}
1616

17-
export { transformToI18n };
17+
export { transform };

0 commit comments

Comments
 (0)