|
2 | 2 | * @Author : Robert Huang<56649783@qq.com> * |
3 | 3 | * @CreatedDate : 2023-02-04 10:01:21 * |
4 | 4 | * @LastEditors : Robert Huang<56649783@qq.com> * |
5 | | - * @LastEditDate : 2023-02-05 18:48:28 * |
| 5 | + * @LastEditDate : 2023-02-05 23:16:41 * |
6 | 6 | * @FilePath : emoji-commit/src/extension.ts * |
7 | 7 | * @CopyRight : MerBleueAviation * |
8 | 8 | *****************************************************************************/ |
9 | 9 |
|
10 | 10 | // The module 'vscode' contains the VS Code extensibility API |
11 | 11 | // Import the module and reference it with the alias vscode in your code below |
| 12 | +import i18next from 'i18next' |
12 | 13 | import * as vscode from 'vscode' |
| 14 | +import l10nEn from '../l10n/bundle.l10n.json' |
| 15 | +import l10nZh from '../l10n/bundle.l10n.zh-cn.json' |
13 | 16 | import packageJson from '../package.json' |
14 | 17 | import { Logger } from './logger' |
15 | 18 | import { emojiCommit } from './utils' |
16 | 19 |
|
17 | 20 | const config = vscode.workspace.getConfiguration(packageJson.name) |
18 | | -console.debug(config) |
| 21 | +// console.debug(config) |
19 | 22 |
|
20 | 23 | const logger = new Logger() |
21 | 24 | logger.setOutputLevel(config.get('logLevel', 'INFO')) |
22 | 25 |
|
23 | | -export { config, logger } |
| 26 | +// i18next |
| 27 | +const i18nResources = { |
| 28 | + en: { |
| 29 | + translation: l10nEn |
| 30 | + }, |
| 31 | + // eslint-disable-next-line @typescript-eslint/naming-convention |
| 32 | + 'zhcn': { |
| 33 | + translation: l10nZh |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +// lang can't be zh-cn, it should be zhcn |
| 38 | +const locale = vscode.env.language.replace('-', '') |
| 39 | +logger.info(`locale: ${locale}`) |
| 40 | +i18next.init({ |
| 41 | + lng: locale, |
| 42 | + fallbackLng: 'en', |
| 43 | + resources: i18nResources |
| 44 | +}) |
| 45 | + |
| 46 | +export { config, logger, i18next } |
24 | 47 |
|
25 | 48 | // This method is called when your extension is activated |
26 | 49 | // Your extension is activated the very first time the command is executed |
|
0 commit comments