Skip to content

Commit a498228

Browse files
committed
feat: video player i18n
Signed-off-by: Innei <i@innei.in>
1 parent f7dedf2 commit a498228

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

locales/app/en.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,15 @@
114114
"player.back_10s": "Back 10s",
115115
"player.close": "Close",
116116
"player.download": "Download",
117+
"player.exit_full_screen": "Exit Full Screen",
117118
"player.forward_10s": "Forward 10s",
119+
"player.full_screen": "Full Screen",
120+
"player.mute": "Mute",
118121
"player.open_entry": "Open Entry",
122+
"player.pause": "Pause",
123+
"player.play": "Play",
119124
"player.playback_rate": "Playback Rate",
125+
"player.unmute": "Unmute",
120126
"player.volume": "Volume",
121127
"search.empty.no_results": "No results found.",
122128
"search.group.entries": "Entries",

src/renderer/src/components/ui/media/VideoPlayer.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
useState,
2121
} from "react"
2222
import { useHotkeys } from "react-hotkeys-hook"
23+
import { useTranslation } from "react-i18next"
2324
import { createContext, useContext, useContextSelector } from "use-context-selector"
2425
import { useEventCallback } from "usehooks-ts"
2526

@@ -208,6 +209,7 @@ const FloatMutedButton = () => {
208209
}
209210

210211
const ControlBar = memo(() => {
212+
const { t } = useTranslation()
211213
const controls = useContextSelector(VideoPlayerContext, (v) => v.controls)
212214
const isPaused = useContextSelector(VideoPlayerContext, (v) => v.state.paused)
213215
const dragControls = useDragControls()
@@ -235,7 +237,7 @@ const ControlBar = memo(() => {
235237

236238
<ActionIcon
237239
shortcut="Space"
238-
label={isPaused ? "Play" : "Pause"}
240+
label={isPaused ? t("player.play") : t("player.pause")}
239241
className="center relative flex"
240242
onClick={() => {
241243
if (isPaused) {
@@ -268,6 +270,7 @@ const ControlBar = memo(() => {
268270
})
269271

270272
const FullScreenControl = () => {
273+
const { t } = useTranslation()
271274
const ref = useContextSelector(VideoPlayerContext, (v) => v.wrapperRef)
272275
const [isFullScreen, setIsFullScreen] = useState(!!document.fullscreenElement)
273276

@@ -283,7 +286,7 @@ const FullScreenControl = () => {
283286

284287
return (
285288
<ActionIcon
286-
label="Full Screen"
289+
label={isFullScreen ? t("player.exit_full_screen") : t("player.full_screen")}
287290
shortcut="f"
288291
labelDelayDuration={1}
289292
onClick={() => {
@@ -306,6 +309,7 @@ const FullScreenControl = () => {
306309
}
307310

308311
const DownloadVideo = () => {
312+
const { t } = useTranslation()
309313
const src = useContextSelector(VideoPlayerContext, (v) => v.src)
310314
const [isDownloading, setIsDownloading] = useState(false)
311315
const download = useEventCallback(() => {
@@ -324,7 +328,7 @@ const DownloadVideo = () => {
324328
})
325329

326330
return (
327-
<ActionIcon shortcut="d" label="Download" labelDelayDuration={1} onClick={download}>
331+
<ActionIcon shortcut="d" label={t("player.download")} labelDelayDuration={1} onClick={download}>
328332
{isDownloading ? (
329333
<i className="i-mgc-loading-3-cute-re animate-spin" />
330334
) : (
@@ -334,6 +338,7 @@ const DownloadVideo = () => {
334338
)
335339
}
336340
const VolumeControl = () => {
341+
const { t } = useTranslation()
337342
const hasAudio = useContextSelector(VideoPlayerContext, (v) => v.state.hasAudio)
338343

339344
const controls = useContextSelector(VideoPlayerContext, (v) => v.controls)
@@ -352,7 +357,11 @@ const VolumeControl = () => {
352357
}}
353358
labelDelayDuration={1}
354359
>
355-
{muted ? <i className="i-mgc-volume-mute-cute-re" /> : <i className="i-mgc-volume-cute-re" />}
360+
{muted ? (
361+
<i className="i-mgc-volume-mute-cute-re" title={t("player.unmute")} />
362+
) : (
363+
<i className="i-mgc-volume-cute-re" title={t("player.mute")} />
364+
)}
356365
</ActionIcon>
357366
)
358367
}
@@ -446,7 +455,7 @@ const ActionIcon = ({
446455
{children || <i className={className} />}
447456
</button>
448457
</TooltipTrigger>
449-
<TooltipContent className="flex items-center gap-1 bg-theme-modal-background">
458+
<TooltipContent className="flex items-center gap-1 text-xs">
450459
{label}
451460
{shortcut && <KbdCombined>{shortcut}</KbdCombined>}
452461
</TooltipContent>

0 commit comments

Comments
 (0)