1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00
Daniel Neto 2023-08-30 15:30:55 -03:00
parent 1c43940ab9
commit ad3a416bd6
3 changed files with 27 additions and 22 deletions

View file

@ -15,25 +15,3 @@ include_once $langFile;
header('Content-Type: application/javascript');
?>
var translations = <?php echo json_encode($t); ?>;
function __(str, allowHTML = false) {
let returnStr = str;
// Check if translation exists for exact string
if (translations.hasOwnProperty(str)) {
returnStr = translations[str];
} else {
// Case insensitive check
let lowerCaseKey = Object.keys(translations).find(key => key.toLowerCase() === str.toLowerCase());
if (lowerCaseKey) {
returnStr = translations[lowerCaseKey];
}
}
if (allowHTML) {
return returnStr;
}
// Escape certain characters for security
return returnStr.replace(/'/g, "&apos;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}

View file

@ -245,6 +245,7 @@ $t['Invalid Captcha'] = 'Captcha inválido';
$t['Invalid Email'] = 'Email inválido';
$t['Invalid'] = 'Inválido';
$t['Is not logged'] = 'não está logado';
$t['is required'] = 'é obrigatório';
$t['Issues on github'] = 'Problemas no github';
$t['Language'] = 'Linguagem';
$t['Last 15 Days'] = 'Últimos 15 dias';

View file

@ -3973,3 +3973,29 @@ function addCloseButton(elementToAppend) {
}
}
function __(str, allowHTML = false) {
if(typeof translations == 'undefined'){
return str;
}
let returnStr = str;
// Check if translation exists for exact string
if (translations.hasOwnProperty(str)) {
returnStr = translations[str];
} else {
// Case insensitive check
let lowerCaseKey = Object.keys(translations).find(key => key.toLowerCase() === str.toLowerCase());
if (lowerCaseKey) {
returnStr = translations[lowerCaseKey];
}
}
if (allowHTML) {
return returnStr;
}
// Escape certain characters for security
return returnStr.replace(/'/g, "&apos;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}