Skip to content

Commit 2704197

Browse files
Added translations to the audio latency test dialog (#212)
* Added translations to the audio latency test dialog * feat: add the `{key}` placeholder --------- Co-authored-by: apoint123 <108002475+apoint123@users.noreply.github.com>
1 parent d5f9f5e commit 2704197

3 files changed

Lines changed: 71 additions & 13 deletions

File tree

locales/en-US/translation.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,25 @@
333333
"workerError": "Error processing audio"
334334
}
335335
},
336+
"latencyTestDialog": {
337+
"title": "Timing Offset Latency Test",
338+
"description": "Choose your preferred BPM, then press the {key} key on each beep to measure the audio and input latency.",
339+
"latencyDisplay": {
340+
"fastest": "Fastest",
341+
"current": {
342+
"none": "Not Measured",
343+
"fast": "Early",
344+
"slow": "Late",
345+
"perfect": "Perfect"
346+
},
347+
"slowest": "Slowest"
348+
},
349+
"bpmInputLabel": "Tempo (BPM)",
350+
"button": {
351+
"start": "Start",
352+
"stop": "Stop"
353+
}
354+
},
336355
"lrclib": {
337356
"searchError": "Search failed, please check network or try again later",
338357
"importError": "Error occurred while importing lyrics",

locales/zh-CN/translation.json

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@
197197
"rubySegment": "注音分词",
198198
"advancedSegment": "高级分词...",
199199
"syncLineTimestamps": "同步行时间戳",
200-
"perWordRomanization":
201-
{
200+
"perWordRomanization": {
202201
"index": "逐字音译",
203202
"check": "检查逐字音译一致性",
204203
"distribute": "自动分配罗马音...",
@@ -332,6 +331,25 @@
332331
"workerError": "处理音频时出错"
333332
}
334333
},
334+
"latencyTestDialog": {
335+
"title": "打轴延迟测试",
336+
"description": "请选择自己喜欢的 BPM,并在每个蜂鸣声响起时按下 {key} 键,以测量音频/输入延迟差",
337+
"latencyDisplay": {
338+
"fastest": "最快延迟",
339+
"current": {
340+
"none": "未测量",
341+
"fast": "",
342+
"slow": "",
343+
"perfect": "完美"
344+
},
345+
"slowest": "最慢延迟"
346+
},
347+
"bpmInputLabel": "节拍 BPM",
348+
"button": {
349+
"start": "开始",
350+
"stop": "结束"
351+
}
352+
},
335353
"lrclib": {
336354
"searchError": "搜索失败,请检查网络或稍后重试",
337355
"importError": "导入歌词时发生错误",

src/modules/audio/modals/LatencyTest.tsx

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Button, Dialog, Flex, Text, TextField } from "@radix-ui/themes";
22
import { useAtom, useAtomValue } from "jotai";
33
import { memo, useEffect, useRef, useState } from "react";
4+
import { useTranslation } from "react-i18next";
5+
import { KeyBinding } from "$/components/KeyBinding";
46
import { audioEngine } from "$/modules/audio/audio-engine";
57
import {
68
latencyTestBPMAtom,
@@ -41,6 +43,7 @@ export const LatencyTestDialog = memo(() => {
4143
const hitOffsetsRef = useRef<number[]>([]);
4244
const visualizerRef = useRef<HTMLCanvasElement>(null);
4345
const beepDuration = 1000 / (latencyBPM / 60);
46+
const { t } = useTranslation();
4447

4548
useEffect(() => {
4649
if (!start || !dialogOpen) {
@@ -199,11 +202,18 @@ export const LatencyTestDialog = memo(() => {
199202
return (
200203
<Dialog.Root open={dialogOpen} onOpenChange={setDialogOpen}>
201204
<Dialog.Content>
202-
<Dialog.Title>打轴延迟测试</Dialog.Title>
205+
<Dialog.Title>
206+
{t("latencyTestDialog.title", "打轴延迟测试")}
207+
</Dialog.Title>
203208
<Flex direction="column" gap="2">
204209
<Text>
205-
请选择自己喜欢的
206-
BPM,并在每个蜂鸣声响起时按下打轴按键,以测量音频/输入延迟差
210+
{t(
211+
"latencyTestDialog.description",
212+
"请选择自己喜欢的 BPM,并在每个蜂鸣声响起时按下 {key} 键,以测量音频/输入延迟差",
213+
{
214+
key: <KeyBinding kbdAtom={keySyncNextAtom} />,
215+
},
216+
)}
207217
</Text>
208218

209219
<Flex
@@ -225,7 +235,9 @@ export const LatencyTestDialog = memo(() => {
225235
}}
226236
>
227237
<Text>
228-
{hitOffset === null ? "最快延迟" : `${hitOffset.max}ms`}
238+
{hitOffset === null
239+
? t("latencyTestDialog.latencyDisplay.fastest", "最快延迟")
240+
: `${hitOffset.max}ms`}
229241
</Text>
230242

231243
<Text
@@ -240,16 +252,23 @@ export const LatencyTestDialog = memo(() => {
240252
}
241253
>
242254
{hitOffset === null
243-
? "未测量"
255+
? t("latencyTestDialog.latencyDisplay.current.none", "未测量")
244256
: hitOffset.cur > 0
245-
? `快 ${hitOffset.cur}ms`
257+
? t("latencyTestDialog.latencyDisplay.current.fast", "快") +
258+
` ${hitOffset.cur}ms`
246259
: hitOffset.cur < 0
247-
? `慢 ${hitOffset.cur}ms`
248-
: "完美 0ms"}
260+
? t("latencyTestDialog.latencyDisplay.current.slow", "慢") +
261+
` ${hitOffset.cur}ms`
262+
: t(
263+
"latencyTestDialog.latencyDisplay.current.perfect",
264+
"完美",
265+
) + " 0ms"}
249266
</Text>
250267

251268
<Text>
252-
{hitOffset === null ? "最慢延迟" : `${-hitOffset.min}ms`}
269+
{hitOffset === null
270+
? t("latencyTestDialog.latencyDisplay.slowest", "最慢延迟")
271+
: `${-hitOffset.min}ms`}
253272
</Text>
254273
</Flex>
255274

@@ -267,7 +286,7 @@ export const LatencyTestDialog = memo(() => {
267286

268287
<Text as="label" size="2">
269288
<Flex direction="column" gap="2">
270-
节拍 BPM
289+
{t("latencyTestDialog.bpmInputLabel", "节拍 BPM")}
271290
<TextField.Root
272291
type="number"
273292
min={60}
@@ -280,7 +299,9 @@ export const LatencyTestDialog = memo(() => {
280299

281300
<Flex gap="2">
282301
<Button onClick={() => setStart((v) => !v)}>
283-
{start ? "结束" : "开始"}
302+
{start
303+
? t("latencyTestDialog.button.stop", "结束")
304+
: t("latencyTestDialog.button.start", "开始")}
284305
</Button>
285306
</Flex>
286307
</Flex>

0 commit comments

Comments
 (0)