what is the best way to do internationalization in php?

孤人 提交于 2019-12-06 12:39:03

问题


For a PHP-MySQL application, what is the best way to handle internationalization? Do I save the data in MySQL or flat files? Is there any standard library that comes with PHP or do I need to write my own functions?


回答1:


Use the new Internationalization module if you're using PHP 5.3. It uses the ICU library that's compatible with C/C++ and Java.

gettext() is on its way to becoming legacy code.




回答2:


You can use 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");
?>

This is the code sample from: http://www.php.net/manual/en/function.gettext.php



来源:https://stackoverflow.com/questions/4217065/what-is-the-best-way-to-do-internationalization-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!