#native_company# #native_desc#
#native_cta#

Native Language Support Page 3

By Didimo Emilio Grimaldo Tunon
on 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 www.coralys.com. 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:

<?php

include('ctnls.class.php');

$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:
welcome.en.html
welcome.es.html
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:

<?php

$nls->LoadPage("welcome.html");

   

?>



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