Skip to content

Commit e5f9e98

Browse files
authored
feat(lyrics-plus): add select language translation for Musixmatch provider (#3288)
1 parent f345385 commit e5f9e98

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

CustomApps/lyrics-plus/OptionsMenu.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,18 @@ const TranslationMenu = react.memo(({ friendlyLanguage, hasTranslation }) => {
100100
ko: "Korean",
101101
};
102102

103-
let modeOptions = {};
103+
let modeOptions = {
104+
none: "None",
105+
};
104106

105107
if (hasTranslation.musixmatch) {
108+
const selectedLanguage = CONFIG.visual["musixmatch-translation-language"];
109+
const languageName = new Intl.DisplayNames([selectedLanguage], {
110+
type: "language",
111+
}).of(selectedLanguage);
106112
sourceOptions = {
107113
...sourceOptions,
108-
musixmatchTranslation: "English (Musixmatch)",
114+
musixmatchTranslation: `${languageName} (Musixmatch)`,
109115
};
110116
}
111117

CustomApps/lyrics-plus/ProviderMusixmatch.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,15 @@ const ProviderMusixmatch = (() => {
162162
const track_id = body?.["matcher.track.get"]?.message?.body?.track?.track_id;
163163
if (!track_id) return null;
164164

165+
const selectedLanguage = CONFIG.visual["musixmatch-translation-language"] || "none";
166+
if (selectedLanguage === "none") return null;
167+
165168
const baseURL =
166-
"https://apic-desktop.musixmatch.com/ws/1.1/crowd.track.translations.get?translation_fields_set=minimal&selected_language=en&comment_format=text&format=json&app_id=web-desktop-app-v1.0&";
169+
"https://apic-desktop.musixmatch.com/ws/1.1/crowd.track.translations.get?translation_fields_set=minimal&comment_format=text&format=json&app_id=web-desktop-app-v1.0&";
167170

168171
const params = {
169172
track_id,
173+
selected_language: selectedLanguage,
170174
usertoken: CONFIG.providers.musixmatch.token,
171175
};
172176

@@ -184,7 +188,10 @@ const ProviderMusixmatch = (() => {
184188

185189
if (!result.translations_list?.length) return null;
186190

187-
return result.translations_list.map(({ translation }) => ({ translation: translation.description, matchedLine: translation.matched_line }));
191+
return result.translations_list.map(({ translation }) => ({
192+
translation: translation.description,
193+
matchedLine: translation.matched_line,
194+
}));
188195
}
189196

190197
return { findLyrics, getKaraoke, getSynced, getUnsynced, getTranslation };

CustomApps/lyrics-plus/Settings.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,19 @@ const OptionList = ({ type, items, onChange }) => {
512512
);
513513
});
514514
};
515+
const languageCodes =
516+
"none,en,af,ar,bg,bn,ca,zh,cs,da,de,el,es,et,fa,fi,fr,gu,he,hi,hr,hu,id,is,it,ja,jv,kn,ko,lt,lv,ml,mr,ms,nl,no,pl,pt,ro,ru,sk,sl,sr,su,sv,ta,te,th,tr,uk,ur,vi,zu".split(
517+
","
518+
);
519+
520+
const displayNames = new Intl.DisplayNames(["en"], { type: "language" });
521+
const languageOptions = languageCodes.reduce((acc, code) => {
522+
acc[code] = code === "none" ? "None" : displayNames.of(code);
523+
return acc;
524+
}, {});
525+
526+
const savedLanguage = localStorage.getItem(`${APP_NAME}:visual:musixmatch-translation-language`) || "none";
527+
CONFIG.visual["musixmatch-translation-language"] = savedLanguage;
515528

516529
function openConfig() {
517530
const configContainer = react.createElement(
@@ -630,6 +643,14 @@ function openConfig() {
630643
max: thresholdSizeLimit.max,
631644
step: thresholdSizeLimit.step,
632645
},
646+
{
647+
desc: "Musixmatch Translation Language.",
648+
info: "Choose the language you want to translate the lyrics to. Changes will take effect after the next track.",
649+
key: "musixmatch-translation-language",
650+
type: ConfigSelection,
651+
options: languageOptions,
652+
defaultValue: savedLanguage,
653+
},
633654
],
634655
onChange: (name, value) => {
635656
CONFIG.visual[name] = value;

0 commit comments

Comments
 (0)