言語配列ベースを翻訳するクラスがあります。問題は、クッキーの値に基づいて言語が変更されないことです。
この関数は言語値を設定する必要がありますが、設定しません。私が何をしても、常に "ar" を self::$currlang 値として取得しているようです。どうすればこの問題を修正できますか?
public function _set(){
if( $_COOKIE['defaultLang'] != '' ) {
self::$currlang = $_COOKIE['defaultLang'];
} else {
//this is the default language
self::$currlang = 'ar';
}
}
ここに私のコードがあります
ご協力いただきありがとうございます :)
<?php
include('../langs/english.php');
include('../langs/arabic.php');
class Translator{
private static $strs = array();
private static $currlang = "";
public function _set(){
if( $_COOKIE['defaultLang'] != '' ) {
self::$currlang = $_COOKIE['defaultLang'];
} else {
//this is the default language
self::$currlang = 'ar';
}
}
public static function loadTranslation($lang, $strs){
if (empty(self::$strs[$lang]))
self::$strs[$lang] = array();
self::$strs[$lang] = array_merge(self::$strs[$lang], $strs);
}
public static function setDefaultLang($lang){
self::$currlang = $lang;
}
public static function getDefaultLang(){
return self::$currlang;
}
public static function translate($key, $lang=""){
if ($lang == ""){
$lang = self::$currlang;
}
$str = self::$strs[$lang][$key];
if (empty($str)){
//$str = "$lang.$key";
$str = 'Language "'. $lang . '", '. $key . ' is not defined.';
}
return $str;
}
public static function freeUnused(){
foreach(self::$strs as $lang => $data){
if ($lang != self::$currlang){
$lstr = self::$strs[$lang]['langname'];
self::$strs[$lang] = array();
self::$strs[$lang]['langname'] = $lstr;
}
}
}
public static function getLangList(){
$list = array();
foreach(self::$strs as $lang => $data){
$h['name'] = $lang;
$h['desc'] = self::$strs[$lang]['langname'];
$h['current'] = $lang == self::$currlang;
$list[] = $h;
}
return $list;
}
public static function &getAllStrings($lang){
return self::$strs[$lang];
}
}
?>