Docs for page Translation.php

## /Translation.php

Description

Functions involved in translating with gettext

- author: Andrew McMillan <andrew@mcmillan.net.nz>
- copyright: Catalyst IT Ltd
- license: GNU GPL v2 or later

Functions
awl_set_locale (line 99)

Set the translation to the user's locale. At this stage all we do is call the gettext function.

void awl_set_locale ( $locale)

- $locale

i18n (line 54)

Mark a string as being internationalized. This is a semaphore method; it does nothing but it allows us to easily identify strings that require translation. Generally this is used to mark strings that will be stored in the database (like descriptions of permissions).

AWL uses GNU gettext for internationalization (i18n) and localization (l10n) of text presented to the user. Gettext needs to know about all places involving strings, that must be translated. Mark any place, where localization at runtime shall take place by using the function translate().

In the help I have used 'xlate' rather than 'translate' and 'x18n' rather than 'i18n' so that the tools skip this particular file for translation :-)

E.g. instead of: print 'TEST to be displayed in different languages'; use: print xlate('TEST to be displayed in different languages'); and you are all set for pure literals. The translation teams will receive that literal string as a job to translate and will translate it (when the message is clear enough). At runtime the message is then localized when printed. The input string can contain a hint to assist translators: print xlate('TT <!-- abbreviation for Translation Test -->'); The hint portion of the string will not be printed.

But consider this case: $message_to_be_localized = 'TEST to be displayed in different languages'; print xlate($message_to_be_localized);

The translate() function is called in the right place for runtime handling, but there is no message at gettext preprocessing time to be given to the translation teams, just a variable name. Translation of the variable name would break the code! So all places potentially feeding this variable have to be marked to be given to translation teams, but not translated at runtime!

This method resolves all such cases. Simply mark the candidates: $message_to_be_localized = x18n('TEST to be displayed in different languages'); print xlate($message_to_be_localized);

- return: the same value

string i18n (string $value)

- string $value: the value

init_gettext (line 84)

Initialise our use of Gettext

void init_gettext ( $domain, $location)

- $domain
- $location

translate (line 65)

Convert a string in English to whatever this user's locale is

void translate ( $en)

- $en

Documentation generated on Fri, 13 Jan 2012 23:40:17 +1300 by phpDocumentor 1.4.3