1. 程式人生 > >php i18n gettext 實現多語言

php i18n gettext 實現多語言

<?php

header("Content-type: text/html; charset=utf-8");

$lng = $_GET['lng'] ? $_GET['lng'] :'zh_TW';

$domain = 'test';

putenv('LANG='.$lng); 

setlocale(LC_ALL, $lng); // 指定要用的語系,如:en_US、zh_CN、zh_TW 

bindtextdomain($domain, '/home/dfct/test'); 

bind_textdomain_codeset($domain, 'UTF-8'); 

textdomain($domain); 

//($_ENV);

// E:/wwwroot/test/zh_TW/LC_MESSAGES/test.mo 

echo _("中文"); 

E:\wwwroot\test\en_US\LC_MESSAGES\test.mo

生成po 和pot檔案用 poedit 比較方便