mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2026-04-20 22:14:34 -04:00
UI loading improvements
Fixed: Caching for dynamically loaded JS files Fixed: Incorrect caching of initialize.js (cherry picked from commit f0cb5b81f140c67fa84162e094cc4e0f3476f5da)
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import createAjaxRequest from 'Utilities/createAjaxRequest';
|
||||
|
||||
function getTranslations() {
|
||||
return createAjaxRequest({
|
||||
global: false,
|
||||
dataType: 'json',
|
||||
url: '/localization',
|
||||
}).request;
|
||||
}
|
||||
|
||||
let translations: Record<string, string> = {};
|
||||
|
||||
export async function fetchTranslations(): Promise<boolean> {
|
||||
return new Promise(async (resolve) => {
|
||||
try {
|
||||
const data = await getTranslations();
|
||||
translations = data.Strings;
|
||||
|
||||
resolve(true);
|
||||
} catch (error) {
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export default function translate(
|
||||
key: string,
|
||||
args?: (string | number | boolean)[]
|
||||
) {
|
||||
const translation = translations[key] || key;
|
||||
|
||||
if (args) {
|
||||
return translation.replace(/\{(\d+)\}/g, (match, index) => {
|
||||
return String(args[index]) ?? match;
|
||||
});
|
||||
}
|
||||
|
||||
return translation;
|
||||
}
|
||||
Reference in New Issue
Block a user