Navigate to the appropriate language directory and execute the following command:
%>msgfmt messages.po
Executing this command produces a file named messages.mo, which is what gettext
will ultimately use for the translations.
Like xgettext, msgfmt also offers a number of features through options. Execute
msgfmt --help to learn more about what??™s available.
Step 6: Set the Desired Language Within Your Scripts
To begin taking advantage of your localized strings, all you need to do is set the locale
using setlocale() and call the bindtextdomain() and textdomain() functions as
demonstrated in Listing 23-1. The end result is the ability to use the same code
source to present your Web site in multiple languages. For instance, Figures 23-1 and
23-2 depict the same form, the first with the locale set to en_US and the second with
the locale set to it_IT.
Figure 23-1. A newsletter subscription form with English prompts
598 CHAPTER 23 ?– B U ILDING WE B SITES FOR THE WORLD
Figure 23-2. The same subscription form, this time in Italian
Of course, there??™s more to maintaining translations than what is demonstrated here.
For instance, you??™ll need to know how to merge and update .po files as the Web site??™s
content changes over time. Gettext offers a variety of utilities for doing exactly this;
consult the gettext documentation for more details.
While gettext is great for maintaining applications in multiple languages, it still
doesn??™t satisfy the need to localize other data such as numbers and dates.
Pages:
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683