Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wrapper): Spicetify.Locale in Spotify v1.2.25+ #2675

Merged
merged 6 commits into from
Nov 23, 2023
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion jsHelper/spicetifyWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,60 @@ window.Spicetify = {
Locale: modules.find(m => m?._dictionary)
});

const localeModule = modules.find(m => m?.getTranslations);
if (localeModule) {
const createUrlLocale = functionModules.find(
m => m.toString().includes("has") && m.toString().includes("baseName") && m.toString().includes("language")
);
Spicetify.Locale = {
get _relativeTimeFormat() {
return localeModule._relativeTimeFormat;
},
get _dateTimeFormats() {
return localeModule._dateTimeFormats;
},
get _locale() {
return localeModule._localeForTranslation.baseName;
},
get _urlLocale() {
return localeModule._localeForURLPath;
},
get _dictionary() {
return localeModule._translations;
},
formatRelativeTime: (date, options) => localeModule.formatRelativeDate(date, options),
formatNumber: (number, options) => localeModule.formatNumber(number, options),
formatNumberCompact: (number, options) => localeModule.formatNumberCompact(number, options),
get: (key, children) => localeModule.get(key, children),
getDateTimeFormat: options => localeModule.getDateTimeFormat(options),
getDictionary: () => localeModule.getTranslations(),
getLocale: () => localeModule._localeForTranslation.baseName,
getSmartlingLocale: () => localeModule.getLocaleForSmartling(),
getUrlLocale: () => localeModule.getLocaleForURLPath(),
getRelativeTimeFormat: () => localeModule.getRelativeTimeFormat(),
getSeparator: () => localeModule.getSeparator(),
setLocale: locale => {
localeModule.initialize({
localeForTranslation: locale,
localeForFormatting: localeModule._localeForFormatting.baseName,
translations: localeModule._translations
});
},
setUrlLocale: locale => {
if (createUrlLocale) localeModule._localeForURLPath = createUrlLocale(locale);
},
setDictionary: dictionary => {
localeModule.initialize({
localeForTranslation: localeModule._localeForTranslation.baseName,
localeForFormatting: localeModule._localeForFormatting.baseName,
translations: dictionary
});
},
toLocaleLowerCase: text => localeModule.toLocaleLowerCase(text),
toLocaleUpperCase: text => localeModule.toLocaleUpperCase(text)
};
}

if (Spicetify.Locale) Spicetify.Locale._supportedLocales = cache.find(m => typeof m?.ja === "string");

Object.defineProperty(Spicetify, "Queue", {
Expand Down Expand Up @@ -1656,7 +1710,7 @@ Spicetify._cloneSidebarItem = function (list, isLibX = false) {

let appProper = manifest.name;
if (typeof appProper === "object") {
appProper = appProper[Spicetify.Locale.getLocale()] || appProper["en"];
appProper = appProper[Spicetify.Locale?.getLocale()] || appProper["en"];
}
if (!appProper) {
appProper = app[0].toUpperCase() + app.slice(1);
Expand Down