\midcom_services_i18n_l10n

This is the L10n main interface class, used by the components. It allows you to get entries from the l10n string tables in the current language with an automatic conversion to the destination character set.

L10n language database file format specification:

Lines starting with --- are considered command lines and treated specially, unless they occur within string data. All commands are separated with at least a single space from their content, unless they don't have an argument.

Empty lines are ignored, unless within string data.

All keys and values will be trim'ed when encountered, so leading and trailing whitespace will be eliminated completely.

Windows-style line endings (\r\n) will be silently converted to the UNIX \n style.

Commented example:

---# Lines starting with a # command are ignored.

---# File format version
---VERSION 2.1.0

---# Language of the table
---LANGUAGE en

---STRING string identifier
TRANSLATED STRING taken literally until ---STRINGEND, which is the
only reserved value at the beginning of the line, everything else is
fine. Linebreaks within the translation are preserved.
\r\n sequences are translated into to \n
---STRINGEND

File naming scheme: {$component_directory}/locale/{$database_name}.{$lang}.txt

Summary

Methods
Properties
Constants
__construct()
set_language()
set_fallback_language()
get_formatter()
string_exists()
string_available()
get()
show()
get_stringdb()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
_load_language()
parse_data()
_check_for_language()
$_library
$_library_filename
$_component_name
$_fallback_language
$_language
$_localedb
$_stringdb
$_version
$database
N/A

Properties

$_library

$_library : string

The name of the locale library we use, this is usually a component's name.

Type

string

$_library_filename

$_library_filename : string

The full path basename to the active library files. The individual files are ending with .$lang.txt.

Type

string

$_component_name

$_component_name : string

The name of the current component

Type

string

$_fallback_language

$_fallback_language : string

Fallback language, in case the selected language is not available.

Type

string

$_language

$_language : string

Current language.

Type

string

$_localedb

$_localedb : Array

Global string table cache, it stores the string tables loaded during runtime.

Type

Array

$_stringdb

$_stringdb : Array

The string database, a reference into the global cache.

Type

Array

$_version

$_version : string

The current L10n DB file format number

Type

string

$database

$database : 

Type

Methods

__construct()

__construct(string  $library, string  $database) 

The constructor loads the translation library indicated by the snippetdir path $library and initializes the system completely. The output character set will be initialized to the language's default.

Parameters

string $library

Name of the locale library to use.

string $database

Name of the database in the library to load.

set_language()

set_language(string  $lang) 

Set output language.

This is usually set through midcom_services_i18n.

Parameters

string $lang

Language code.

set_fallback_language()

set_fallback_language(string  $lang) 

Set the fallback language.

This is usually set through midcom_services_i18n.

Parameters

string $lang

Language name.

string_exists()

string_exists(string  $string, string  $language = null) : boolean

Checks if a localized string for $string exists. If $language is unset, the current language is used.

Parameters

string $string

The string-ID to search for.

string $language

The language to search in.

Returns

boolean —

Indicating availability.

string_available()

string_available(string  $string) : boolean

Checks whether the given string is available in either the current or the fallback language. Use this to determine if an actually processed result is returned by get. This is helpful especially if you want to "catch" cases where a string might translate to itself in some languages.

Parameters

string $string

The string-ID to search for

Returns

boolean —

Indicating availability.

get()

get(string  $string, string  $language = null) : string

Retrieves a localized string from the database using $language as destination. If $language is unset, the currently set default language is used. If the string is not found in the selected language, the fallback is checked. If even the fallback cannot be found, then $string is returned and the event is logged to MidCOMs Debugging system.

L10n DB loads are done through string_exists.

Parameters

string $string

The string-ID to search for.

string $language

The language to search in, uses the current language as default.

Returns

string —

The translated string if available, the fallback string otherwise.

show()

show(string  $string, string  $language = null) 

This is a shortcut for "echo $this->get(.

..);", useful in style code.

Note, that due to the stupidity of the Zend engine, it is not possible to call this function echo, like it should have been called.

Parameters

string $string

The string-ID to search for.

string $language

The language to search in, uses the current language as default.

get_stringdb()

get_stringdb(string  $language) 

Returns the entire translation table for the given language

Parameters

string $language

The language to query

_load_language()

_load_language(  $lang) 

Load a language database

  • Leading and trailing whitespace will be eliminated

Parameters

$lang

parse_data()

parse_data(array  $data,   $lang,   $filename) 

Parameters

array $data
$lang
$filename

_check_for_language()

_check_for_language(string  $lang) 

Checks, whether the referenced language is already loaded. If not, it is automatically made available.

Parameters

string $lang

The language to check for.