Skip to content

Commit

Permalink
Add language variations (#671)
Browse files Browse the repository at this point in the history
Co-authored-by: Felipe Marinho <[email protected]>
  • Loading branch information
felipemarinho97 and felipemarinho97 authored Nov 11, 2024
1 parent 049f4b0 commit 8312c66
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
15 changes: 6 additions & 9 deletions front/packages/ui/src/settings/playback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@
* along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
*/

import { useLocalSetting } from "@kyoo/models";
import { Select } from "@kyoo/primitives";
import { useTranslation } from "react-i18next";
import { languageCodes, useLanguageName } from "../utils";
import { Preference, SettingsContainer, useSetting } from "./base";

import { useLocalSetting } from "@kyoo/models";
import { Select } from "@kyoo/primitives";
import SubtitleLanguage from "@material-symbols/svg-400/rounded/closed_caption-fill.svg";
import PlayModeI from "@material-symbols/svg-400/rounded/display_settings-fill.svg";
import AudioLanguage from "@material-symbols/svg-400/rounded/music_note-fill.svg";
import intl from "langmap";
import { useLanguageName } from "../utils";

const allLanguages = Object.keys(intl).filter((x) => !x.includes("-") && !x.includes("@"));
import { useTranslation } from "react-i18next";

export const PlaybackSettings = () => {
const { t } = useTranslation();
Expand Down Expand Up @@ -62,7 +59,7 @@ export const PlaybackSettings = () => {
label={t("settings.playback.audioLanguage.label")}
value={audio}
onValueChange={(value) => setAudio(value)}
values={["default", ...allLanguages]}
values={["default", ...languageCodes]}
getLabel={(key) =>
key === "default" ? t("mediainfo.default") : (getLanguageName(key) ?? key)
}
Expand All @@ -77,7 +74,7 @@ export const PlaybackSettings = () => {
label={t("settings.playback.subtitleLanguage.label")}
value={subtitle ?? "none"}
onValueChange={(value) => setSubtitle(value === "none" ? null : value)}
values={["none", "default", ...allLanguages]}
values={["none", "default", ...languageCodes]}
getLabel={(key) =>
key === "none"
? t("settings.playback.subtitleLanguage.none")
Expand Down
15 changes: 15 additions & 0 deletions front/packages/ui/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,18 @@ export const useDisplayName = () => {
return "Unknown";
};
};

const seenNativeNames = new Set();

export const languageCodes = Object.keys(intl)
.filter((x) => {
const nativeName = intl[x]?.nativeName;

// Only include if nativeName is unique and defined
if (nativeName && !seenNativeNames.has(nativeName)) {
seenNativeNames.add(nativeName);
return true;
}
return false;
})
.filter((x) => !x.includes("@"));

0 comments on commit 8312c66

Please sign in to comment.