Skip to content

[Feature Request]: Please add a "Chinese (Simplified)" option for online subtitle translation. #5749

@Mikezkjit

Description

@Mikezkjit

Describe the feature you'd like to request

In the current version, when selecting a translation language, only "Chinese (Traditional)" is available in the list. The translation feature works perfectly. Please add an additional option for "Chinese (Simplified)". Thank you.

Describe the solution you'd like

The main reason seems to be that YouTube has reduced the number of online subtitle translations for interfaces such as Android, returning only Traditional Chinese subtitles. However, Simplified Chinese subtitles are actually supported. I tried modifying a version, and it worked — an extra "Chinese (Simplified)" option appeared in the subtitle list, and selecting it successfully translated the content into Simplified Chinese. The solution involved modifying only two files: TranslatedCaptionTrack.java and VideoInfo.java. The changes simply add support for Simplified Chinese subtitles without affecting any other subtitles. I hope you could consider incorporating this code into your main version. Thank you.

Describe alternatives you've considered

Modification approach (minimal intrusion, no reflection required):
1、Modify TranslatedCaptionTrack.java by adding a custom constructor and fields to allow it to work even without a TranslationLanguage object.

public class TranslatedCaptionTrack extends CaptionTrack {
public final static String TRANSLATE_MARKER = "*";
private final CaptionTrack mOriginTrack;
private final TranslationLanguage mLanguage;
private final String mTag;
// New: Fallback fields for hardcoded injection.
private final String mCustomLangCode;
private final String mCustomLangName;

// Keep the original constructor.
public TranslatedCaptionTrack(CaptionTrack originTrack, TranslationLanguage language, String tag) {
    mOriginTrack = originTrack;
    mLanguage = language;
    mTag = tag;
    mCustomLangCode = null;
    mCustomLangName = null;
}

// New: Create directly using language code and name.
public TranslatedCaptionTrack(CaptionTrack originTrack, String langCode, String langName) {
    mOriginTrack = originTrack;
    mLanguage = null;
    mTag = null;
    mCustomLangCode = langCode;
    mCustomLangName = langName;
}

@Override
public String getBaseUrl() {
    if (mOriginTrack == null) return null;
    if (mLanguage != null) {
        // Original logic remains.
        if (Helpers.equals(mOriginTrack.getLanguageCode(), mLanguage.getLanguageCode())) {
            return mOriginTrack.getBaseUrl();
        }
        return mOriginTrack.getBaseUrl() + "&tlang=" + mLanguage.getLanguageCode();
    } else {
        // When hardcoding, assume we always want translation (different from the original language) and directly construct the tlang.
        if (mCustomLangCode != null && !mCustomLangCode.equals(mOriginTrack.getLanguageCode())) {
            return mOriginTrack.getBaseUrl() + "&tlang=" + mCustomLangCode;
        }
        return mOriginTrack.getBaseUrl();
    }
}

......
}

  1. After merging the existing translation languages, inject Simplified Chinese.

private List mergeCaptionTracks() {
if (mMergedCaptionTracks == null) {
mMergedCaptionTracks = mCaptionTracks;

    if (mTranslationLanguages != null && mCaptionTracks != null) {
        CaptionTrack originTrack = findOriginTrack(mCaptionTracks);
        String tag = Helpers.runMultiMatcher(originTrack.getName(), tagPattern);
        for (TranslationLanguage language : mTranslationLanguages) {
            mMergedCaptionTracks.add(new TranslatedCaptionTrack(originTrack, language, tag));
        }
    }

    // ===== Inject Simplified Chinese (if missing).=====
    if (mCaptionTracks != null && !mCaptionTracks.isEmpty()) {
        boolean hasSimplified = false;
        for (CaptionTrack track : mMergedCaptionTracks) {
            String code = track.getLanguageCode();
            if ("zh-Hans".equals(code) || "zh-CN".equals(code)) {
                hasSimplified = true;
                break;
            }
        }
        if (!hasSimplified) {
            CaptionTrack origin = findOriginTrack(mCaptionTracks);
            if (origin != null) {
                mMergedCaptionTracks.add(new TranslatedCaptionTrack(origin, "zh-Hans", "中文(简体)"));
            }
        }
    }
    // =====================================
}
return mMergedCaptionTracks;

}

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions