mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-05 02:39:46 +02:00
Update
This commit is contained in:
parent
c7c12525ea
commit
00f383eb49
16 changed files with 534 additions and 157 deletions
39
locale/function.js.php
Normal file
39
locale/function.js.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
if (empty($_GET['lang'])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$lang = preg_replace('/[^a-z0-9_]/i', '', $_GET['lang']);
|
||||
|
||||
$langFile = "./{$lang}.php";
|
||||
if(!file_exists($langFile)){
|
||||
return '';
|
||||
}
|
||||
|
||||
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, "'").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue