i18n.php

Support functions for internationalization.

This file activates support for the GNU gettext extension if it is loaded and falls back to an ad hoc system using native PHP functions otherwise.

Functions
_
function _(
$str
)

Mimics the behavior of gettext.

Parameters
str

The string to translate.

Returns

The translated string.  If no translated version is found for the current language, then the str parameter is returned.

lang_js
function lang_js(
$langfalse
)

Gets a link to the JavaScript translation file for the configured language.  This should be linked into any page that generates text from JavaScript.  If the correct translation file does not exist, then use the English file.

fmtdate
function fmtdate(
$fmt,
$tsfalse
)

Print a formatted date.

This function exists because strftime prints localized strings using the local character set.  So, for example, if you are running on Windows and set the locale to "rus" (Russian"), then you get a the Windows Russian date, which is in whatever 2-byte encoding Windows uses for Russian.  Needless to say, this breaks the page.

The ugly, hacky solution is to offer the user the alternative of using strftime, which respects the locale and hence causes problems, or date, which is stupid and ignores the locale.

Note that this function now attempts to auto-convert from strftime() format codes to date() format codes.  Since all strftime() codes start with a %, old code that uses date() codes will be unaffacted.

Parameters
fmt

The format string for the date

ts

The optional timestamp to use for the date.

Returns

The formatted date string.

p_
function p_(
$str
)

A convenience funtion to print a translated string.

Parameters
str

The string to translate.

pf_
function pf_()

A convenience function that mixes translation with printf.

Parameters

Takes a variable list of parameters, the first of which is a format string for printf, which will be translated.  The remainder are the substitution variables for printf.

spf_
function spf_()

A convenience function that mixes translation with sprintf.

Parameters

Takes a variable list of parameters, the first of which is a format string for printf, which will be translated.  The remainder are the substitution variables for printf.

Returns

The first argument, translated with the the other arguments substituted for the appropriate scancodes.