diff --git a/src/commands/extractText.ts b/src/commands/extractText.ts index 1179cd0b..f67a50ce 100644 --- a/src/commands/extractText.ts +++ b/src/commands/extractText.ts @@ -1,50 +1,51 @@ // @ts-ignore -import * as limax from 'limax' +// import * as limax from 'limax' import { commands, window, workspace } from 'vscode' import { trim } from 'lodash' import { ExtensionModule } from '../modules' -import { ExtractTextOptions, Global, Commands, Config, CurrentFile } from '../core' +// import { ExtractTextOptions, Global, Commands, Config, CurrentFile } from '../core' +import { ExtractTextOptions, Global, Commands } from '../core' import i18n from '../i18n' -import { overrideConfirm } from './overrideConfirm' -import { keypathValidate } from './keypathValidate' +// import { overrideConfirm } from './overrideConfirm' +// import { keypathValidate } from './keypathValidate' const m: ExtensionModule = () => { return commands.registerCommand(Commands.extract_text, async (options: ExtractTextOptions) => { const { filepath, text, range, languageId } = options - const default_keypath = limax(text, { separator: Config.preferredDelimiter, tone: false }) as string - const locale = Config.sourceLanguage + // const default_keypath = limax(text, { separator: Config.preferredDelimiter, tone: false }) as string + // const locale = Config.sourceLanguage // prompt for keypath - const keypath = await window.showInputBox({ - prompt: i18n.t('prompt.enter_i18n_key'), - value: default_keypath, - }) + // const keypath = await window.showInputBox({ + // prompt: i18n.t('prompt.enter_i18n_key'), + // value: default_keypath, + // }) - if (!keypath) { - window.showWarningMessage(i18n.t('prompt.extraction_canceled')) - return - } + // if (!keypath) { + // window.showWarningMessage(i18n.t('prompt.extraction_canceled')) + // return + // } - if (!keypathValidate(keypath)) - return window.showWarningMessage(i18n.t('prompt.invalid_keypath')) + // if (!keypathValidate(keypath)) + // return window.showWarningMessage(i18n.t('prompt.invalid_keypath')) - const writeKeypath = CurrentFile.loader.rewriteKeys(keypath, 'write', { locale }) + // const writeKeypath = CurrentFile.loader.rewriteKeys(keypath, 'write', { locale }) - const shouldOverride = await overrideConfirm(writeKeypath, true, true) + // const shouldOverride = await overrideConfirm(writeKeypath, true, true) - if (shouldOverride === 'retry') { - commands.executeCommand(Commands.extract_text, options) - return - } - if (shouldOverride === 'canceled') - return + // if (shouldOverride === 'retry') { + // commands.executeCommand(Commands.extract_text, options) + // return + // } + // if (shouldOverride === 'canceled') + // return const value = trim(text, '\'"') // prompt for template const replacer = await window.showQuickPick( - Global.refactorTemplates(keypath, languageId), + Global.refactorTemplates('', languageId, value), { placeHolder: i18n.t('prompt.replace_text_as'), }) @@ -64,16 +65,16 @@ const m: ExtensionModule = () => { editBuilder.replace(range, replacer) }) - if (shouldOverride === 'skip') - return + // if (shouldOverride === 'skip') + // return // save key - await CurrentFile.loader.write({ - filepath: undefined, - keypath: writeKeypath, - value, - locale, - }) + // await CurrentFile.loader.write({ + // filepath: undefined, + // keypath: writeKeypath, + // value, + // locale, + // }) }) } diff --git a/src/commands/manipulations/index.ts b/src/commands/manipulations/index.ts index 4d1746e5..91d66e44 100644 --- a/src/commands/manipulations/index.ts +++ b/src/commands/manipulations/index.ts @@ -4,6 +4,6 @@ export * from './copyKey' export * from './renameKey' export * from './deleteKey' export * from './editKey' -export * from './fulfillkeys' +export * from './fulfillKeys' export * from './newKey' export * from './duplicateKey' diff --git a/src/core/Global.ts b/src/core/Global.ts index 636e6d01..36458efc 100644 --- a/src/core/Global.ts +++ b/src/core/Global.ts @@ -56,8 +56,8 @@ export class Global { .flatMap(f => f.getKeyMatchReg(languageId, filepath)) } - static refactorTemplates (keypath: string, languageId?: string) { - return uniq(this.enabledFrameworks.flatMap(f => f.refactorTemplates(keypath, languageId))) + static refactorTemplates (keypath: string, languageId?: string, content?: string) { + return uniq(this.enabledFrameworks.flatMap(f => f.refactorTemplates(keypath, languageId, content))) } static isLanguageIdSupported (languageId: string) { diff --git a/src/frameworks/base.ts b/src/frameworks/base.ts index 5c033c61..54ba92ac 100644 --- a/src/frameworks/base.ts +++ b/src/frameworks/base.ts @@ -34,7 +34,7 @@ export abstract class Framework { /** * Return possible choices of replacement for messages extracted from code */ - abstract refactorTemplates (keypath: string, languageId?: string): string[] + abstract refactorTemplates (keypath: string, languageId?: string, content?: string): string[] /** * Locale file's name match diff --git a/src/frameworks/custom/index.ts b/src/frameworks/custom/index.ts index c3ec9d6c..3a43cec5 100644 --- a/src/frameworks/custom/index.ts +++ b/src/frameworks/custom/index.ts @@ -84,9 +84,9 @@ class CustomFramework extends Framework { return this.data?.monopoly || false } - refactorTemplates (keypath: string) { + refactorTemplates (keypath: string, languageId?: string, content?: string) { return (this.data?.refactorTemplates || ['$1']) - .map(i => i.replace(/\$1/g, keypath)) + .map(i => i.replace(/\$1/g, content || '')) } startWatch (root?: string) {