PHPBuilder - Native Language Support Page 3

RSS Twitter

Native Language Support - Page 3

by: Didimo Emilio Grimaldo Tunon
February 13, 2001

CtNls - National Language Support

Having considered various alternatives, I wrote down a set of requirements for the NLS module:
  • It had to be simple, and based in PHP
  • Easy to use
  • Allow the user the freedom of choosing or mixing NLS methods
As a result, I developed a PHP class that would allow the user to set up a multi-lingual website. With this class, the developer can emulate the Apache approach of one file per language, without reconfiguring Apache. Additionally, it is possible to use a PHP script that generates the output in the appropriate language by means of message catalogs.
A real life application of this class is on my website at The main page is available in English (en), Spanish (es) and Dutch (nl).

Using CtNls

This class is very easy to use. The application would have something like this in its initialization code:



$nls = new CtNls
At that point, the class has detected the choice of languages suggested by the user behind the browser. What happens next depends on which method the application uses to provide multi-lingual content.
For static web pages, the approach is similar to the Apache convention. The name of the webpage comprises three parts: the base name, the language extension (two letter code per ISO standard) and the extension which would typically be ".html". For example a welcome page would be:
Notice that each page contains a different language. At this point, your PHP application would serve the file in the appropriate language, by specifying the whole name without the language ID/code. The CtNls class inserts the appropriate ID/code:


Here you can specify any filename that is valid to the PHP virtual() function, which is how LoadPage() delivers the content to the browser.

« Previous Page
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Didimo Emilio Grimaldo Tunon



(Maximum characters: 1200). You have characters left.