开发者

How can i provide multi language and multi currency facility to my php Project?

I need to provide multi language and multi currency facility to my project. My team do开发者_运维技巧n't want to use Google language converter. How can i achieve this task. My project is related to hotel bookings and i'm developing this project using php. Please help me.


What you need is internationalisation. Often abbreviated to i18n.

Are you using a framework? Large web frameworks as Symfony, CakePHP, Code Igniter have i18n libraries integrated.

If you can configure the production server you can enable the PHP Intl.

i18n enables you to:

  1. format numbers as currency. As far as I know Symfony can also differentiate the currency format depending on language/culture so that in some countries it will be 5€ instead of €5
  2. format dates according language/culture
  3. translate translate text (obviously)


Have a read of PHP's gettext feature

http://www.php.net/manual/en/book.gettext.php


With the smarty template engine you can load translations from a config file and you can use custom modifiers to display the currency.


It is good practice to use constants in the source code for all human readable information, i.e.

define('COMMON_ERROR','An error occured.');
print COMMON_ERROR;
// instead of
print 'An error occured.';

For each language a file containing the defs is required; i.e.

if($_GET['mylang']){ require_once($_GET['mylang'].'.languagefile.php')}
else require_once('en.languagefile.php');

assuming that each language file has name of pattern 'language.languagefile.php' and contains the appropiate constants.


I used Zend Framework (Zend_Translate/_Currency) for a project with 6 languages (gettext) and 2 currencies and the result was quite worth the hassle. If you don't mind the steep learning curve of ZF...

As you can see from the earlier answers, your best bet is a framework with out-of-the-box i18n.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜