我一直在尝试使用gettext一周,但我无法使其工作。我仅将C
语言环境用于测试目的。这是我的test.php
文件:
<?php
$locales = array( "C", "es", "es_ES", "es_ES.UTF-8", "es_ES.utf8", "es-ES" );
if (( $setTo = setlocale( LC_ALL, $locales )) === FALSE ){
echo "Unable to set a locale that the OS recognises.<br>";
}else{
echo "Set LC_ALL to " . $setTo . "<br>";
putenv("LANGUAGE=".$setTo); // returns 1
}
$charset = "UTF-8";
$domain = "strings";
echo bindtextdomain($domain, "./Locale") . "<br>";
bind_textdomain_codeset($domain, $charset);
textdomain($domain);
echo gettext("test");
?>
这是我的strings.po文件:
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2017-09-15 17:27:32+02:00\n"
"PO-Revision-Date: 2017-09-21 21:18+0200\n"
"Last-Translator: FULL NAME MAIL\n"
"Language-Team: None, sorry\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: es_ES\n"
"X-Generator: Poedit 2.0.3\n"
msgctxt "TESTING"
msgid "test"
msgstr "gettext is working"
这是我的树视图:
./Locale/
├── [drwxr-xr-x] C
│ └── [drwxr-xr-x] LC_MESSAGES
│ ├── [-rwxr-xr-x] strings.mo
│ └── [-rwxr-xr-x] strings.po
├── [lrwxrwxrwx] es_ES -> C
└── [lrwxrwxrwx] es_ES.UTF-8 -> C
4 directories, 2 files
怎么了?