Skip to content

Commit

Permalink
fix(player/react): speed normal label not using translations
Browse files Browse the repository at this point in the history
closes #1021
  • Loading branch information
mihar-22 committed Nov 30, 2023
1 parent 42d0730 commit 1b72abc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,9 @@ function DefaultSpeedSubmenu() {
const { Icons } = React.useContext(DefaultLayoutContext),
label = useDefaultLayoutLang('Speed'),
normalText = useDefaultLayoutLang('Normal'),
options = usePlaybackRateOptions(),
options = usePlaybackRateOptions({
normalLabel: normalText,
}),
hint = options.selectedValue === '1' ? normalText : options.selectedValue + 'x';
return (
<MenuBase.Root className="vds-speed-menu vds-menu">
Expand Down
11 changes: 9 additions & 2 deletions packages/react/src/hooks/options/use-playback-rate-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import * as React from 'react';
import { useReactContext, useSignal } from 'maverick.js/react';
import { mediaContext } from 'vidstack';

const DEFAULT_RATES = [0.25, 0.5, 0.75, { label: 'Normal', rate: 1 }, 1.25, 1.5, 1.75, 2];
const DEFAULT_RATES = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2];

/**
* @docs {@link https://www.vidstack.io/docs/player/api/hooks/use-playback-rate-options}
*/
export function usePlaybackRateOptions({
rates = DEFAULT_RATES,
normalLabel = 'Normal',
}: UsePlaybackRateOptions = {}): PlaybackRateOptions {
const media = useReactContext(mediaContext)!,
{ playbackRate, canSetPlaybackRate } = media.$state;
Expand All @@ -19,7 +20,12 @@ export function usePlaybackRateOptions({

return React.useMemo(() => {
const options = rates.map<PlaybackRateOption>((opt) => {
const label = typeof opt === 'number' ? opt + 'x' : opt.label,
const label =
typeof opt === 'number'
? opt === 1 && normalLabel
? normalLabel
: opt + 'x'
: opt.label,
rate = typeof opt === 'number' ? opt : opt.rate;
return {
label,
Expand Down Expand Up @@ -52,6 +58,7 @@ export function usePlaybackRateOptions({

export interface UsePlaybackRateOptions {
rates?: (number | { label: string; rate: number })[];
normalLabel?: string | null;
}

export type PlaybackRateOptions = PlaybackRateOption[] & {
Expand Down

0 comments on commit 1b72abc

Please sign in to comment.