Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add 'most-similar-by-key' mode for TargetPickingStrategy #758

Merged
merged 5 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"config.target_picking_strategy.file-previous": "Text in die zuvor ausgewählte Sprachdatei der aktuellen Datei extrahieren",
"config.target_picking_strategy.global-previous": "Text in die aktuell ausgewähle Datei extrahieren",
"config.target_picking_strategy.most-similar": "Automatisches Extrahieren von Text in die Datei, deren Pfad am meisten mit dem Pfad der aktuellen Datei übereinstimmt",
"config.target_picking_strategy.most-similar-by-key": "Füllen Sie die extrahierte Kopie automatisch in die Sprachdatei ein, die am besten zum aktuellen i18n-Schlüssel passt",
"config.target_picking_strategy.none": "Benutzer wählt manuell aus, in welche Datei der Text extrahiert werden soll",
"config.translate.engines": "Übersetzungsdienste.",
"config.translate.fallbackToKey": "Schlüssel selbst zum Übersetzen verwenden, wenn es keine Quellübersetzung für diesen Schlüssel gibt.",
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"config.target_picking_strategy.file-previous": "Extract text to current file's previous selected locale file",
"config.target_picking_strategy.global-previous": "Extract text to (current or other) file 's previous selected locale file",
"config.target_picking_strategy.most-similar": "Automatically extract text to the file which path most matches to current file's path",
"config.target_picking_strategy.most-similar-by-key": "Automatically fill the extracted copy into the language file that best matches the current i18n key",
"config.target_picking_strategy.none": "User manually select which file to extract text to",
"config.translate.engines": "Translation services.",
"config.translate.fallbackToKey": "Use key itself to translate when there is no source translation for that key.",
Expand Down
1 change: 1 addition & 0 deletions locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"config.target_picking_strategy.file-previous": "Extraer el texto al archivo de localización seleccionado anteriormente del archivo actual",
"config.target_picking_strategy.global-previous": "Extraer el texto al archivo (actual o de otro tipo) del archivo local previamente seleccionado",
"config.target_picking_strategy.most-similar": "Extraer automáticamente el texto al archivo cuya ruta coincida más con la ruta del archivo actual",
"config.target_picking_strategy.most-similar-by-key": "Rellene automáticamente la copia extraída en el archivo de idioma que mejor coincida con la clave i18n actual",
"config.target_picking_strategy.none": "El usuario selecciona manualmente a qué archivo extraer el texto",
"config.translate.engines": "Servicios de traducción.",
"config.translate.fallbackToKey": "Usar la llave en sí para traducir cuando no hay una traducción de origen para esa llave.",
Expand Down
1 change: 1 addition & 0 deletions locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"config.target_picking_strategy.file-previous": "Extraire le texte dans le fichier locale, précédemment sélectionné, du fichier actuel",
"config.target_picking_strategy.global-previous": "Extraire le texte dans le fichier locale, précédemment sélectionné, du fichier actuel (ou autre)",
"config.target_picking_strategy.most-similar": "Extraire automatiquement le texte dans le fichier dont le chemin correspond le plus au chemin du fichier actuel",
"config.target_picking_strategy.most-similar-by-key": "Remplissez automatiquement la copie extraite dans le fichier de langue qui correspond le mieux à la clé i18n actuelle",
"config.target_picking_strategy.none": "L'utilisateur sélectionne manuellement le fichier dans lequel extraire le texte",
"config.translate.engines": "Services de traduction.",
"config.translate.fallbackToKey": "Utilisez la clé elle-même pour traduire lorsqu'il n'y a pas de traduction source pour cette clé.",
Expand Down
1 change: 1 addition & 0 deletions locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"config.target_picking_strategy.file-previous": "",
"config.target_picking_strategy.global-previous": "",
"config.target_picking_strategy.most-similar": "",
"config.target_picking_strategy.most-similar-by-key": "抽出したコピーを、現在のi18nキーに最も一致する言語ファイルに自動的に入力します",
"config.target_picking_strategy.none": "",
"config.translate.engines": "",
"config.translate.fallbackToKey": "",
Expand Down
1 change: 1 addition & 0 deletions locales/nb-NO.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"config.target_picking_strategy.file-previous": "",
"config.target_picking_strategy.global-previous": "",
"config.target_picking_strategy.most-similar": "",
"config.target_picking_strategy.most-similar-by-key": "Fyll automatisk den utpakkede kopien inn i språkfilen som passer best til gjeldende i18n-nøkkel",
"config.target_picking_strategy.none": "",
"config.translate.engines": "",
"config.translate.fallbackToKey": "",
Expand Down
1 change: 1 addition & 0 deletions locales/nl-NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"config.target_picking_strategy.file-previous": "",
"config.target_picking_strategy.global-previous": "",
"config.target_picking_strategy.most-similar": "",
"config.target_picking_strategy.most-similar-by-key": "Vul de uitgepakte kopie automatisch in het taalbestand dat het beste overeenkomt met de huidige i18n-sleutel",
"config.target_picking_strategy.none": "",
"config.translate.engines": "",
"config.translate.fallbackToKey": "Gebruik de sleutel zelf als vertaling, als er geen originele vertaling bestaat",
Expand Down
1 change: 1 addition & 0 deletions locales/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"config.target_picking_strategy.file-previous": "",
"config.target_picking_strategy.global-previous": "",
"config.target_picking_strategy.most-similar": "",
"config.target_picking_strategy.most-similar-by-key": "Preencha automaticamente a cópia extraída no arquivo de idioma que melhor corresponde à chave i18n atual",
"config.target_picking_strategy.none": "",
"config.translate.engines": "",
"config.translate.fallbackToKey": "",
Expand Down
1 change: 1 addition & 0 deletions locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"config.target_picking_strategy.file-previous": "Извлекать текст в предыдущий выбранный файл перевода текущего файла",
"config.target_picking_strategy.global-previous": "Извлекать текст в (текущий или другой) файл предыдущего выбранного файла перевода",
"config.target_picking_strategy.most-similar": "Автоматически заполнять извлеченную копию в файл перевода, который лучше всего соответствует текущему пути к файлу",
"config.target_picking_strategy.most-similar-by-key": "Автоматически заполнять извлеченную копию языковым файлом, который лучше всего соответствует текущему ключу i18n.",
"config.target_picking_strategy.none": "Пользователь вручную выбирает файл для извлечения текста",
"config.translate.engines": "Сервисы перевода.",
"config.translate.fallbackToKey": "Использовать сам ключ для перевода, если для этого ключа нет перевода",
Expand Down
1 change: 1 addition & 0 deletions locales/sv-SE.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"config.target_picking_strategy.file-previous": "Extrahera text till nuvarande fils tidigare valda locale-fil",
"config.target_picking_strategy.global-previous": "Extrahera text till (nuvarande elle annan) fils tidigare valda locale-fil",
"config.target_picking_strategy.most-similar": "Extrahera text automatiskt till den fil vars sökväg mest stämmer överens med nuvarande filens sökväg",
"config.target_picking_strategy.most-similar-by-key": "Fyll automatiskt i den extraherade kopian i den språkfil som bäst matchar den aktuella i18n-nyckeln",
"config.target_picking_strategy.none": "Välj själv vilken fil att extrahera text till",
"config.translate.engines": "Översättningstjänster.",
"config.translate.fallbackToKey": "Använd nyckeln själv för att översätta när det inte finns någon källspråksöversättning för den nyckeln.",
Expand Down
1 change: 1 addition & 0 deletions locales/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"config.target_picking_strategy.file-previous": "Metni mevcut dosyanın önceki seçili dil dosyasına çıkartın",
"config.target_picking_strategy.global-previous": "Metni (mevcut veya başka) dosyanın önceki seçili yerel ayar dosyasına çıkartın",
"config.target_picking_strategy.most-similar": "Geçerli dosyanın bulunduğu alana en çok uyan yolu dosyaya otomatik olarak ayıklayın",
"config.target_picking_strategy.most-similar-by-key": "Çıkarılan kopyayı, geçerli i18n anahtarıyla en iyi eşleşen dil dosyasına otomatik olarak doldurun",
"config.target_picking_strategy.none": "Kullanıcı metnin çıkarılacağı dosyayı el ile seçer",
"config.translate.engines": "Çeviri hizmetleri.",
"config.translate.fallbackToKey": "Bu anahtar için kaynak çevirisi olmadığında çeviri yapmak için anahtarın kendisini kullanın.",
Expand Down
1 change: 1 addition & 0 deletions locales/uk-UA.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"config.target_picking_strategy.file-previous": "Автоматично заповнювати обраний файл перекладу при останньому завантаженні з поточного файлу",
"config.target_picking_strategy.global-previous": "Автоматично заповнювати обраний файл перекладу при добуванні копії в останньому (поточному/іншому) файлі",
"config.target_picking_strategy.most-similar": "Автоматично заповнювати витягнуту копію в файл перекладу, який найкраще відповідає поточному шляху до файлу",
"config.target_picking_strategy.most-similar-by-key": "Автоматично заповнюйте витягнуту копію в мовний файл, який найкраще відповідає поточному ключу i18n",
"config.target_picking_strategy.none": "Користувач вручну обирає файл для вилучення тексту",
"config.translate.engines": "Сервіс для перекладу.",
"config.translate.fallbackToKey": "Використовувати сам ключ для перекладу, якщо для цього ключа нема переводу",
Expand Down
1 change: 1 addition & 0 deletions locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"config.target_picking_strategy.file-previous": "自动填入上次抽取当前文件中的文案时选择的语言文件中",
"config.target_picking_strategy.global-previous": "自动填入上次抽取(当前/其他)文件中的文案时选择的语言文件中",
"config.target_picking_strategy.most-similar": "自动将抽取的文案填入与当前文件路径最匹配的语言文件中",
"config.target_picking_strategy.most-similar-by-key": "自动将抽取的文案填入与当前i18n key最匹配的语言文件中",
"config.target_picking_strategy.none": "用户手动选择将文本抽取到哪个语言文件",
"config.translate.engines": "翻译服务提供商",
"config.translate.fallbackToKey": "当对应路径没有翻译时,使用路径本身进行翻译",
Expand Down
1 change: 1 addition & 0 deletions locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"config.target_picking_strategy.file-previous": "自動填入上次抽取當前文件中的文案時選擇的語言文件中",
"config.target_picking_strategy.global-previous": "自動填入上次抽取(當前/其他)文件中的文案時選擇的語言文件中",
"config.target_picking_strategy.most-similar": "自動將抽取的文案填入與當前文件路徑最匹配的語言文件中",
"config.target_picking_strategy.most-similar-by-key": "自動將抽取的文案填入與當前i18n key最匹配的語言文件中",
"config.target_picking_strategy.none": "用戶手動選擇將文本抽取到哪個語言文件",
"config.translate.engines": "翻譯服務供應商",
"config.translate.fallbackToKey": "當對應路徑沒有翻譯時,使用路徑本身進行翻譯",
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1169,14 +1169,16 @@
"enum": [
"none",
"most-similar",
"most-similar-by-key",
"file-previous",
"global-previous"
],
"enumDescriptions": [
"%config.target_picking_strategy.none%",
"%config.target_picking_strategy.most-similar%",
"%config.target_picking_strategy.file-previous%",
"%config.target_picking_strategy.global-previous%"
"%config.target_picking_strategy.global-previous%",
"%config.target_picking_strategy.most-similar-by-key%"
],
"description": "%config.target_picking_strategy%"
},
Expand Down
9 changes: 9 additions & 0 deletions src/core/loaders/LocaleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,18 @@ export class LocaleLoader extends Loader {
ignoreFocusOut: true,
})
}

if (Config.targetPickingStrategy === TargetPickingStrategy.MostSimilar && pending.textFromPath)
return this.findBestMatchFile(pending.textFromPath, paths)

if (Config.targetPickingStrategy === TargetPickingStrategy.MostSimilarByKey && keypath) {
const splitSymbol = Config.namespace ? Global.getNamespaceDelimiter() : '.'
const prefixKey = keypath.split(splitSymbol)[0]
const matched = this.findBestMatchFile(`${this._locale_dirs}/${prefixKey}`, paths)
if (matched.includes(prefixKey))
return matched
}

if (Config.targetPickingStrategy === TargetPickingStrategy.FilePrevious && pending.textFromPath)
return this.handleExtractToFilePrevious(pending.textFromPath, paths, keypath)

Expand Down
1 change: 1 addition & 0 deletions src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export enum TargetPickingStrategy {
MostSimilar = 'most-similar',
FilePrevious ='file-previous',
GlobalPrevious = 'global-previous',
MostSimilarByKey = 'most-similar-by-key',
}

export type DetectionSource = 'html-attribute' | 'html-inline' | 'js-string' | 'js-template' | 'jsx-text'
Expand Down