Because the differences
between British and United States English are minimal, largely confined to a few
spelling variants, you??™d only be required to maintain the few differing strings and
allow gettext() to default to the strings passed to the function for those it cannot find
in the repository.
?– Note You can find both the language and country codes as defined by ISO on many Web sites; just
search for the keywords ISO, country codes, and language codes. Table 23-1 offers a list of common
code combinations.
Listing 23-1 presents a simple example that seeks to translate the string Choose a
password: to its Italian equivalent.
Table 23-1. Common Country and Language Code Combinations
Combination Locale
pt_BR Brazil
fr_FR France
de_DE Germany
en_GB Great Britain
he_IL Israel
it_IT Italy
es_MX Mexico
es_ES Spain
en_US United States
594 CHAPTER 23 ?– B U ILDING WE B SITES FOR THE WORLD
Listing 23-1. Using gettext() to Support Multiple Languages
// Specify the target language
$language = 'it_IT';
// Assign the appropriate locale
setlocale(LC_ALL, $language);
// Identify the location of the translation files
bindtextdomain("messages", "/usr/local/apache/htdocs/locale");
// Tell the script which domain to search within when translating text
textdomain("messages");
?>
Of course, in order for Listing 23-1 to behave as expected, you need to create the
aforementioned translation repository and translate the strings according to the
desired language.
Pages:
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679