File-based i18n-translations always have a "locale" (e.g. 'en_US'). Common
language names (e.g. 'en') are mainly used in Translatable for
database-entities.

Text Collection

Features a "textcollector-mode" that parses all files with a certain
extension (currently *.php and *.ss) for new translatable strings. Textcollector
will write updated string-tables to their respective folders inside the module,
and automatically namespace entities to the classes/templates they are found in
(e.g. $lang['en_US']['AssetAdmin']['UPLOADFILES']).

Caution: Does not apply any character-set conversion, it is assumed that all
content is stored and represented in UTF-8 (Unicode). Please make sure your
files are created with the correct character-set, and your HTML-templates render
UTF-8.

Caution: The language file has to be stored in the same module path as the
"filename namespaces" on the entities. So an entity stored in
$lang['en_US']['AssetAdmin']['DETAILSTAB'] has to in the language file
cms/lang/en_US.php, as the referenced file (AssetAdmin.php) is stored in the
"cms" module.

Methods summary

Use javascript i18n through the ss.i18n class (enabled by default). If set to
TRUE, includes javascript requirements for the base library
(sapphire/javascript/i18n.js) and all necessary lang files (e.g.
sapphire/lang/de_DE.js) plus fallbacks to the default locale (e.g.
sapphire/lang/en_US.js). If set to FALSE, only includes a stub implementation
which is necessary. Mainly disabled to save bandwidth in a frontend context when
website is in single language.

Use javascript i18n through the ss.i18n class (enabled by default). If set to
TRUE, includes javascript requirements for the base library
(sapphire/javascript/i18n.js) and all necessary lang files (e.g.
sapphire/lang/de_DE.js) plus fallbacks to the default locale (e.g.
sapphire/lang/en_US.js). If set to FALSE, only includes a stub implementation
which is necessary. Mainly disabled to save bandwidth in a frontend context when
website is in single language.

Caution: This flag gets overwritten in LeftAndMain::init() to enforce
javascript i18n for the CMS interfaces.

Returns

This is the main translator function. Returns the string defined by $class
and $entity according to the currently set locale.

This is the main translator function. Returns the string defined by $class
and $entity according to the currently set locale.

Parameters

$entity

string $entity Entity that identifies the string. It must be in the form
"Namespace.Entity" where Namespace will be usually the class name where this
string is used and Entity identifies the string inside the namespace.

$string

string $string The original string itself. In a usual call this is a mandatory
parameter, but if you are reusing a string which has already been "declared"
(using another call to this function, with the same class and entity), you can
omit it.

$priority

string $priority Optional parameter to set a translation priority. If a string
is widely used, should have a high priority (PR_HIGH), in this way translators
will be able to prioritise this strings. If a string is rarely shown, you should
use PR_LOW. You can use PR_MEDIUM as well. Leaving this field blank will be
interpretated as a "normal" priority (less than PR_MEDIUM).

$context

string $context If the string can be difficult to translate by any reason, you
can help translators with some more info using this param

Returns

Returns the "short" language name from a locale, e.g. "en_US" would return
"en". This conversion is determined internally by the i18n::$tinymce_lang
lookup table. If no match can be found in this lookup, the characters before the
underscore ("_") are returned.

Returns the "short" language name from a locale, e.g. "en_US" would return
"en". This conversion is determined internally by the i18n::$tinymce_lang
lookup table. If no match can be found in this lookup, the characters before the
underscore ("_") are returned.

Returns

Set the current locale, used as the default for any localized classes, such
as FormField or DBField instances. Locales can also be persisted
in Member->Locale, for example in the CMSMain interface the
Member locale overrules the global locale value set here.

Set the current locale, used as the default for any localized classes, such
as FormField or DBField instances. Locales can also be persisted
in Member->Locale, for example in the CMSMain interface the
Member locale overrules the global locale value set here.

Parameters

boolean $force_load If true (not default), we force the inclusion. Generally
this should be off for performance, but enabling this is useful for interfaces
like CustomTranslationAdmin which need to load more than the usual locales, and
may need to reload them.

Given a class name (a "locale namespace"), will search for its module and, if
available, will load the resources for the currently defined locale. If not
available, the original English resource will be loaded instead (to avoid
blanks)

Given a class name (a "locale namespace"), will search for its module and, if
available, will load the resources for the currently defined locale. If not
available, the original English resource will be loaded instead (to avoid
blanks)

Parameters

$class

string $class Resources for this class will be included, according to the set
locale.

Parameters

Merge an extra of language translations into $lang[$locale]. We'd use
array_merge_recursive, except it doesn't work for translations that specify
priorities and comments, because they are indexed by number.

Merge an extra of language translations into $lang[$locale]. We'd use
array_merge_recursive, except it doesn't work for translations that specify
priorities and comments, because they are indexed by number.

Parameters

$locale

$locale String The locale we are merging into

$extra

$extra Array An array of [locale][class][entity]=> translation, keyed on
entity, that are to be merged for this locale.

See

Comments

Comment policy: Please use comments for tips and corrections about the described
functionality. Comments are moderated, we reserve the right to remove comments that are inappropriate or are no longer relevant.
Use the Silverstripe Forum to ask questions.