【发布时间】:2010-11-18 16:21:54
【问题描述】:
对于 PHP-MySQL 应用程序,处理国际化的最佳方式是什么?我将数据保存在 MySQL 还是平面文件中?有没有 PHP 自带的标准库,还是我需要自己写函数?
【问题讨论】:
标签: php mysql internationalization
对于 PHP-MySQL 应用程序,处理国际化的最佳方式是什么?我将数据保存在 MySQL 还是平面文件中?有没有 PHP 自带的标准库,还是我需要自己写函数?
【问题讨论】:
标签: php mysql internationalization
你可以使用gettext():
<?php
// Set language to German
putenv('LC_ALL=de_DE');
setlocale(LC_ALL, 'de_DE');
// Specify location of translation tables
bindtextdomain("myPHPApp", "./locale");
// Choose domain
textdomain("myPHPApp");
// Translation is looking for in ./locale/de_DE/LC_MESSAGES/myPHPApp.mo now
// Print a test message
echo gettext("Welcome to My PHP Application");
// Or use the alias _() for gettext()
echo _("Have a nice day");
?>
【讨论】:
如果您使用的是 PHP 5.3,请使用新的 Internationalization 模块。它使用与 C/C++ 和 Java 兼容的 ICU 库。
gettext() 正在成为遗留代码。
【讨论】: