0
我想補充的多語言支持,我的網站,像這樣:PHP - 多語言支持
Language.php
:
class lang {
private $lang = null;
function __construct($lang) {
global $module;
$module['lang'] = true;
$this->lang = parse_ini_file("includes/languages/{$lang}.ini");
}
public function xlate($str) {
$arg_count = func_num_args();
if ($arg_count > 1) {
$params = func_get_args();
// strip first arg
array_shift($params);
} else {
$params = array();
}
$out_str = isset($this->lang[$str]) ? $this->lang[$str] : null;
if (!$out_str) {
throw new exception("Lang String Not Found: $str");
$this->lang = parse_ini_file("includes/languages/en_gb.ini");
}
return vsprintf($out_str, $params);
}
}
我則已經存儲在ini文件我的語言變量:
en_gb.ini
:
Support = Support
Quick Menu = Quick Menu
HOME_MAIN_TITLE = You will Get Paid
然後我用它喜歡:
echo $lang->xlate("Support");
echo $lang->xlate("Quick Menu");
echo $lang->xlate("HOME_MAIN_TITLE");
哪個有效。但是,每當我在語言傳遞'
的性格,這是行不通的:
HOME_MAIN_TITLE = You'll Get Paid
呼應的文字,直到'
字符:
You
然後停止。
我該如何解決這個問題?
嘗試在'''之前添加一個反斜槓,所以它變成'\''。這被稱爲轉義字符https://en.wikipedia.org/wiki/Escape_character –
看看突出顯示的文字。你的throw語句後面的行也不會被執行。 – Rangad
@KevinPei添加反斜槓不起作用。它只會打印:你\ – oliverbj