-
-
Notifications
You must be signed in to change notification settings - Fork 103
How to include and use language files into your project
Lucas Kovács edited this page Aug 19, 2020
·
8 revisions
We covered in this article How to create or edit a Language file, but what if we just created one and we want to include/add it to our project, controller or page? Just follow these steps:
- Open any controller that you have created
- Be sure that your controller extends from the parent class Controller
- Load the language file calling
parent::loadLang
and providing a name as a parameter. See the example below.
class MyClass extends Controller
{
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
// load Language
parent::loadLang('my_language_file');
}
}
Notice that you won't need to add _lang.php, that will be done for you. Just be sure that your file name matches the file that you created under application/languages. In this case my_language_file_lang.php
You can load a single language file or multiple passing an array.
parent::loadLang(['language_file_one', 'language_file_two']);
Our last step is to use the just created and loaded file. There are a few ways that you can do it.
$this->langs->language; // store it into a variable to use it
$this->langs->line('language_line');
$this->langs->language['language_line'];
$this->langs->language['language_line']['language_line_second_block']['language_line_third_block'];
This document is valid as of: 30 October 2019
Valid as of: v3.1.0 Beta 3
Last update: 19 August 2020