diff --git a/CHANGELOG.md b/CHANGELOG.md index 3646174..bd87164 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to the react-i18n-prompt extension will be documented in this file. +### [0.0.4] + +- [bugfix]: can not get text when i18n key in array in language package file. +- [bugfix]: can not get script plugin for error workspace path in windows operator system. +- [feature]: change the `react-i18n-prompt.language-package-exclude-path` to support multiple path which separated by ';' + ### [0.0.3] - [bugfix]: the link of i18n key is not working in windows operator system. diff --git a/package.json b/package.json index 829a6d7..2eb1956 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "react-i18n-prompt", "displayName": "React I18n Prompt Tool", "description": "i18n prompt tool, show language of i18n key, add link to i18n key, prompt i18n key when user input i18n key", - "version": "0.0.3", + "version": "0.0.4", "publisher": "Rain", "engines": { "vscode": "^1.58.0" @@ -45,7 +45,8 @@ }, "react-i18n-prompt.language-package-exclude-path": { "type": "string", - "default": "src/locale/zh-cn/**/index.{ts,js,tsx,jsx}" + "default": "src/locale/zh-cn/**/index.{ts,js,tsx,jsx}", + "description": "Multiple paths can be entered separated by ';'" }, "react-i18n-prompt.language-key-prefix": { "type": "string", diff --git a/src/core/core.ts b/src/core/core.ts index f3e077a..122c283 100644 --- a/src/core/core.ts +++ b/src/core/core.ts @@ -63,6 +63,17 @@ class Core { VscodeEvent.insertI18nChinese(this._activeEditor, paramsLocations); } + public filterSameUris(originUris: vscode.Uri[], filterUris: vscode.Uri[]) { + let filterResult: vscode.Uri[] = []; + for (const filterItem of filterUris) { + const sameUri = originUris.find( + (originItem) => originItem.path === filterItem.path + ); + if (!!sameUri) filterResult.push(filterItem); + } + return filterResult; + } + public async findAllLanguageDictionary() { this._statusBarItem.notify('eye', 'Looking for i18n path...', false); const pluginFind = plugin.getAllI18nKeyAndValue(); @@ -88,10 +99,18 @@ class Core { } this._languageDictionary = new Map(); this._languageFile = new Map(); - const uris = await VscodeEvent.getFiles( - config.localePath, - config.localeExcludePath - ); + let uris: vscode.Uri[] = []; + const localeExcludePathArray = config.localeExcludePath.split(';'); + for (const excludePath of localeExcludePathArray) { + const currentUris = await VscodeEvent.getFiles( + config.localePath, + excludePath + ); + uris = this.filterSameUris( + uris.length === 0 ? [...currentUris] : [...uris], + currentUris + ); + } for (const uri of uris) { const fileContent = await fs.promises.readFile(uri.fsPath); const ast = this._astTool.parse(fileContent.toString()); diff --git a/src/event/VscodeEvent.ts b/src/event/VscodeEvent.ts index 11847af..01dc338 100644 --- a/src/event/VscodeEvent.ts +++ b/src/event/VscodeEvent.ts @@ -99,7 +99,7 @@ class VscodeEvent { if (!temp || temp.length === 0) { return; } - return temp[0].uri.path; + return temp[0].uri.fsPath; } public watchFileChanged(path: string) { diff --git a/src/tool/AstTool.ts b/src/tool/AstTool.ts index 577459f..1ea93a1 100644 --- a/src/tool/AstTool.ts +++ b/src/tool/AstTool.ts @@ -172,6 +172,22 @@ class AstTool { newKey, dictionary ); + } else if (this.isArrayExpression(property.value)) { + let newKey = key; + if (prefix.length > 0) { + newKey = `${prefix}.${newKey}`; + } + (property.value as t.ArrayExpression).elements.forEach( + (element, index) => { + if (element) { + this.getAllI18nKeyAndValueFromObject( + element as t.ObjectExpression, + `${newKey}.${index}`, + dictionary + ); + } + } + ); } else if (this.isStringLiteral(property.value)) { let value = property.value.value; if (value.includes('\n') || value.includes('\r')) { @@ -228,6 +244,10 @@ class AstTool { private isObjectExpression(node: t.Node): node is t.ObjectExpression { return t.isObjectExpression(node); } + + private isArrayExpression(node: t.Node): node is t.ObjectExpression { + return t.isArrayExpression(node); + } } export default AstTool;