Skip to content

Commit

Permalink
chg: feat: display subtitle attributtes on player
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemarinho97 committed Jan 3, 2025
1 parent e57afc5 commit e711080
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion front/packages/ui/src/components/media-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const MediaInfoTable = ({
// Only show it if there is more than one track
track.isDefault && !singleTrack ? t("mediainfo.default") : undefined,
track.isForced ? t("mediainfo.forced") : undefined,
track.isHearingImpaired ? t("mediainfo.hearing-impaired") : undefined,
"isHearingImpaired" in track && track.isHearingImpaired ? t("mediainfo.hearing-impaired") : undefined,
"isExternal" in track && track.isExternal ? t("mediainfo.external") : undefined,
track.codec,
]
Expand Down
5 changes: 3 additions & 2 deletions front/packages/ui/src/player/components/right-buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { useAtom } from "jotai";
import { useTranslation } from "react-i18next";
import { Platform, View } from "react-native";
import { type Stylable, useYoshiki } from "yoshiki/native";
import { useDisplayName } from "../../utils";
import { useDisplayName, useSubtitleName } from "../../utils";
import { fullscreenAtom, subtitleAtom } from "../state";
import { AudiosMenu, QualitiesMenu } from "../video";

Expand All @@ -50,6 +50,7 @@ export const RightButtons = ({
const { css } = useYoshiki();
const { t } = useTranslation();
const getDisplayName = useDisplayName();
const getSubtitleName = useSubtitleName();
const [isFullscreen, setFullscreen] = useAtom(fullscreenAtom);
const [selectedSubtitle, setSubtitle] = useAtom(subtitleAtom);

Expand All @@ -74,7 +75,7 @@ export const RightButtons = ({
{subtitles.map((x, i) => (
<Menu.Item
key={x.index ?? i}
label={x.link ? getDisplayName(x) : `${getDisplayName(x)} (${x.codec})`}
label={x.link ? getSubtitleName(x) : `${getSubtitleName(x)} (${x.codec})`}
selected={selectedSubtitle === x}
disabled={!x.link}
onSelect={() => setSubtitle(x)}
Expand Down
26 changes: 23 additions & 3 deletions front/packages/ui/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
import type { Track } from "@kyoo/models";
import type { Subtitle, Track } from "@kyoo/models";

import intl from "langmap";
import { useTranslation } from "react-i18next";

export const useLanguageName = () => {
return (lang: string) => intl[lang]?.nativeName;
};

export const useDisplayName = () => {
const getLanguageName = useLanguageName();
const { t } = useTranslation();

return (sub: Track) => {
const lng = sub.language ? getLanguageName(sub.language) : null;

if (lng && sub.title && sub.title !== lng) return `${lng} - ${sub.title}`;
if (lng) return lng;
if (sub.title) return sub.title;
if (sub.index !== null) return `Unknown (${sub.index})`;
return "Unknown";
if (sub.index !== null) return `${t("mediainfo.unknown")} (${sub.index})`;
return t("mediainfo.unknown");
};
};

export const useSubtitleName = () => {
const getDisplayName = useDisplayName();
const { t } = useTranslation();

return (sub: Subtitle) => {
const name = getDisplayName(sub);
const attributes = [name];

if (sub.isDefault) attributes.push(t("mediainfo.default"));
if (sub.isForced) attributes.push(t("mediainfo.forced"));
if (sub.isHearingImpaired) attributes.push(t("mediainfo.hearing-impaired"));
if (sub.isExternal) attributes.push(t("mediainfo.external"));

return attributes.join(" - ");
}
}

const seenNativeNames = new Set();

export const languageCodes = Object.keys(intl)
Expand Down
3 changes: 2 additions & 1 deletion front/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@
"duration": "Duration",
"size": "Size",
"novideo": "No video",
"nocontainer": "Invalid container"
"nocontainer": "Invalid container",
"unknown": "Unknown"
},
"admin": {
"users": {
Expand Down
3 changes: 2 additions & 1 deletion front/translations/pt_br.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@
"size": "Tamanho",
"novideo": "Sem vídeo",
"nocontainer": "Contêiner inválido",
"external": "Externo"
"external": "Externo",
"unknown": "Desconhecido"
},
"admin": {
"users": {
Expand Down

0 comments on commit e711080

Please sign in to comment.