开发者

what is the best way to do internationalization in php?

开发者 https://www.devze.com 2023-01-25 23:39 出处:网络
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 ne

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?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消