10.7. Internationalization

 < Day Day Up > 

RT can be configured to run in a variety of languages and has a lot of support internally for internationalization.

10.7.1. How RT's I18N FrameworkI18N Framework

Most of the text generated by RT is localized, except for log messages. Depending on what type of code you are writing, there are a few different ways to access RT's localization functions.

Inside a module such as a script condition or overlay RT offers the methods loc( ) and loc_fuzzy( ).

Inside Mason components, there is a globally available function loc( ) which does the same thing. If you want to localize a piece of inline text inside a component, you can wrap it in a filtering component call, like this:

     <&|/l>My text</&> 

This calls a Mason component that runs your text through an I18N filter and outputs the result.

10.7.2. Writing Internationalized Code

Whenever you generate a piece of text to be presented to the end user, you should use RT's I18N framework. Under the hood, RT uses Locale::Maketext and Locale::Maketext::Lexicon to implement I18N.

10.7.2.1. Bracket notation

To specify the string to localize, Locale::Maketext uses bracket notation, which is a mini-templating system. When localizing a string, you often need to interpolate variables. For example, if you want to localize "Found 6 tickets," you want to make the number of tickets found a variable. In bracket notation that would be Found [*,_1,ticket]. This tells the I18N system that the first parameter is some quantity of tickets. This allows it to properly pluralize "ticket." The first part of the notation, *, is shorthand for the quant method in Locale::Maketext.

Complete documentation of this notation can be found in the documentation for Locale::Maketext, and there are plenty of examples of its usage in the RT core code.

10.7.3. Localizing RT

Each localization of RT is contained in a single .po file installed under lib/RT/I18N. These files simply contain pairs of strings as found in the source, and their translated versions. For example, in the French translation, fr.po, we can see:

     #: lib/RT/Group_Overlay.pm:1160     msgid "Group has no such member"     msgstr "Un tel membre n'appartient pas au groupe" 

The msgid is what is passed in the call to the localization method, and the msgstr is the translated version.

RT comes with a utility to generate an empty message catalog for a new translation. Simply run the script extract-message-catalog from the root of your RT installation and give it the filename for the new catalog you would like created.

The new catalog will create a new empty catalog, along with comments indicating where each msgid comes from, as in the above example.

This script is not installed in a normal RT installation, but it is available from the source tarball.

     < Day Day Up > 


    RT Essentials
    RT Essentials
    ISBN: 0596006683
    EAN: 2147483647
    Year: 2005
    Pages: 166

    Similar book on Amazon

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net