Search for Resources and Solutions

How to use a language file in your components, apps, themes or plugins

CodeIgniter has a special code which you can use to include your language files from any location you want. You can use the language files in your components, apps, themes or plugins.

First of all, create a language file in the theme, component, app or theme directory language/yourlanguage. Example: user_lang.php.

Now to call it, just use the code:

// Load language
$CI->lang->load( 'user', $CI->config->item('language'), FALSE, TRUE, PATH_OF_YOUR_COMPONENT_APP_THEME);

The variable $CI has the CodeIgniter object instance.

user is the name of the language file, _lang.php isn't required. 

$CI->config->item('language') has the selected language, please add same code.

PATH_OF_YOUR_COMPONENT_APP_THEME -  is the path of your theme, component, app or theme directory. Not the path of the language directory.

Please, remember the file name should be unique, otherwise won't work if there are more files with same name.

Was this article helpful?