mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
New: Localization framework
This commit is contained in:
28
frontend/src/Utilities/String/translate.js
Normal file
28
frontend/src/Utilities/String/translate.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import $ from 'jquery';
|
||||
|
||||
function getTranslations() {
|
||||
let localization = null;
|
||||
const ajaxOptions = {
|
||||
async: false,
|
||||
type: 'GET',
|
||||
global: false,
|
||||
dataType: 'json',
|
||||
url: `${window.Radarr.apiRoot}/localization`,
|
||||
success: function(data) {
|
||||
localization = data.strings;
|
||||
}
|
||||
};
|
||||
|
||||
ajaxOptions.headers = ajaxOptions.headers || {};
|
||||
ajaxOptions.headers['X-Api-Key'] = window.Radarr.apiKey;
|
||||
|
||||
$.ajax(ajaxOptions);
|
||||
return localization;
|
||||
}
|
||||
|
||||
const translations = getTranslations();
|
||||
|
||||
export default function translate(key) {
|
||||
const formatedKey = key.charAt(0).toLowerCase() + key.slice(1);
|
||||
return translations[formatedKey] || key;
|
||||
}
|
Reference in New Issue
Block a user