You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/frontend/src/Utilities/String/translate.js

32 lines
630 B

import createAjaxRequest from 'Utilities/createAjaxRequest';
function getTranslations() {
let localization = null;
const ajaxOptions = {
async: false,
dataType: 'json',
url: '/localization',
success: function(data) {
localization = data.strings;
}
};
createAjaxRequest(ajaxOptions);
return localization;
}
const translations = getTranslations();
export default function translate(key, args = '') {
const translation = translations[key] || key;
if (args) {
return translation.replace(/\{(\d+)\}/g, (match, index) => {
return args[index];
});
}
return translation;
}