forked from kevinowino869/mitrobill
Auto Translate Language
This commit is contained in:
@ -8,9 +8,43 @@
|
||||
|
||||
class Lang
|
||||
{
|
||||
public static function T($var)
|
||||
public static function T($key)
|
||||
{
|
||||
return Lang($var);
|
||||
global $_L, $lan_file, $config;
|
||||
$L = $_SESSION['Lang'];
|
||||
if (!empty($_L[$key])) {
|
||||
return $_L[$key];
|
||||
}
|
||||
$val = $key;
|
||||
$md5 = md5($key);
|
||||
if (!empty($_L[$key])) {
|
||||
return $_L[$key];
|
||||
}else if (!empty($_L[$md5])) {
|
||||
return $_L[$md5];
|
||||
} else if (!empty($_L[str_replace(' ', '_', $key)])) {
|
||||
return $_L[str_replace(' ', '_', $key)];
|
||||
} else {
|
||||
$iso = Lang::getIsoLang()[$config['language']];
|
||||
if(!empty($iso) && !empty($val)){
|
||||
$temp = Lang::translate($val, $iso);
|
||||
if(!empty($temp)){
|
||||
$val = $temp;
|
||||
}
|
||||
}
|
||||
$key = md5($key);
|
||||
$_L[$key] = $val;
|
||||
$_SESSION['Lang'][$key] = $val;
|
||||
file_put_contents(File::pathFixer('system/lan/' . $config['language'] . '/common.lan.json'), json_encode($_SESSION['Lang']));
|
||||
return $val;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getIsoLang(){
|
||||
global $isolang;
|
||||
if(empty($isolang) || count($isolang)==0){
|
||||
$isolang = json_decode(file_get_contents(File::pathFixer("system/lan/country.json")),true);
|
||||
}
|
||||
return $isolang;
|
||||
}
|
||||
|
||||
public static function htmlspecialchars($var)
|
||||
@ -151,4 +185,25 @@ class Lang
|
||||
}
|
||||
return $textLeft.str_pad($textRight, $cols-strlen($textLeft), $pad_string, 0);
|
||||
}
|
||||
|
||||
public static function translate($txt, $to='id'){
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL,"https://translate.google.com/m?hl=en&sl=en&tl=$to&ie=UTF-8&prev=_m&q=".urlencode($txt));
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; CPU OS 13_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/28.1 Mobile/15E148 Safari/605.1.15");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
|
||||
curl_setopt ($ch, CURLOPT_HEADER, 0);
|
||||
$hasil = curl_exec ($ch);
|
||||
curl_close($ch);
|
||||
$temp = explode('<div class="result-container">', $hasil);
|
||||
if(count($temp)>0){
|
||||
$temp = explode("</div", $temp[1]);
|
||||
if(!empty($temp[0])){
|
||||
return $temp[0];
|
||||
}
|
||||
}
|
||||
return $txt;
|
||||
}
|
||||
}
|
||||
|
@ -78,11 +78,11 @@ class Paginator
|
||||
}
|
||||
|
||||
if ($page < $counter - 1) {
|
||||
$pagination .= "<li><a href='{$url}&p=$next&q=$query'>" . $_L['Next'] . "</a></li>";
|
||||
$pagination .= "<li><a href='{$url}&p=$lastpage&q=$query'>" . $_L['Last'] . "</a></li>";
|
||||
$pagination .= "<li><a href='{$url}&p=$next&q=$query'>" . Lang::T('Next') . "</a></li>";
|
||||
$pagination .= "<li><a href='{$url}&p=$lastpage&q=$query'>" . Lang::T('Last') . "</a></li>";
|
||||
} else {
|
||||
$pagination .= "<li class='disabled'><a class='disabled'>" . $_L['Next'] . "</a></li>";
|
||||
$pagination .= "<li class='disabled'><a class='disabled'>" . $_L['Last'] . "</a></li>";
|
||||
$pagination .= "<li class='disabled'><a class='disabled'>" . Lang::T('Next') . "</a></li>";
|
||||
$pagination .= "<li class='disabled'><a class='disabled'>" . Lang::T('Last') . "</a></li>";
|
||||
}
|
||||
$pagination .= "</ul>";
|
||||
|
||||
@ -184,11 +184,11 @@ class Paginator
|
||||
}
|
||||
|
||||
if ($page < $counter - 1) {
|
||||
$pagination .= "<li><a href='{$url}$next'>" . $_L['Next'] . "</a></li>";
|
||||
$pagination .= "<li><a href='{$url}$lastpage'>" . $_L['Last'] . "</a></li>";
|
||||
$pagination .= "<li><a href='{$url}$next'>" . Lang::T('Next') . "</a></li>";
|
||||
$pagination .= "<li><a href='{$url}$lastpage'>" . Lang::T('Last') . "</a></li>";
|
||||
} else {
|
||||
$pagination .= "<li class='disabled'><a class='disabled'>" . $_L['Next'] . "</a></li>";
|
||||
$pagination .= "<li class='disabled'><a class='disabled'>" . $_L['Last'] . "</a></li>";
|
||||
$pagination .= "<li class='disabled'><a class='disabled'>" . Lang::T('Next') . "</a></li>";
|
||||
$pagination .= "<li class='disabled'><a class='disabled'>" . Lang::T('Last') . "</a></li>";
|
||||
}
|
||||
$pagination .= "</ul>";
|
||||
|
||||
@ -278,11 +278,11 @@ class Paginator
|
||||
}
|
||||
|
||||
if ($page < $counter - 1) {
|
||||
$pagination .= "<li><a href='{$url}$next'>" . $_L['Next'] . "</a></li>";
|
||||
$pagination .= "<li><a href='{$url}$lastpage'>" . $_L['Last'] . "</a></li>";
|
||||
$pagination .= "<li><a href='{$url}$next'>" . Lang::T('Next') . "</a></li>";
|
||||
$pagination .= "<li><a href='{$url}$lastpage'>" . Lang::T('Last') . "</a></li>";
|
||||
} else {
|
||||
$pagination .= "<li class='disabled'><a class='disabled'>" . $_L['Next'] . "</a></li>";
|
||||
$pagination .= "<li class='disabled'><a class='disabled'>" . $_L['Last'] . "</a></li>";
|
||||
$pagination .= "<li class='disabled'><a class='disabled'>" . Lang::T('Next') . "</a></li>";
|
||||
$pagination .= "<li class='disabled'><a class='disabled'>" . Lang::T('Last') . "</a></li>";
|
||||
}
|
||||
$pagination .= "</ul>";
|
||||
|
||||
|
Reference in New Issue
Block a user