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.
35 lines
760 B
35 lines
760 B
import $ from 'jquery';
|
|
|
|
function getTranslations() {
|
|
let localization = null;
|
|
const ajaxOptions = {
|
|
async: false,
|
|
type: 'GET',
|
|
global: false,
|
|
dataType: 'json',
|
|
url: `${window.Lidarr.apiRoot}/localization`,
|
|
success: function(data) {
|
|
localization = data.Strings;
|
|
}
|
|
};
|
|
|
|
ajaxOptions.headers = ajaxOptions.headers || {};
|
|
ajaxOptions.headers['X-Api-Key'] = window.Lidarr.apiKey;
|
|
|
|
$.ajax(ajaxOptions);
|
|
return localization;
|
|
}
|
|
|
|
const translations = getTranslations();
|
|
|
|
export default function translate(key, args = '') {
|
|
if (args) {
|
|
const translatedKey = translate(key);
|
|
return translatedKey.replace(/\{(\d+)\}/g, (match, index) => {
|
|
return args[index];
|
|
});
|
|
}
|
|
|
|
return translations[key] || key;
|
|
}
|