Skip to content

Commit a9ca8ca

Browse files
committed
feat: allow toggle i18n-ally.extract.autoDetect from UI, close #591
1 parent 33f339b commit a9ca8ca

19 files changed

+85
-1
lines changed

Diff for: locales/de.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"command.delete_key": "Schlüssel löschen",
99
"command.duplicate_key": "Schlüssel kopieren",
1010
"command.edit_key": "Übersetzung bearbeiten",
11+
"command.extract.disable-auto-detect": "",
12+
"command.extract.enable-auto-detect": "",
1113
"command.fulfill_keys": "Vervollständige Schlüssel mit leeren Texten",
1214
"command.go_to_range": "",
1315
"command.insert_key": "Schlüssel einfügen",
@@ -32,6 +34,7 @@
3234
"config.annotation_in_place": "Zeige Hinweise im Text",
3335
"config.annotation_max_length": "Maximale Zeichenlänge für Hinweise die im Text angezeigt werden. Abgeschnitte Zeichen werden als (...) angezeigt",
3436
"config.annotations": "Hinweise im Text aktivieren",
37+
"config.auto_detection": "",
3538
"config.deepl_api_key": "API key für die DeepL translate engine",
3639
"config.deepl_log": "DeepL debug logs anzeigen",
3740
"config.deepl_use_free_api_entry": "",

Diff for: locales/en.json

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"command.delete_key": "Delete key",
99
"command.duplicate_key": "Duplicate key",
1010
"command.edit_key": "Edit translation",
11+
"command.extract.disable-auto-detect": "Disable hard-coded strings auto detection",
12+
"command.extract.enable-auto-detect": "Enable hard-coded strings auto detection",
1113
"command.fulfill_keys": "Fulfill keys with empty strings",
1214
"command.go_to_range": "Go to range",
1315
"command.insert_key": "Insert key",

Diff for: locales/es.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"command.delete_key": "Eliminar clave",
99
"command.duplicate_key": "Duplicar clave",
1010
"command.edit_key": "Editar traducción",
11+
"command.extract.disable-auto-detect": "",
12+
"command.extract.enable-auto-detect": "",
1113
"command.fulfill_keys": "Rellenar claves con cadena vacía",
1214
"command.go_to_range": "",
1315
"command.insert_key": "Insertar clave",
@@ -32,6 +34,7 @@
3234
"config.annotation_in_place": "Mostrar la anotación en su lugar en vez de agregar a la cola",
3335
"config.annotation_max_length": "Máximo número de caracteres que se mostrarán en las anotaciones en línea. Los restantes se mostrarán como elipses (...)",
3436
"config.annotations": "Habilitar las anotaciones en línea.",
37+
"config.auto_detection": "",
3538
"config.deepl_api_key": "API key para el traductor DeepL",
3639
"config.deepl_log": "Mostrar mensajes de depuración del motor DeepL",
3740
"config.deepl_use_free_api_entry": "",

Diff for: locales/fr.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"command.delete_key": "Supprimer une Clé",
99
"command.duplicate_key": "Dupliquer une Clé",
1010
"command.edit_key": "Modifier la traduction",
11+
"command.extract.disable-auto-detect": "",
12+
"command.extract.enable-auto-detect": "",
1113
"command.fulfill_keys": "Remplir les champs vides de Clés",
1214
"command.go_to_range": "Aller à la plage",
1315
"command.insert_key": "Insérer une clé",
@@ -32,6 +34,7 @@
3234
"config.annotation_in_place": "Montrer une annotation sur place au lieu d'ajouter dans la queue",
3335
"config.annotation_max_length": "Nombre maximum de caractères à afficher dans les annotations. Le surplus sera affiché sous forme d'ellipse (...)",
3436
"config.annotations": "Activer les annotations.",
37+
"config.auto_detection": "",
3538
"config.deepl_api_key": "Clé API pour utiliser le moteur de traduction DeepL",
3639
"config.deepl_log": "Montrer le journal de debug du moteur DeepL",
3740
"config.deepl_use_free_api_entry": "Utiliser le point d'entrée gratuite de DeepL",

Diff for: locales/ja.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"command.delete_key": "i18nキーを削除する",
99
"command.duplicate_key": "",
1010
"command.edit_key": "翻訳を編集する",
11+
"command.extract.disable-auto-detect": "",
12+
"command.extract.enable-auto-detect": "",
1113
"command.fulfill_keys": "空文字でキーを埋める",
1214
"command.go_to_range": "",
1315
"command.insert_key": "",
@@ -32,6 +34,7 @@
3234
"config.annotation_in_place": "",
3335
"config.annotation_max_length": "インラインアノテーションの最大文字数です。超過している部分は(...)と表示されます。",
3436
"config.annotations": "インラインアノテーションを有効にする.",
37+
"config.auto_detection": "",
3538
"config.deepl_api_key": "",
3639
"config.deepl_log": "",
3740
"config.deepl_use_free_api_entry": "",

Diff for: locales/nb-NO.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"command.delete_key": "Slett nøkkel",
99
"command.duplicate_key": "",
1010
"command.edit_key": "Rediger oversettelse",
11+
"command.extract.disable-auto-detect": "",
12+
"command.extract.enable-auto-detect": "",
1113
"command.fulfill_keys": "",
1214
"command.go_to_range": "",
1315
"command.insert_key": "",
@@ -32,6 +34,7 @@
3234
"config.annotation_in_place": "",
3335
"config.annotation_max_length": "Maksimalt antall tegn vist i hjelpevindu. Resterende del vil bli vist som (...)",
3436
"config.annotations": "Slå på hjelpevindu",
37+
"config.auto_detection": "",
3538
"config.deepl_api_key": "",
3639
"config.deepl_log": "",
3740
"config.deepl_use_free_api_entry": "",

Diff for: locales/nl-NL.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"command.delete_key": "Verwijder sleutel",
99
"command.duplicate_key": "Dupliceer sleutel",
1010
"command.edit_key": "Bewerk vertaling",
11+
"command.extract.disable-auto-detect": "",
12+
"command.extract.enable-auto-detect": "",
1113
"command.fulfill_keys": "Sleutels met lege waarden aanvullen",
1214
"command.go_to_range": "",
1315
"command.insert_key": "",
@@ -32,6 +34,7 @@
3234
"config.annotation_in_place": "",
3335
"config.annotation_max_length": "Max. aantal karakters zichtbaar binnen inline annotaties. Overschreden delen worden getoond als ellipses (...)",
3436
"config.annotations": "Inline annotaties inschakelen.",
37+
"config.auto_detection": "",
3538
"config.deepl_api_key": "",
3639
"config.deepl_log": "",
3740
"config.deepl_use_free_api_entry": "",

Diff for: locales/pt-BR.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"command.delete_key": "Deletar chave",
99
"command.duplicate_key": "Duplicar chave",
1010
"command.edit_key": "Editar tradução",
11+
"command.extract.disable-auto-detect": "",
12+
"command.extract.enable-auto-detect": "",
1113
"command.fulfill_keys": "Preencher chaves com strings vazias",
1214
"command.go_to_range": "",
1315
"command.insert_key": "",
@@ -32,6 +34,7 @@
3234
"config.annotation_in_place": "",
3335
"config.annotation_max_length": "Número máximo de caracteres exibidos nas anotações inline. O restante será exibido em forma de reticências (...)",
3436
"config.annotations": "Habilitar anotações inline",
37+
"config.auto_detection": "",
3538
"config.deepl_api_key": "",
3639
"config.deepl_log": "",
3740
"config.deepl_use_free_api_entry": "",

Diff for: locales/ru.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"command.delete_key": "Удалить ключ",
99
"command.duplicate_key": "Повторяющийся ключ",
1010
"command.edit_key": "Редактировать перевод",
11+
"command.extract.disable-auto-detect": "",
12+
"command.extract.enable-auto-detect": "",
1113
"command.fulfill_keys": "Заполнять ключ пустой строкой",
1214
"command.go_to_range": "",
1315
"command.insert_key": "Вставить ключ",
@@ -32,6 +34,7 @@
3234
"config.annotation_in_place": "Показывать аннотацию на месте вместо добавления в конец",
3335
"config.annotation_max_length": "Максимальное количество символов, отображаемых во встроенных аннотациях. Лишние символы будут отображаться в виде многоточия (...)",
3436
"config.annotations": "Включить встроенные аннотации.",
37+
"config.auto_detection": "",
3538
"config.deepl_api_key": "API ключ для использования DeepL",
3639
"config.deepl_log": "Отображать отладочные журналы DeepL",
3740
"config.deepl_use_free_api_entry": "",

Diff for: locales/sv-SE.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"command.delete_key": "Ta bort nyckel",
99
"command.duplicate_key": "Duplicera nyckel",
1010
"command.edit_key": "Ändra översättning",
11+
"command.extract.disable-auto-detect": "",
12+
"command.extract.enable-auto-detect": "",
1113
"command.fulfill_keys": "Skapa saknade nycklar med tomma strängar",
1214
"command.go_to_range": "",
1315
"command.insert_key": "Lägg till nyckel",
@@ -32,6 +34,7 @@
3234
"config.annotation_in_place": "Visa anteckningar på plats istället för att vidhänga på slutet",
3335
"config.annotation_max_length": "Max antal bokstävers som visas i insatta anteckningen. Överflödiga bokstäver kommer visas som en ellips (…)",
3436
"config.annotations": "Aktivera insatta anteckningar.",
37+
"config.auto_detection": "",
3538
"config.deepl_api_key": "",
3639
"config.deepl_log": "",
3740
"config.deepl_use_free_api_entry": "",

Diff for: locales/tr.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"command.delete_key": "Çeviriyi sil",
99
"command.duplicate_key": "Çeviriyi klonla",
1010
"command.edit_key": "Çeviriyi düzenle",
11+
"command.extract.disable-auto-detect": "",
12+
"command.extract.enable-auto-detect": "",
1113
"command.fulfill_keys": "Boş bırakılmış çevirileri doldur",
1214
"command.go_to_range": "Aralığa git",
1315
"command.insert_key": "Çeviri ekle",
@@ -32,6 +34,7 @@
3234
"config.annotation_in_place": "Ek açıklamaları kuyruğa eklemek yerine olduğu yerde göster",
3335
"config.annotation_max_length": "Satır aralığında gösterilen ek açıklamaların maksimum karakter uzunluğu. Fazladan karakterler noktalı şekilde görüntülenecektir (...)",
3436
"config.annotations": "Satır aralığında ek açıklamaları etkinleştir",
37+
"config.auto_detection": "",
3538
"config.deepl_api_key": "DeepL çeviri sistemini kullanmak için API anahtarı",
3639
"config.deepl_log": "DeepL sisteminin hata ayıklama kayıtlarını göster",
3740
"config.deepl_use_free_api_entry": "DeepL'in Bedava API giriş noktasını kullanın",

Diff for: locales/uk-UA.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"command.delete_key": "Видалити ключ",
99
"command.duplicate_key": "Дублікат ключа",
1010
"command.edit_key": "Редагувати переклад",
11+
"command.extract.disable-auto-detect": "",
12+
"command.extract.enable-auto-detect": "",
1113
"command.fulfill_keys": "Заповнювати ключ порожній рядком",
1214
"command.go_to_range": "",
1315
"command.insert_key": "Вставити ключ",
@@ -32,6 +34,7 @@
3234
"config.annotation_in_place": "Показувати анотацію на місці замість додавання в кінець",
3335
"config.annotation_max_length": "Максимальна кількість символів, що відображаються у вбудованих анотаціях. Зайві символи будуть відображатися у вигляді трьох крапок (...)",
3436
"config.annotations": "Включити вбудовані анотації.",
37+
"config.auto_detection": "",
3538
"config.deepl_api_key": "Ключ для використання API DeepL",
3639
"config.deepl_log": "Відображати налагоджувальні журнали DeepL",
3740
"config.deepl_use_free_api_entry": "",

Diff for: locales/zh-CN.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"command.delete_key": "删除路径",
99
"command.duplicate_key": "建立副本",
1010
"command.edit_key": "编辑文案",
11+
"command.extract.disable-auto-detect": "",
12+
"command.extract.enable-auto-detect": "",
1113
"command.fulfill_keys": "使用空字符串填充文案路径",
1214
"command.go_to_range": "",
1315
"command.insert_key": "插入i18n文案",
@@ -32,6 +34,7 @@
3234
"config.annotation_in_place": "在路径原位显示翻译文案,而不是附加在末尾",
3335
"config.annotation_max_length": "内联注释显示的最大字符数。超出的部分将显示为省略号(...)",
3436
"config.annotations": "启用内联注释",
37+
"config.auto_detection": "",
3538
"config.deepl_api_key": "",
3639
"config.deepl_log": "",
3740
"config.deepl_use_free_api_entry": "",

Diff for: locales/zh-TW.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"command.delete_key": "刪除路徑",
99
"command.duplicate_key": "建立副本",
1010
"command.edit_key": "編輯文案",
11+
"command.extract.disable-auto-detect": "",
12+
"command.extract.enable-auto-detect": "",
1113
"command.fulfill_keys": "使用空字串填充文案路徑",
1214
"command.go_to_range": "",
1315
"command.insert_key": "插入i18n文案",
@@ -32,6 +34,7 @@
3234
"config.annotation_in_place": "在路徑原位顯示翻譯文案,而不是附加在末尾",
3335
"config.annotation_max_length": "內聯註釋顯示的最大文字數。超出的部分將顯示為省略號(...)",
3436
"config.annotations": "啟用內聯註釋",
37+
"config.auto_detection": "",
3538
"config.deepl_api_key": "",
3639
"config.deepl_log": "",
3740
"config.deepl_use_free_api_entry": "",

Diff for: package.json

+28
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,16 @@
370370
"category": "%extname%",
371371
"title": "%command.show_docs%",
372372
"icon": "$(question)"
373+
},
374+
{
375+
"command": "i18n-ally.extract-disable-auto-detect",
376+
"category": "%extname%",
377+
"title": "%command.extract.disable-auto-detect%"
378+
},
379+
{
380+
"command": "i18n-ally.extract-enable-auto-detect",
381+
"category": "%extname%",
382+
"title": "%command.extract.enable-auto-detect%"
373383
}
374384
],
375385
"menus": {
@@ -465,6 +475,14 @@
465475
{
466476
"command": "i18n-ally.go-to-range",
467477
"when": "false"
478+
},
479+
{
480+
"command": "i18n-ally.extract-disable-auto-detect",
481+
"when": "false"
482+
},
483+
{
484+
"command": "i18n-ally.extract-enable-auto-detect",
485+
"when": "false"
468486
}
469487
],
470488
"view/item/context": [
@@ -560,6 +578,16 @@
560578
"command": "i18n-ally.extract-hard-strings-batch",
561579
"when": "viewItem =~ /i18n-ally-hard-string-root/",
562580
"group": "i18nally@1"
581+
},
582+
{
583+
"command": "i18n-ally.extract-disable-auto-detect",
584+
"when": "viewItem =~ /i18n-ally-hard-string-root/ && i18n-ally.extract.autoDetect == true",
585+
"group": "i18nally@2"
586+
},
587+
{
588+
"command": "i18n-ally.extract-enable-auto-detect",
589+
"when": "viewItem =~ /i18n-ally-hard-string-root/ && i18n-ally.extract.autoDetect == false",
590+
"group": "i18nally@2"
563591
}
564592
],
565593
"view/title": [

Diff for: src/commands/commands.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export const enum Commands {
99
set_source_language = 'i18n-ally.set-source-language',
1010
extract_text = 'i18n-ally.extract-text',
1111
extract_hard_strings_batch = 'i18n-ally.extract-hard-strings-batch',
12+
extract_disable_auto_detect = 'i18n-ally.extract-disable-auto-detect',
13+
extract_enable_auto_detect = 'i18n-ally.extract-enable-auto-detect',
1214
detect_hard_strings = 'i18n-ally.detect_hard_strings',
1315
replace_with = 'i18n-ally.replace-with',
1416
copy_key = 'i18n-ally.copy-key',

Diff for: src/commands/extractText.ts

+6
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ async function ExtractOrInsertCommnad(options?: ExtractTextOptions, detection?:
205205
const m: ExtensionModule = () => {
206206
return [
207207
commands.registerCommand(Commands.extract_text, ExtractOrInsertCommnad),
208+
commands.registerCommand(Commands.extract_enable_auto_detect, () => {
209+
Config.extractAutoDetect = true
210+
}),
211+
commands.registerCommand(Commands.extract_disable_auto_detect, () => {
212+
Config.extractAutoDetect = false
213+
}),
208214
]
209215
}
210216

Diff for: src/core/Config.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path'
22
import { execSync } from 'child_process'
3-
import { workspace, extensions, ExtensionContext } from 'vscode'
3+
import { workspace, extensions, ExtensionContext, commands } from 'vscode'
44
import { trimEnd, uniq } from 'lodash'
55
import { TagSystems } from '../tagSystems'
66
import { EXT_NAMESPACE, EXT_ID, EXT_LEGACY_NAMESPACE, KEY_REG_DEFAULT, KEY_REG_ALL, DEFAULT_LOCALE_COUNTRY_MAP } from '../meta'
@@ -437,6 +437,11 @@ export class Config {
437437
return this.getConfig<boolean>('extract.autoDetect') ?? false
438438
}
439439

440+
static set extractAutoDetect(v: boolean) {
441+
this.setConfig('extract.autoDetect', v, false)
442+
commands.executeCommand('setContext', 'i18n-ally.extract.autoDetect', v)
443+
}
444+
440445
static get extractParserHTMLOptions() {
441446
return this.getConfig<ExtractionHTMLOptions>('extract.parsers.html') ?? {}
442447
}

Diff for: src/core/Global.ts

+2
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ export class Global {
366366
Log.info(`🧩 Enabled frameworks: ${this.enabledFrameworks.map(i => i.display).join(', ')}`)
367367
Log.info(`🧬 Enabled parsers: ${this.enabledParsers.map(i => i.id).join(', ')}`)
368368
Log.info('')
369+
commands.executeCommand('setContext', 'i18n-ally.extract.autoDetect', Config.extractAutoDetect)
370+
369371
await this.initLoader(this._rootpath, reload)
370372
}
371373
else {

0 commit comments

Comments
 (0)