English 中文(简体)
PHP - Mulilingual application design
原标题:

There are many ways to design a multilingual application in PHP. Some language file based, others database based.

  • I am looking to use it for mostly small amounts of text e.g errors - at most a paragraph.

  • I guess I will need twenty or so
    languages.

Really I am looking for recommendations rather than a definitive answer. What have you used before, what is fastest, easiest to update etc.

Many thanks,

最佳回答

The Gettext family of functions is a good starting point:

The gettext functions implement an NLS (Native Language Support) API which can be used to internationalize your PHP applications.

Zend_Translate is extremely flexible and has a thread-safe implementation of gettext. The manual states that it addresses the following problems with native internationalization implementations:

  • Inconsistent API: There is no single API for the different source formats. The usage of gettext for example is very complicated.
  • PHP supports only gettext and native array: PHP itself offers only support for array or gettext. All other source formats have to be coded manually, because there is no native support.
  • No detection of the default language:The default language of the user cannot be detected without deeper knowledge of the backgrounds for the different web browsers.
  • Gettext is not thread-safe: PHP s gettext library is not thread safe, and it should not be used in a multithreaded environment. This is due to problems with gettext itself, not PHP, but it is an existing problem.

It is worth noting that the Zend Framework is not a full-stack framework - in other words, you will not need to use the whole thing just to make use of its internationalization API.

What I really like about it is its support for multiple adapters for different data sources, which you can easily mix, match, and change only having to apply very light modifications to your application. Hope that helps.

问题回答

I dealt with both solutions. (database and flat file.) But i will give you another view angle. when you design your application or software there is an another important point you should think from the beginning. You will save your language items in database and flat file. the language support of database (or table) and text file is important. If you try to keep Turkish characters in latin 1 database you will face character some problems. Turkish is an example. The database must support your language item s characters.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签