feat: Добавлена настройка "Язык субтитров по умолчанию"#1584
feat: Добавлена настройка "Язык субтитров по умолчанию"#1584I3eka wants to merge 5 commits intoilyhalight:devfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new “Default subtitles language” setting to decouple subtitle language selection from the voice translation target language, improving usability for language-learning and similar scenarios.
Changes:
- Introduces a new persisted config value:
responseLanguageSubtitles(empty string = “Auto” / legacy behavior). - Adds a new subtitles-language select control to the Settings UI and wires it to storage/events.
- Updates subtitles enabling/selection logic (and a subtitles cache validation check) to prefer the configured subtitles language.
Reviewed changes
Copilot reviewed 69 out of 69 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/videoHandler/modules/translation.ts | Uses responseLanguageSubtitles when validating cached subtitles before caching translation results. |
| src/videoHandler/modules/subtitles.ts | Enables subtitles using responseLanguageSubtitles as the target subtitle language (fallbacks to previous behavior). |
| src/videoHandler/modules/init.ts | Adds responseLanguageSubtitles default value to initial storage read. |
| src/ui/views/settings.ts | Adds the “Default subtitles language” select to the Subtitles settings section and persists it. |
| src/types/views/settings.ts | Extends settings view event map with select:subtitlesLanguage. |
| src/types/storage.ts | Adds storage key + StorageData.responseLanguageSubtitles. |
| src/types/localization.ts | Adds VOTSubtitlesLanguage to localization phrase typings. |
| src/localization/locales/*.json | Adds localized strings for VOTSubtitlesLanguage across locales. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| const targetSubtitleLang = this.data?.responseLanguageSubtitles || videoData.responseLanguage; | ||
| if ( | ||
| !cachedSubs?.some( | ||
| (item) => | ||
| item.source === "yandex" && | ||
| item.translatedFromLanguage === videoData.detectedLanguage && | ||
| item.language === videoData.responseLanguage, | ||
| item.language === targetSubtitleLang, |
There was a problem hiding this comment.
targetSubtitleLang can legitimately be set to the detected/original language (e.g. user wants original subtitles while voice translation is to another language). In that case the cache validation below will never match because it requires translatedFromLanguage === videoData.detectedLanguage, so subtitles cache gets deleted and this.subtitles cleared even though valid subtitles in targetSubtitleLang may exist. Consider relaxing the predicate to accept any subtitle track in targetSubtitleLang (or explicitly handle the targetSubtitleLang === detectedLanguage case), otherwise switching default subtitles language to the original language will cause unnecessary cache invalidation / subtitle resets.
src/ui/views/settings.ts
Outdated
| items:[ | ||
| { | ||
| label: localizationProvider.get("langs.auto" as any), | ||
| value: "", |
There was a problem hiding this comment.
Formatting: items:[ is inconsistent with the surrounding object literal style in this file (e.g. items: ...). Keeping the spacing consistent improves readability and reduces diffs from auto-formatters.
src/types/views/settings.ts
Outdated
| "select:translationTextService": [item: TranslateService]; | ||
| "select:buttonPosition": [item: Position]; | ||
| "select:menuLanguage": [item: LangOverride]; | ||
| "select:subtitlesLanguage":[item: string]; |
There was a problem hiding this comment.
Type formatting: missing whitespace after the colon in the event key ("select:subtitlesLanguage":[...]). Align with the spacing used by the other entries in this map for consistency.
src/types/storage.ts
Outdated
| autoHideButtonDelay: number; | ||
| useAudioDownload: boolean; | ||
| compatVersion: CompatibilityVersion; | ||
| responseLanguageSubtitles: string; |
There was a problem hiding this comment.
responseLanguageSubtitles is typed as a plain string, which allows persisting invalid/unsupported language codes. Other language-related settings use stricter unions (e.g. LanguageSelectKey, ResponseLang). Consider typing this as "" | Exclude<LanguageSelectKey, "auto"> (or similar) to match the actual values stored by the Settings UI and to keep the setting type-safe across the codebase.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 70 out of 70 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
src/ui/views/settings.ts
Outdated
| subtitlesDownloadFormatSelect?: Select<SubtitleFormat>; | ||
| subtitlesLanguageSelectLabel?: Label; | ||
| subtitlesLanguageSelect?: Select<string>; |
There was a problem hiding this comment.
subtitlesLanguageSelect is declared as Select<string>, but it's instantiated as Select<"" | Exclude<LanguageSelectKey, "auto">>. This loses type-safety for the setting value (and can become a TS incompatibility depending on Select's generic variance). Consider typing the field consistently as Select<"" | Exclude<LanguageSelectKey, "auto">> (or a shared alias) so bindPersistedSetting/events stay correctly typed.
| return ( | ||
| targetSubtitleLang === videoData.detectedLanguage || | ||
| item.translatedFromLanguage === videoData.detectedLanguage | ||
| ); |
There was a problem hiding this comment.
Subtitles cache invalidation uses a cache key built from videoData.responseLanguage, but validates cached entries against targetSubtitleLang (which may come from responseLanguageSubtitles). This mismatch can cause repeated cache deletions / refetching when the user sets a fixed subtitle language. Consider incorporating the effective subtitles target language into the subtitles cache key (and into loadSubtitles/callers), or changing the invalidation check to validate against the same language used to build subsCacheKey.
| !cachedSubs?.some((item) => { | ||
| if ( | ||
| item.source !== "yandex" || | ||
| item.language !== targetSubtitleLang | ||
| ) { | ||
| return false; | ||
| } | ||
| // If user wants original subtitles (target == detected), accept it. | ||
| // Otherwise ensure it is translated from the correct source. | ||
| return ( | ||
| targetSubtitleLang === videoData.detectedLanguage || | ||
| item.translatedFromLanguage === videoData.detectedLanguage | ||
| ); |
There was a problem hiding this comment.
The cache validation here only considers item.source === "yandex". With the new default subtitles language setting, a valid matching subtitle track might come from a site source (e.g., YouTube captions) and still satisfy the user's selected targetSubtitleLang. As written, the code will delete the subtitles cache even if a non-Yandex track matches the requested language. Consider broadening the predicate to accept any source that matches targetSubtitleLang (and only apply the translatedFromLanguage check when relevant).
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 70 out of 70 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| ) | ||
| !cachedSubs?.some((item) => { | ||
| if (item.source !== "yandex" || item.language !== responseLang) { | ||
| return false; |
There was a problem hiding this comment.
subsCacheKey is computed using this.videoData.responseLanguage, but the matching predicate now compares cached subtitle items against the responseLang argument. If videoData.responseLanguage can change while this translation is in-flight (e.g., user changes the target language in the UI), these two values can diverge and cause the code to delete the subtitles cache for a different language than the one being validated. Consider deriving both the cache key and the match check from the same stable pair for this request (e.g., requestLang/responseLang args or reqLang/resLang), rather than mixing mutable this.videoData state with the function parameter.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 70 out of 70 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
ad1de1c to
9560c63
Compare
Описание:
Описание изменений
Данный PR вносит изменения в раздел «Настройки субтитров», добавляя возможность выбора приоритетного языка для субтитров. Эта настройка позволяет автоматически применять выбранный язык при открытии видео, независимо от выбранного языка голосового перевода.
Мотивация
В текущей версии расширения, при использовании функций «Автоперевод видео» и «Субтитры при открытии», язык субтитров жестко привязан к целевому языку голосового перевода.
Такое поведение ограничивает удобство использования, особенно в сценариях изучения иностранных языков.
Пример сценария: Пользователь просматривает видео на английском языке и использует закадровую озвучку на своем родном языке для понимания сложного контекста, но при этом хочет видеть оригинальные английские субтитры для восприятия текста. Ранее для этого требовалось переключать язык субтитров вручную при каждом запуске видео.
Детали реализации
responseLanguageSubtitlesв конфигурацию.hashes.jsonи типы TypeScript с помощью скриптаnpm run localizeв соответствии с CONTRIBUTING.md.Скриншоты
Тестирование