[英]I18n using PHP gettext()
我正在嘗試使用PHP gettext()翻譯我的網站,我已經實現了以下代碼:
if ( false === function_exists('gettext') ) {
echo "You do not have the gettext library installed with PHP.";
exit(1);
}
setlocale(LC_ALL, 'en_US.UTF-8');
$localedir = dirname(__FILE__) . '/Locale';
echo $localedir . ': ';
bindtextdomain('messages', $localedir);
textdomain('messages');
echo gettext("Hello");
exit(0);
但它似乎沒有用,因為它回顯了我在gettext()中傳遞的相同字符串。
我在關注https://blog.udemy.com/php-gettext/教程時使用poedit創建了* .po,*。em文件。
以上代碼摘自https://github.com/nota-ja/php-gettext-example/blob/master/index.php
但是,雖然有這樣的解決方案,我無法翻譯給定的內容。 任何形式的幫助將不勝感激。
謝謝!
你不必用function_exists等於false。 function_exists將檢查函數是否存在
if (function_exists('gettext')) {
// this function exists
}else{
echo "You do not have the gettext library installed with PHP.";
exit(1);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.