Table of Contents |
---|
Table of Contents |
---|
maxLevel | 4 |
---|
minLevel | 2 |
---|
outline | true |
---|
class | toc |
---|
|
|
Info |
---|
|
A language translation utility is provided at http://translate.blesta.com.This project is intended to facilitate the crowd sourced translation of Blesta into many languages and participation is highly encouraged. |
Language in Blesta is handled by a collection of language files, heretoafter referred to as a "language pack." Language packs are primarily located in the language directory /installdir/language/, but additional files may be located in various other locations including Modules, Payment Gateways, Plugins, and some components or helpers. The default language in Blesta is English, US located in /installdir/language/en_us/.
...
Code Block |
---|
title | /installdir/language/en_us/en_us |
---|
firstline | 1 |
---|
linenumbers | true |
---|
|
English, US |
Language Direction
Language direction may be defined in the app_controller.php language file. This identifies which direction text should read (ltr for left-to-right, or rtl for right-to-left).
Code Block |
---|
title | /installdir/language/en_us/app_controller.php |
---|
firstline | 1 |
---|
linenumbers | true |
---|
|
$lang['AppController.lang.dir'] = "ltr"; |
If not defined language will default to the "ltr" (left-to-right) direction.
Anatomy of a Language File
...
- [ClassName].[methodName].[entry_name]
- [ClassName].[!errrorerror/!success/!notice].[entry_name]
...
Info |
---|
title | Variables can appear in any order |
---|
|
The definition above could easily have been written as "The payment was successfully processed! Transaction Number: %2\$s, Amount: %1\$s". |
Using Definitions
Loading Language Files
Language files may be loaded from anywhere in Blesta. By default the Language library looks for language files in /installdir/language/, but you can override this value.
Code Block |
---|
language | php |
---|
title | From somewhere in a controller or model |
---|
firstline | 37 |
---|
linenumbers | true |
---|
|
Language::loadLang("lang_file"); // loads from /installdir/language/[language_pack]/lang_file.php
Language::loadLang("lang_file", null, PLUGINDIR . "my_plugin" . DS . "language" . DS); // loads from /installdir/plugins/my_plugin/language/[language_pack]/lang_file.php |
Displaying Definitions
Controllers and Models must invoke the Language library directly to access language definitions.
Code Block |
---|
language | php |
---|
title | From somewhere in a controller or model |
---|
firstline | 68 |
---|
linenumbers | true |
---|
|
echo Language::_("ControllerName.methodName.entry_name"); |
Views have access to a wrapper method and should utilize the following syntax, instead:
Code Block |
---|
language | php |
---|
title | From somewhere in a view |
---|
firstline | 17 |
---|
|
<?php $this->_("ControllerName.methodName.entry_name");?> |
To set variables for substitution, add them beginning as the 3rd parameters to Language::_() or $this->_(). For example:
Code Block |
---|
language | php |
---|
title | From somewhere in a view |
---|
firstline | 17 |
---|
|
<?php $this->_("ControllerName.methodName.entry_name", false, $param1, $param2, ..., $paramN);?> |