Having considered various alternatives, I wrote down a set of requirements for the NLS
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
A real life application of this class is on my website at www.coralys.com. The
main page is available in English (en), Spanish (es) and Dutch (nl).
This class is very easy to use. The application would have something like this in its
$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.