我试图让一个简单的gettext工作,但我只是回到英文版。我从未做过任何多语言支持,所以这对我来说是非常新的。我在Windows测试服务器上使用php版本5.5.28但是生产将在ubuntu服务器上。这是我正在使用的简单的PHP代码。 GET [' lang'] =' es_ES'对于这个测试。
$language = $_GET['lang'];
echo $language . '<br>';
putenv( "LANG=$language" );
setlocale( LC_ALL, $language );
$domain = 'messages';
echo CORE_PATH . "locale";
echo '<br>';
bindtextdomain( $domain, CORE_PATH . "locale" );
textdomain( $domain );
echo gettext( "A string to be translated would go here" );
echo '<br>';
echo _( 'test' );
echo '<br>';
这是语言环境目录
├───en_US
│ └───LC_MESSAGES
└───es_ES
└───LC_MESSAGES
├───messages.po
└───messages.mo
这是message.po,如果它有帮助
msgid ""
msgstr ""
"Project-Id-Version: csc-pathways\n"
"POT-Creation-Date: 2017-07-10 11:07-0700\n"
"PO-Revision-Date: 2017-07-10 11:08-0700\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.0.2\n"
"X-Poedit-Basepath: ../../../pages\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-SearchPath-0: .\n"
#: test.php:20
msgid "A string to be translated would go here"
msgstr "Una cadena a traducir iría aquí"
#: test.php:22
msgid "test"
msgstr "prueba"