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.

Summary
i18n.phpSupport functions for internationalization.
Functions
_Mimics the behavior of gettext.
lang_jsGets a link to the JavaScript translation file for the configured language.
fmtdatePrint a formatted date.
p_A convenience funtion to print a translated string.
pf_A convenience function that mixes translation with printf.
spf_A convenience function that mixes translation with sprintf.

Functions

_

function _($str)

Mimics the behavior of gettext.

Parameters

strThe 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($lang = false)

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,  
$ts = false)

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

fmtThe format string for the date
tsThe 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

strThe 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.

function _($str)
Mimics the behavior of gettext.
function lang_js($lang = false)
Gets a link to the JavaScript translation file for the configured language.
function fmtdate($fmt,  
$ts = false)
Print a formatted date.
function p_($str)
A convenience funtion to print a translated string.
function pf_()
A convenience function that mixes translation with printf.
function spf_()
A convenience function that mixes translation with sprintf.
Close