PHP, MultiLanguage, PO MO gettext() 多國語言版本

PHP, MultiLanguage, PO MO gettext() 多國語言版本

在php 要如何做多國語言支援? 下面的步驟可以說明

請把下面的php code 存起來

#. tset.php


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>

$domain = ‘messages’;
bindtextdomain($domain, "includes/translations");

$iso_codes = array (
foreach ($iso_codes as $iso_code => $language) {
putenv (‘LANG=’.$iso_code);      //Print out the language name and greeting
setlocale(LC_ALL, $iso_code);    //Filter the greeting through gettext
echo $iso_code;
printf ("%12s: %s\n", $language, gettext("str_hello")) &amp;amp; "\n";
echo gettext("txt");
echo gettext("str_hello");
echo gettext("URL");
echo gettext("Row");
echo  ‘<br>’;

setlocale(‘LC_ALL’, "nl_NL");
bindtextdomain("greetings", "./locale/");

echo _("Hello World");


#. 然後下載工具 Poedit

$./xgettext -n *.php

如果是中文的 _(“中文”) 就要用

$ ./xgettext –from-code=UTF-8 -n  *.php

tset.php messages.po

#. Use Poedit to edit .po file and convert string, and save to .mo (msgfmt.exe)
#. COPY .po and .mo  \includes\translations\zh\LC_MESSAGES\messages.po and messages.po

01 StringCH02 ArrayCH03 檔案