import { TextDocument } from 'vscode' import { Framework, ScopeRange } from './base' import { LanguageId } from '~/utils' import { extractionsParsers, DefaultExtractionRules, DefaultDynamicExtractionsRules } from '~/extraction' import { Config, RewriteKeySource, RewriteKeyContext } from '~/core' class ReactI18nextFramework extends Framework { id = 'react-i18next' display = 'React I18next' namespaceDelimiter = ':' // both `/` and `:` should work as delimiter, #425 namespaceDelimiters = [':', '/'] namespaceDelimitersRegex = /[:/]/g detection = { packageJSON: [ 'react-i18next', 'next-i18next', ], } languageIds: LanguageId[] = [ 'javascript', 'typescript', 'javascriptreact', 'typescriptreact', 'ejs', ] // for visualize the regex, you can use https://regexper.com/ usageMatchRegex = [ '\\Wt\\(\\s*[\'"`]({key})[\'"`]', '\\Wi18nKey=[\'"`]({key})[\'"`]', ] supportAutoExtraction = [ 'javascript', 'typescript', 'javascriptreact', 'typescriptreact', 'html', ] derivedKeyRules = [ '{key}_plural', '{key}_0', '{key}_1', '{key}_2', '{key}_3', '{key}_4', '{key}_5', '{key}_6', '{key}_7', '{key}_8', '{key}_9', // support v4 format as well as v3 '{key}_zero', '{key}_one', '{key}_two', '{key}_few', '{key}_many', '{key}_other', ] detectHardStrings(doc: TextDocument) { const lang = doc.languageId const text = doc.getText() if (lang === 'html') { return extractionsParsers.html.detect( text, DefaultExtractionRules, DefaultDynamicExtractionsRules, Config.extractParserHTMLOptions, //