Skip to content

Commit 181faa4

Browse files
committed
feat: new disabled setting
1 parent a1c8261 commit 181faa4

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"config.derived_keys": "Rules to mark derived keys in the usage report",
4141
"config.dir_structure": "Preferred directory structure to organize locale files",
4242
"config.disable_path_parsing": "Disable path resolution",
43+
"config.disabled": "Disable i18n Ally for the project",
4344
"config.display_language": "Displaying language",
4445
"config.editor_prefer_editor": "Prefer to use webview editor for locale editing.",
4546
"config.enabled_frameworks": "Specify the supported framework(s) to enable. If no value is set, the extension will detect frameworks automatically.",

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,11 @@
654654
"type": "object",
655655
"title": "%extname%",
656656
"properties": {
657+
"i18n-ally.disabled": {
658+
"type": "boolean",
659+
"default": false,
660+
"description": "%config.disabled%"
661+
},
657662
"i18n-ally.localesPaths": {
658663
"type": [
659664
"string",

src/core/Config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { ExtractionHTMLOptions } from '~/extraction/parsers/options'
1111

1212
export class Config {
1313
static readonly reloadConfigs = [
14+
'disabled',
1415
'localesPaths',
1516
'pathMatcher',
1617
'includeSubfolders',
@@ -45,6 +46,10 @@ export class Config {
4546
static ctx: ExtensionContext
4647
static readonly debug = process.env.NODE_ENV === 'development'
4748

49+
static get disabled() {
50+
return Config.getConfig<boolean>('disabled') ?? true
51+
}
52+
4853
// languages
4954
static get displayLanguage(): string {
5055
return this.normalizeLocale(Config.getConfig<string>('displayLanguage') || '')

src/core/Global.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ export class Global {
3838
static async init(context: ExtensionContext) {
3939
this.context = context
4040

41-
context.subscriptions.push(workspace.onDidChangeWorkspaceFolders(e => this.updateRootPath()))
42-
context.subscriptions.push(window.onDidChangeActiveTextEditor(e => this.updateRootPath()))
43-
context.subscriptions.push(workspace.onDidOpenTextDocument(e => this.updateRootPath()))
44-
context.subscriptions.push(workspace.onDidCloseTextDocument(e => this.updateRootPath()))
41+
context.subscriptions.push(workspace.onDidChangeWorkspaceFolders(() => this.updateRootPath()))
42+
context.subscriptions.push(window.onDidChangeActiveTextEditor(() => this.updateRootPath()))
43+
context.subscriptions.push(workspace.onDidOpenTextDocument(() => this.updateRootPath()))
44+
context.subscriptions.push(workspace.onDidCloseTextDocument(() => this.updateRootPath()))
4545
context.subscriptions.push(workspace.onDidChangeConfiguration(e => this.update(e)))
4646
await this.updateRootPath()
4747
}
@@ -169,7 +169,7 @@ export class Global {
169169
.flatMap(f => [
170170
f.supportedExts,
171171
Object.entries(Config.parsersExtendFileExtensions)
172-
.find(([k, v]) => v === f.id)?.[0],
172+
.find(([, v]) => v === f.id)?.[0],
173173
])
174174
.filter(Boolean)
175175
.join('|')
@@ -323,9 +323,9 @@ export class Global {
323323
const frameworks = Config.enabledFrameworks
324324
this.enabledFrameworks = getEnabledFrameworksByIds(frameworks, this._rootpath)
325325
}
326-
const isValidProject = this.enabledFrameworks.length > 0
326+
const isValidProject = this.enabledFrameworks.length > 0 && this.enabledParsers.length > 0
327327
const hasLocalesSet = Global.localesPaths.length > 0
328-
const shouldEnabled = isValidProject && hasLocalesSet
328+
const shouldEnabled = !Config.disabled && isValidProject && hasLocalesSet
329329
this.setEnabled(shouldEnabled)
330330

331331
if (this.enabled) {
@@ -335,13 +335,15 @@ export class Global {
335335
await this.initLoader(this._rootpath, reload)
336336
}
337337
else {
338-
if (!isValidProject)
339-
Log.info('⚠ Current workspace is not a valid project, extension disabled')
340-
else if (!hasLocalesSet)
341-
Log.info('⚠ No locales path setting found, extension disabled')
342-
343-
if (isValidProject && !hasLocalesSet)
344-
ConfigLocalesGuide.autoSet()
338+
if (!Config.disabled) {
339+
if (!isValidProject)
340+
Log.info('⚠ Current workspace is not a valid project, extension disabled')
341+
else if (!hasLocalesSet)
342+
Log.info('⚠ No locales path setting found, extension disabled')
343+
344+
if (isValidProject && !hasLocalesSet)
345+
ConfigLocalesGuide.autoSet()
346+
}
345347

346348
this.unloadAll()
347349
}

0 commit comments

Comments
 (0)