Vesthelm Engine

2.1.1 User Guide

Language Class

The Language class provides methods for calling language files and making the frontend and backend side of Vesthelm Engine translatable into multiple languages.

Calling the Language Class

$Language = $this->Language;

$Language = $this->Lang;

$Language = $this->I18N;

$Language = language();

Calling the Language Methods

$this->Language->get();

$this->Lang->get();

$this->I18N->get();

language()->get();

Loading the Language Groups

Vesthelm Engine automatically loads language groups when using languages in PHP files, but if you want to use languages in Javascript files, you must load them manually:

To load one of your language groups you will use the following function within the controller that needs it:

load_lang(array('general', 'bulletins')); //no enhancement specified so language group will be 'vesthelm'

load_lang('general, bulletins', 'bulletin_board'); //enhancement specified

First argument (can be string separated with comma or array) 'general' and 'bulletins' are the name of language groups. Second argument 'bulletin_board' is the name of the enhancement.

Getting a Language Item

To retrieve an item from your language group:

$lang_item = lang('new_bulletins', 'bulletins', 'bulletin_board');

$lang_item = $this->Language->get('new_bulletins', 'bulletins', 'bulletin_board');

$lang_item = $this->Lang->get('new_bulletins', 'bulletins', 'bulletin_board');

$lang_item = $this->I18N->get('new_bulletins', 'bulletins', 'bulletin_board');

$lang_item = language()->get('new_bulletins', 'bulletins', 'bulletin_board');

echo $lang_item; //Outputs: New Bulletins

First argument 'new_bulletins' is the language group array index you want to retrieve. Second argument 'bulletins' is the name of language group. Third argument 'bulletin_board' is the name of the enhancement. Fourth argument - bool used to unserialize language item using unserialize() function if it was serialized by serialize() function.

Setting a Language Item

If you would like to dynamically set a language item or change an existing one, you can do so using:

$this->Language->set('new_bulletins', 'New Phrase', 'bulletins', 'bulletin_board');

$this->Lang->set('new_bulletins', 'New Phrase', 'bulletins', 'bulletin_board');

$this->I18N->set('new_bulletins', 'New Phrase', 'bulletins', 'bulletin_board');

language()->set('new_bulletins', 'New Phrase', 'bulletins', 'bulletin_board');

echo lang('new_bulletins', 'bulletins', 'bulletin_board'); //Outputs: New Phrase

First argument 'new_bulletins' is the language group array index you want to retrieve. Second argument 'New Phrase' is new language item value. Third argument 'bulletins' is the name of language group. Fourth argument 'bulletin_board' is the name of the enhancement. Fifth argument - bool used to unserialize language item using unserialize() function if it was serialized by serialize() function.