Skip to content

Commit

Permalink
fix: disable detection subtree instead of hiding
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Mar 31, 2021
1 parent c007d7c commit 8b7c414
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 15 deletions.
2 changes: 2 additions & 0 deletions locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"prompt.translate_no_jobs": "Keine Übersetzung notwendig",
"prompt.writing_js": "Das Schreiben in js/ts-Dateien wird nicht unterstützt.",
"refactor.extract_text": "🌍 Text in i18n-Nachrichten extrahieren",
"refactor.extracting_not_support_for_lang": "",
"refactor.replace_with": "Ersetzen Sie den Text durch die vorhandene Übersetzung: \"{0}\"",
"review.accept_suggestion": "Vorschlag akzeptieren",
"review.apply_suggestion": "Vorschlag anwenden",
Expand All @@ -200,6 +201,7 @@
"review.unknown_user": "Unbekannt",
"view.current_file": "Aktuelle Datei",
"view.current_file_hard_strings": "",
"view.current_file_hard_strings_not_supported": "",
"view.current_file_keys_in_use": "",
"view.current_file_keys_not_found": "",
"view.help_feedback": "Hilfe & Rückmeldung",
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
"review.unknown_user": "Unknown",
"view.current_file": "Current file",
"view.current_file_hard_strings": "Hard-coded strings [beta]",
"view.current_file_hard_strings_not_supported": "\"{0}\" is not supported yet",
"view.current_file_keys_in_use": "Keys in use",
"view.current_file_keys_not_found": "Keys not found",
"view.help_feedback": "Help & Feedback",
Expand Down
2 changes: 2 additions & 0 deletions locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"prompt.translate_no_jobs": "No se necesita traducción.",
"prompt.writing_js": "Escribir archivos a js/ts no está soportado.",
"refactor.extract_text": "🌍 Extraer texto en mensajes i18n",
"refactor.extracting_not_support_for_lang": "",
"refactor.replace_with": "Remplazar texto con traducción existenten: \"{0}\"",
"review.accept_suggestion": "Aceptar sugerencia",
"review.apply_suggestion": "Aplicar sugerancia",
Expand All @@ -200,6 +201,7 @@
"review.unknown_user": "Desconocido",
"view.current_file": "Archivo actual",
"view.current_file_hard_strings": "",
"view.current_file_hard_strings_not_supported": "",
"view.current_file_keys_in_use": "",
"view.current_file_keys_not_found": "",
"view.help_feedback": "Ayuda y comentarios",
Expand Down
2 changes: 2 additions & 0 deletions locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"prompt.translate_no_jobs": "",
"prompt.writing_js": "Le mode \"Ecriture\" n'est pas disponible pour les fichiers JS/TS.",
"refactor.extract_text": "🌍 Extract text into i18n messages",
"refactor.extracting_not_support_for_lang": "",
"refactor.replace_with": "",
"review.accept_suggestion": "",
"review.apply_suggestion": "",
Expand All @@ -200,6 +201,7 @@
"review.unknown_user": "",
"view.current_file": "Fichier ouvert",
"view.current_file_hard_strings": "",
"view.current_file_hard_strings_not_supported": "",
"view.current_file_keys_in_use": "",
"view.current_file_keys_not_found": "",
"view.help_feedback": "Aide & Retours",
Expand Down
2 changes: 2 additions & 0 deletions locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"prompt.translate_no_jobs": "",
"prompt.writing_js": "js/ts ファイルはサポートしていません。",
"refactor.extract_text": "🌍 Extract text into i18n messages",
"refactor.extracting_not_support_for_lang": "",
"refactor.replace_with": "",
"review.accept_suggestion": "",
"review.apply_suggestion": "",
Expand All @@ -200,6 +201,7 @@
"review.unknown_user": "",
"view.current_file": "現在のファイル",
"view.current_file_hard_strings": "",
"view.current_file_hard_strings_not_supported": "",
"view.current_file_keys_in_use": "",
"view.current_file_keys_not_found": "",
"view.help_feedback": "ヘルプ & フィードバック",
Expand Down
2 changes: 2 additions & 0 deletions locales/nb-NO.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"prompt.translate_no_jobs": "",
"prompt.writing_js": "Skriving til js/ts fil støttes ikke.",
"refactor.extract_text": "🌍 Ekstraher tekst til i18n ally",
"refactor.extracting_not_support_for_lang": "",
"refactor.replace_with": "",
"review.accept_suggestion": "",
"review.apply_suggestion": "",
Expand All @@ -200,6 +201,7 @@
"review.unknown_user": "",
"view.current_file": "Denne filen",
"view.current_file_hard_strings": "",
"view.current_file_hard_strings_not_supported": "",
"view.current_file_keys_in_use": "",
"view.current_file_keys_not_found": "",
"view.help_feedback": "Hjelp & Tilbakemeldinger",
Expand Down
2 changes: 2 additions & 0 deletions locales/nl-NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"prompt.translate_no_jobs": "",
"prompt.writing_js": "Het schrijven naar js/ts bestanden wordt niet ondersteund.",
"refactor.extract_text": "🌍 Extraheer tekst naar i18n berichten",
"refactor.extracting_not_support_for_lang": "",
"refactor.replace_with": "",
"review.accept_suggestion": "",
"review.apply_suggestion": "",
Expand All @@ -200,6 +201,7 @@
"review.unknown_user": "",
"view.current_file": "Huidige bestand",
"view.current_file_hard_strings": "",
"view.current_file_hard_strings_not_supported": "",
"view.current_file_keys_in_use": "",
"view.current_file_keys_not_found": "",
"view.help_feedback": "Help & Feedback",
Expand Down
2 changes: 2 additions & 0 deletions locales/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"prompt.translate_no_jobs": "",
"prompt.writing_js": "Passar para arquivo js/ts não é suportado",
"refactor.extract_text": "🌍 Extrair texto como mensagem i18n",
"refactor.extracting_not_support_for_lang": "",
"refactor.replace_with": "",
"review.accept_suggestion": "",
"review.apply_suggestion": "",
Expand All @@ -200,6 +201,7 @@
"review.unknown_user": "",
"view.current_file": "Arquivo atual",
"view.current_file_hard_strings": "",
"view.current_file_hard_strings_not_supported": "",
"view.current_file_keys_in_use": "",
"view.current_file_keys_not_found": "",
"view.help_feedback": "Ajuda e comentários",
Expand Down
2 changes: 2 additions & 0 deletions locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"prompt.translate_no_jobs": "Перевод не нужен.",
"prompt.writing_js": "Запись в файлы js/ts не поддерживается.",
"refactor.extract_text": "🌍 Извлечь текст в сообщения i18n",
"refactor.extracting_not_support_for_lang": "",
"refactor.replace_with": "Заменить текст существующим переводом: \"{0}\"",
"review.accept_suggestion": "Принять Предложение",
"review.apply_suggestion": "Применить предложение",
Expand All @@ -200,6 +201,7 @@
"review.unknown_user": "Неизвестно",
"view.current_file": "Текущий файл",
"view.current_file_hard_strings": "",
"view.current_file_hard_strings_not_supported": "",
"view.current_file_keys_in_use": "",
"view.current_file_keys_not_found": "",
"view.help_feedback": "Помощь и обратная связь",
Expand Down
2 changes: 2 additions & 0 deletions locales/sv-SE.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"prompt.translate_no_jobs": "Ingen översättning krävs.",
"prompt.writing_js": "Att skriva till js/ts-filer stödjs inte.",
"refactor.extract_text": "🌍 Extrahera text till i18n meddelande",
"refactor.extracting_not_support_for_lang": "",
"refactor.replace_with": "Ersätt text med redan existerande översättning: \"{0}\"",
"review.accept_suggestion": "Acceptera Förslag",
"review.apply_suggestion": "Tillämpa förslag",
Expand All @@ -200,6 +201,7 @@
"review.unknown_user": "Okänd",
"view.current_file": "Nuvarande fil",
"view.current_file_hard_strings": "",
"view.current_file_hard_strings_not_supported": "",
"view.current_file_keys_in_use": "",
"view.current_file_keys_not_found": "",
"view.help_feedback": "Hjälp & Feedback",
Expand Down
2 changes: 2 additions & 0 deletions locales/uk-UA.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"prompt.translate_no_jobs": "Переклад не потрібен.",
"prompt.writing_js": "Запис у файли js/ts не підтримується.",
"refactor.extract_text": "🌍 Витягувати текст в повідомлення i18n",
"refactor.extracting_not_support_for_lang": "",
"refactor.replace_with": "Замінити текст існуючим перекладом: \"{0}\"",
"review.accept_suggestion": "Прийняти пропозицію",
"review.apply_suggestion": "Застосувати пропозицію",
Expand All @@ -200,6 +201,7 @@
"review.unknown_user": "Невідомо",
"view.current_file": "Поточний файл",
"view.current_file_hard_strings": "",
"view.current_file_hard_strings_not_supported": "",
"view.current_file_keys_in_use": "",
"view.current_file_keys_not_found": "",
"view.help_feedback": "Допомога і зворотний зв'язок",
Expand Down
2 changes: 2 additions & 0 deletions locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"prompt.translate_no_jobs": "无翻译工作",
"prompt.writing_js": "不支持写入文案至 js/ts 文件",
"refactor.extract_text": "🌍 提取文案到 i18n",
"refactor.extracting_not_support_for_lang": "",
"refactor.replace_with": "用现有翻译替换文本:\"{0}\"",
"review.accept_suggestion": "接受建议",
"review.apply_suggestion": "应用建议",
Expand All @@ -200,6 +201,7 @@
"review.unknown_user": "未知",
"view.current_file": "当前文件",
"view.current_file_hard_strings": "",
"view.current_file_hard_strings_not_supported": "",
"view.current_file_keys_in_use": "",
"view.current_file_keys_not_found": "",
"view.help_feedback": "帮助和反馈",
Expand Down
2 changes: 2 additions & 0 deletions locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"prompt.translate_no_jobs": "無翻譯工作",
"prompt.writing_js": "不支援寫入文案至 js/ts 檔案",
"refactor.extract_text": "🌍 提取文案到 i18n",
"refactor.extracting_not_support_for_lang": "",
"refactor.replace_with": "用現有翻譯替換文本:\"{0}\"",
"review.accept_suggestion": "接受建議",
"review.apply_suggestion": "套用建議",
Expand All @@ -200,6 +201,7 @@
"review.unknown_user": "未知",
"view.current_file": "當前檔案",
"view.current_file_hard_strings": "",
"view.current_file_hard_strings_not_supported": "",
"view.current_file_keys_in_use": "",
"view.current_file_keys_not_found": "",
"view.help_feedback": "幫助和回饋",
Expand Down
5 changes: 5 additions & 0 deletions res/dark/symbol-string-gray.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 22 additions & 11 deletions src/views/items/CurrentFileExtractionItem.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
import { TreeItemCollapsibleState } from 'vscode'
import { TreeItemCollapsibleState, window } from 'vscode'
import { CurrentFileLocalesTreeProvider } from '../providers'
import { BaseTreeItem } from './Base'
import { HardStringDetectResultItem } from './HardStringDetectResultItem'
import i18n from '~/i18n'
import { CurrentFile } from '~/core'
import { CurrentFile, Global } from '~/core'
import { DetectionResult } from '~/extraction'

export class CurrentFileExtractionItem extends BaseTreeItem {
collapsibleState = TreeItemCollapsibleState.Collapsed
result: DetectionResult[] | undefined
langId = 'unknown'

constructor(readonly provider: CurrentFileLocalesTreeProvider) {
super(provider.ctx)
}

// @ts-expect-error
get iconPath() {
return this.getIcon('symbol-string')
this.langId = window.activeTextEditor?.document.languageId || 'unknown'
if (this.langId && Global.getExtractionFrameworksByLang(this.langId).length)
this.collapsibleState = TreeItemCollapsibleState.Collapsed
else
this.collapsibleState = TreeItemCollapsibleState.None
this.updateDescription()
}

getLabel() {
return i18n.t('view.current_file_hard_strings')
}

// @ts-expect-error
get description() {
const length = CurrentFile.hardStrings?.length
return length == null ? '?' : length.toString()
updateDescription() {
if (this.collapsibleState === TreeItemCollapsibleState.None) {
this.iconPath = this.getIcon('symbol-string-gray')
this.description = i18n.t('view.current_file_hard_strings_not_supported', this.langId)
}
else {
this.iconPath = this.getIcon('symbol-string')
const length = CurrentFile.hardStrings?.length
this.description = length == null ? '?' : length.toString()
}
}

async getChildren() {
if (this.collapsibleState === TreeItemCollapsibleState.None)
return []

this.result = await CurrentFile.detectHardStrings()

if (this.result == null)
Expand Down
5 changes: 1 addition & 4 deletions src/views/providers/CurrentFileLocalesTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ export class CurrentFileLocalesTreeProvider implements TreeDataProvider<BaseTree
const items: BaseTreeItem[] = [
new CurrentFileInUseItem(this),
new CurrentFileNotFoundItem(this),
new CurrentFileExtractionItem(this),
]

const langId = window.activeTextEditor?.document.languageId
if (langId && Global.getExtractionFrameworksByLang(langId).length)
items.push(new CurrentFileExtractionItem(this))

return items
}

Expand Down

0 comments on commit 8b7c414

Please sign in to comment.