Fix Romanization <3

This commit is contained in:
2026-06-01 19:17:02 +10:00
parent f069d7eae2
commit fa273705ad
2 changed files with 20 additions and 18 deletions
+1 -1
View File
@@ -281,7 +281,7 @@ export const Settings = () => {
}} }}
/> />
<AnySwitch <AnySwitch
title="Romanize Lyrics | Beta" title="Romanize Lyrics"
desc="Display romanized (latin) text for non-latin lyrics (e.g. Korean, Japanese, Chinese)" desc="Display romanized (latin) text for non-latin lyrics (e.g. Korean, Japanese, Chinese)"
checked={romanizeLyrics} checked={romanizeLyrics}
onChange={(_: unknown, checked: boolean) => { onChange={(_: unknown, checked: boolean) => {
+19 -17
View File
@@ -49,6 +49,14 @@ const toastErr = (msg: string) =>
// clean up resources // clean up resources
export const unloads = new Set<LunaUnload>(); export const unloads = new Set<LunaUnload>();
// MARKER: Romanization Gate
const romanizedText = (
item: { text?: string | null; romanized?: string | null },
fallback = "",
): string =>
(settings.romanizeLyrics && item.romanized ? item.romanized : item.text) ??
fallback;
// MARKER: Player Market UI (Ensure new UI is enabled) // MARKER: Player Market UI (Ensure new UI is enabled)
function enablePlayerMarketUI() { function enablePlayerMarketUI() {
@@ -1852,17 +1860,13 @@ const formatLrcTime = (timeSeconds: number): string => {
const buildSyntheticLyricsText = (response: LyricsApiResponse): string => const buildSyntheticLyricsText = (response: LyricsApiResponse): string =>
response.data response.data
.map((line) => ("romanized" in line && line.romanized ? line.romanized : line.text)) .map((line) => romanizedText(line))
.filter((line) => line.trim().length > 0) .filter((line) => line.trim().length > 0)
.join("\n"); .join("\n");
const buildSyntheticLrcText = (response: LyricsApiResponse): string => const buildSyntheticLrcText = (response: LyricsApiResponse): string =>
response.data response.data
.map((line) => { .map((line) => `[${formatLrcTime(line.startTime)}]${romanizedText(line)}`)
const text =
("romanized" in line && line.romanized ? line.romanized : line.text) ?? "";
return `[${formatLrcTime(line.startTime)}]${text}`;
})
.join("\n"); .join("\n");
const registerSyntheticNativeLyrics = ( const registerSyntheticNativeLyrics = (
@@ -2432,19 +2436,19 @@ const normalizeLineData = (data: ApiLine[]): WordLine[] => {
: startMs + durationMs; : startMs + durationMs;
const safeSinger = line.element?.singer ?? "v1000"; const safeSinger = line.element?.singer ?? "v1000";
const safeKey = line.element?.key ?? `line-${idx}`; const safeKey = line.element?.key ?? `line-${idx}`;
const text = line.romanized ?? line.text; // Romanization Gate now decides which text to show (romanized or original)
return { return {
text, text: romanizedText(line),
startTime: startMs / 1000, startTime: startMs / 1000,
duration: durationMs / 1000, duration: durationMs / 1000,
endTime: endMs / 1000, endTime: endMs / 1000,
syllabus: [ syllabus: [
{ {
text: `${text} `, text: `${line.text} `,
time: startMs, time: startMs,
duration: Math.max(1, endMs - startMs), duration: Math.max(1, endMs - startMs),
isBackground: false, isBackground: false,
romanized: line.romanized ? `${line.romanized} ` : undefined,
}, },
], ],
element: { element: {
@@ -2805,9 +2809,7 @@ const buildWordSpans = (): {
return span; return span;
}; };
const useRomanized = settings.romanizeLyrics; const sylDisplay = (s: WordTiming) => romanizedText(s);
const sylDisplay = (s: WordTiming) =>
useRomanized && s.romanized != null ? s.romanized : s.text;
// Group syllables into words: trailing whitespace in syl.text marks a word boundary // Group syllables into words: trailing whitespace in syl.text marks a word boundary
const wordGroups: number[][] = []; const wordGroups: number[][] = [];
@@ -3028,10 +3030,10 @@ const buildTidalLines = (
let textIdx = 0; let textIdx = 0;
for (const tidalSpan of tidalSpans) { for (const tidalSpan of tidalSpans) {
const rawText = tidalSpan.textContent ?? ""; const rawText = tidalSpan.textContent ?? "";
const text = const text = romanizedText({
settings.romanizeLyrics && romanizedLines?.[textIdx] text: rawText,
? romanizedLines[textIdx] romanized: romanizedLines?.[textIdx],
: rawText; });
if (rawText.trim().length > 0) textIdx++; if (rawText.trim().length > 0) textIdx++;
if (rawText.trim().length === 0) { if (rawText.trim().length === 0) {
const spacer = document.createElement("div"); const spacer = document.createElement("div");