parent
d3e6d7cd05
commit
cc63c3f3cd
@ -1,34 +1,31 @@
|
||||
import $ from 'jquery';
|
||||
import createAjaxRequest from 'Utilities/createAjaxRequest';
|
||||
|
||||
function getTranslations() {
|
||||
let localization = null;
|
||||
const ajaxOptions = {
|
||||
async: false,
|
||||
type: 'GET',
|
||||
global: false,
|
||||
dataType: 'json',
|
||||
url: `${window.Radarr.apiRoot}/localization`,
|
||||
url: '/localization',
|
||||
success: function(data) {
|
||||
localization = data.Strings;
|
||||
}
|
||||
};
|
||||
|
||||
ajaxOptions.headers = ajaxOptions.headers || {};
|
||||
ajaxOptions.headers['X-Api-Key'] = window.Radarr.apiKey;
|
||||
createAjaxRequest(ajaxOptions);
|
||||
|
||||
$.ajax(ajaxOptions);
|
||||
return localization;
|
||||
}
|
||||
|
||||
const translations = getTranslations();
|
||||
|
||||
export default function translate(key, args = '') {
|
||||
export default function translate(key, args) {
|
||||
const translation = translations[key] || key;
|
||||
|
||||
if (args) {
|
||||
const translatedKey = translate(key);
|
||||
return translatedKey.replace(/\{(\d+)\}/g, (match, index) => {
|
||||
return translation.replace(/\{(\d+)\}/g, (match, index) => {
|
||||
return args[index];
|
||||
});
|
||||
}
|
||||
|
||||
return translations[key] || key;
|
||||
return translation;
|
||||
}
|
||||
|
Loading…
Reference in new issue