Skip to content

Commit

Permalink
Update language code and name formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
IanDesuyo committed Jan 4, 2025
1 parent 07032f2 commit e8d6fad
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions extension/src/pages/youtube-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,22 @@ const appendTranslatedTracks = (tracks: any, tlang: string) => {
for (const track of tracks) {
// Ignore subtitles that are already in the target language
if (track.languageCode !== tlang) {
const translatedTrack = {
const translatedTrack = {
...track,
languageCode:`${track.languageCode} >> ${tlang}`,
baseUrl: `${track.baseUrl}&tlang=${tlang}` // YouTube API param for translation
name: {
simpleText: `${track.name?.simpleText} >> ${tlang}`,
runs: track.name?.runs?.map((run: any) => ({ ...run, text: `${run.text} >> ${tlang}` })),
},
languageCode: tlang,
baseUrl: `${track.baseUrl}&tlang=${tlang}`, // YouTube API param for translation
};

translatedTracks.push(translatedTrack);
}
}


return translatedTracks;
}
};

document.addEventListener(
'asbplayer-get-synced-data',
Expand Down Expand Up @@ -111,9 +114,10 @@ document.addEventListener(
}

response.basename = playerContext.videoDetails?.title || document.title;
response.subtitles = appendTranslatedTracks(playerContext?.captions?.playerCaptionsTracklistRenderer?.captionTracks || [], TLANG).map(
adaptYtTrack
);
response.subtitles = appendTranslatedTracks(
playerContext?.captions?.playerCaptionsTracklistRenderer?.captionTracks || [],
TLANG
).map(adaptYtTrack);
} catch (error) {
if (error instanceof Error) {
response.error = error.message;
Expand Down

0 comments on commit e8d6fad

Please sign in to comment.