Skip to content

Commit

Permalink
feat: continue auto detection configuration, close #523
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Apr 7, 2021
1 parent be2a94c commit d90b065
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/by-features/extractions/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"i18n-ally.localesPaths": "locales",
"i18n-ally.sourceLanguage": "en",
"i18n-ally.keystyle": "nested",
"i18n-ally.extract.autoDetect": true,
"i18n-ally.translate.saveAsCandidates": true,
}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,11 @@
"default": {},
"description": "Parser options for extracting HTML, see https://github.com/lokalise/i18n-ally/blob/master/src/extraction/parsers/options.ts"
},
"i18n-ally.extract.autoDetect": {
"type": "boolean",
"default": false,
"description": "Enables hard-coded strings detection automatically whenever opening supported a file"
},
"i18n-ally.parserOptions": {
"type": "object"
},
Expand Down
4 changes: 4 additions & 0 deletions src/core/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@ export class Config {
return this.getConfig<number>('extract.keyMaxLength') ?? Infinity
}

static get extractAutoDetect() {
return this.getConfig<boolean>('extract.autoDetect') ?? false
}

static get extractParserHTMLOptions() {
return this.getConfig<ExtractionHTMLOptions>('extract.parsers.html') ?? {}
}
Expand Down
12 changes: 8 additions & 4 deletions src/views/items/CurrentFileExtractionItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CurrentFileLocalesTreeProvider } from '../providers'
import { BaseTreeItem } from './Base'
import { HardStringDetectResultItem } from './HardStringDetectResultItem'
import i18n from '~/i18n'
import { CurrentFile, Global } from '~/core'
import { Config, CurrentFile, Global } from '~/core'
import { DetectionResult } from '~/extraction'

export class CurrentFileExtractionItem extends BaseTreeItem {
Expand All @@ -16,10 +16,14 @@ export class CurrentFileExtractionItem extends BaseTreeItem {
this.contextValue = 'i18n-ally-hard-string-root'

this.langId = window.activeTextEditor?.document.languageId || 'unknown'
if (this.langId && Global.getExtractionFrameworksByLang(this.langId).length)
this.collapsibleState = TreeItemCollapsibleState.Collapsed
else
if (this.langId && Global.getExtractionFrameworksByLang(this.langId).length) {
this.collapsibleState = Config.extractAutoDetect
? TreeItemCollapsibleState.Expanded
: TreeItemCollapsibleState.Collapsed
}
else {
this.collapsibleState = TreeItemCollapsibleState.None
}
this.updateDescription()
}

Expand Down

0 comments on commit d90b065

Please sign in to comment.