Retired Documentation:  You are using the documentation for version 1.7.3 which was retired in 2013. Go here for the latest version documentation or check here for your available upgrades to the latest version.

Language Class

Calling the Language Class

ExpressionEngine uses the Language class for calling language files and making the Control Panel side of ExpressionEngine translatable into multiple languages. To use the Language class in your modules you must call the $LANG global in every function that will require the use of any text. The language used when this class is called is dependent on the logged in user's localization preferences.

function database_example()
{
	global $LANG;

	echo $LANG->line('');
}

ExpressionEngine also requires that every module have a file in the language directory (ex: /system/language/english/) for the module with its filename in this form: 'lang.your_module_name.php'. Contained in this file with be an array ($L) of all the language variables for your module. Every module language file must contain at least two values for the name and description of the module, which are displayed in the Module page in the Control Panel.

<?php

$L = array(

//----------------------------------------
// Required for MODULES page
//----------------------------------------

"moblog_module_name" =>
"Moblog",

"moblog_module_description" =>
"Moblogging Module",

//----------------------------------------

"moblog" =>
"Moblogging",

"edit_moblog" =>
"Update Moblog",

"view_moblogs" =>
"Moblog Accounts",

// END
''=>''
);
?>

When adding text to your language file array, be careful when using non-alphanumeric characters such as quotes and monetary symobls. For such things we suggest that you convert them into HTML entities or escape them with a backslash.

Fetching a Line of Text

A module's language file is automatically loaded whenever the module is accessed through the Module section of the Control Panel. So, in that instance, you simply need to call the piece of text you wish from the array contained in your module's langauge file. To do so, you simply use the $LANG->line() function and specify the key for that piece of text in the array.

$DSP->title = $LANG->line('view_moblogs');
// Returns "Moblog Accounts";

EXTRA: If you are using the lines of text as a label for form fields, then you can automatically create the <label> HTML tag for that field.

$DSP->body .= $DSP->itemgroup(
                              $DSP->required().NBS.
                              $LANG->line('username', 'username'),
                              $DSP->input_text('username', '',)
                              );

Calling a Language File

A module's language file is automatically loaded whenever the module is accessed through the Module section of the Control Panel. There are also two other language files that will be loaded automatically by ExpressionEngine. The first, lang.core.php, is always available on both the user side and Control Panel side of ExpressionEngine. It contains many often used pieces of text and also Localization related lines of text. Second, if accessing any part of the Control Panel, then the values located in lang.cp.php are always available to you. On the user side of the site, the values located in lang.core.

Every so often, you might require or desire the language values from another language file. For example, you know that the lang.members.php file contains many member related pieces of text, and instead of duplicating those in your module's language file you could use the text in that language file. To load that language file and its values, you simply need to call the $LANG->fetch_language_file() function with the name of the language file.

$LANG->fetch_language_file('members');

Top of Page