Skip to content

Commit

Permalink
fix: show detection subtree only for support language
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Mar 31, 2021
1 parent 18c9c85 commit 2a62205
Show file tree
Hide file tree
Showing 19 changed files with 33 additions and 12 deletions.
5 changes: 1 addition & 4 deletions examples/by-features/demo/Demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
<p>{{ $t('intro') }}</p>
<p>{{ $t('hello') }}</p>
<p>{{ $t('not_exist') }}</p>
<p>
Hard coded
String
</p>
<p>{{ $t('hard-coded-string') }}</p>
</div>
</template>

Expand Down
5 changes: 3 additions & 2 deletions examples/by-features/demo/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"and": "good"
}
},
"yad": "asd"
}
"yad": "asd",
"hard-coded-string": "Hard coded String"
}
1 change: 1 addition & 0 deletions locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"command.duplicate_key": "Schlüssel kopieren",
"command.edit_key": "Übersetzung bearbeiten",
"command.fulfill_keys": "Vervollständige Schlüssel mit leeren Texten",
"command.go_to_range": "",
"command.insert_key": "Schlüssel einfügen",
"command.locale_visibility_hide": "Lokalisierung verbergen",
"command.locale_visibility_show": "Lokalisierung anzeigen",
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"prompt.translate_no_jobs": "No translation needed.",
"prompt.writing_js": "Writing to js/ts files is not supported.",
"refactor.extract_text": "🌍 Extract text into i18n messages",
"refactor.extracting_not_support_for_lang": "Extracting for language \"{0}\" is not supported yet",
"refactor.replace_with": "Replace text with existing translation: \"{0}\"",
"review.accept_suggestion": "Accept Suggestion",
"review.apply_suggestion": "Apply suggestion",
Expand Down
1 change: 1 addition & 0 deletions locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"command.duplicate_key": "Duplicar clave",
"command.edit_key": "Editar traducción",
"command.fulfill_keys": "Rellenar claves con cadena vacía",
"command.go_to_range": "",
"command.insert_key": "Insertar clave",
"command.locale_visibility_hide": "Ocultar configuración regional",
"command.locale_visibility_show": "Mostrar configuración regional",
Expand Down
1 change: 1 addition & 0 deletions locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"command.duplicate_key": "Dupliquer une Clé",
"command.edit_key": "Modifier la traduction",
"command.fulfill_keys": "Remplir les champs vides de Clés",
"command.go_to_range": "",
"command.insert_key": "",
"command.locale_visibility_hide": "Cacher le dossier de la locale",
"command.locale_visibility_show": "Afficher le dossier locde la locale",
Expand Down
1 change: 1 addition & 0 deletions locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"command.duplicate_key": "",
"command.edit_key": "翻訳を編集する",
"command.fulfill_keys": "空文字でキーを埋める",
"command.go_to_range": "",
"command.insert_key": "",
"command.locale_visibility_hide": "ロケールを隠す",
"command.locale_visibility_show": "ロケールを表示する",
Expand Down
1 change: 1 addition & 0 deletions locales/nb-NO.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"command.duplicate_key": "",
"command.edit_key": "Rediger oversettelse",
"command.fulfill_keys": "",
"command.go_to_range": "",
"command.insert_key": "",
"command.locale_visibility_hide": "Skjul oversettelse",
"command.locale_visibility_show": "Vis oversettelse",
Expand Down
1 change: 1 addition & 0 deletions locales/nl-NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"command.duplicate_key": "Dupliceer sleutel",
"command.edit_key": "Bewerk vertaling",
"command.fulfill_keys": "Sleutels met lege waarden aanvullen",
"command.go_to_range": "",
"command.insert_key": "",
"command.locale_visibility_hide": "Verberg locale",
"command.locale_visibility_show": "Toon locale",
Expand Down
1 change: 1 addition & 0 deletions locales/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"command.duplicate_key": "Duplicar chave",
"command.edit_key": "Editar tradução",
"command.fulfill_keys": "Preencher chaves com strings vazias",
"command.go_to_range": "",
"command.insert_key": "",
"command.locale_visibility_hide": "Esconder locale",
"command.locale_visibility_show": "Exibir locale",
Expand Down
1 change: 1 addition & 0 deletions locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"command.duplicate_key": "Повторяющийся ключ",
"command.edit_key": "Редактировать перевод",
"command.fulfill_keys": "Заполнять ключ пустой строкой",
"command.go_to_range": "",
"command.insert_key": "Вставить ключ",
"command.locale_visibility_hide": "Скрыть перевод",
"command.locale_visibility_show": "Показать перевод",
Expand Down
1 change: 1 addition & 0 deletions locales/sv-SE.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"command.duplicate_key": "Duplicera nyckel",
"command.edit_key": "Ändra översättning",
"command.fulfill_keys": "Skapa saknade nycklar med tomma strängar",
"command.go_to_range": "",
"command.insert_key": "Lägg till nyckel",
"command.locale_visibility_hide": "Göm locale",
"command.locale_visibility_show": "Visa locale",
Expand Down
1 change: 1 addition & 0 deletions locales/uk-UA.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"command.duplicate_key": "Дублікат ключа",
"command.edit_key": "Редагувати переклад",
"command.fulfill_keys": "Заповнювати ключ порожній рядком",
"command.go_to_range": "",
"command.insert_key": "Вставити ключ",
"command.locale_visibility_hide": "Приховати мову",
"command.locale_visibility_show": "Показати мову",
Expand Down
1 change: 1 addition & 0 deletions locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"command.duplicate_key": "建立副本",
"command.edit_key": "编辑文案",
"command.fulfill_keys": "使用空字符串填充文案路径",
"command.go_to_range": "",
"command.insert_key": "插入i18n文案",
"command.locale_visibility_hide": "隐藏此语言",
"command.locale_visibility_show": "显示此语言",
Expand Down
1 change: 1 addition & 0 deletions locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"command.duplicate_key": "建立副本",
"command.edit_key": "編輯文案",
"command.fulfill_keys": "使用空字串填充文案路徑",
"command.go_to_range": "",
"command.insert_key": "插入i18n文案",
"command.locale_visibility_hide": "隱藏此語言",
"command.locale_visibility_show": "顯示此語言",
Expand Down
5 changes: 3 additions & 2 deletions src/commands/detectHardStrings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ExtensionModule } from '~/modules'
import { Global } from '~/core'
import { Commands } from '~/commands'
import { DetectionResult } from '~/extraction'
import i18n from '~/i18n'

const decoration = window.createTextEditorDecorationType({
// TODO: configureable
Expand All @@ -19,10 +20,10 @@ export async function DetectHardStrings() {
if (!doc || !editor)
return

const frameworks = Global.enabledFrameworks.filter(i => i.supportAutoExtraction?.includes(doc.languageId))
const frameworks = Global.getExtractionFrameworksByLang(doc.languageId)

if (!frameworks.length) {
window.showWarningMessage(`Extracting for language "${doc.languageId}" is not supported yet`)
window.showWarningMessage(i18n.t('refactor.extracting_not_support_for_lang'), doc.languageId)
return
}

Expand Down
4 changes: 4 additions & 0 deletions src/core/Global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,4 +409,8 @@ export class Global {
const ignored = Config.ignoredLocales
return locales.filter(locale => !ignored.includes(locale))
}

static getExtractionFrameworksByLang(languageId: string) {
return this.enabledFrameworks.filter(i => i.supportAutoExtraction?.includes(languageId))
}
}
4 changes: 2 additions & 2 deletions src/editor/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class ExtractProvider implements CodeActionProvider {
if (!(selection instanceof Selection))
return []

const text = document.getText(selection)
if (!text || selection.start.line !== selection.end.line)
const text = document.getText(selection)?.trim().replace(/\s*\r?\n\s*/g, ' ')
if (!text)
return []

const options: ExtractTextOptions = {
Expand Down
9 changes: 7 additions & 2 deletions src/views/providers/CurrentFileLocalesTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ export class CurrentFileLocalesTreeProvider implements TreeDataProvider<BaseTree
if (element)
return await element.getChildren()

return [
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
}

protected refresh(): void {
Expand Down

0 comments on commit 2a62205

Please sign in to comment.