Welcome Guest, Not a member yet? Register   Sign In
Load Variables in Language Files?
#1

[eluser]JasonS[/eluser]
Hi,

This doesn't appear to be documented. I was just wondering if it was possible to load variables in to Language Files.

e.g.

Code:
$this->lang->line('welcome', array('Jason'));

Code:
$lang['welcome'] = "Hello $1, welcome to our great new website";

This would be pretty handy in a project I am working on.
#2

[eluser]rogierb[/eluser]
If you want that kind of behaviour, extend the language class since it is not supported by default.

In a similar case, I use sprintf and %s, but extending the language class seems the better solution
#3

[eluser]JasonS[/eluser]
Thanks a lot, I just wanted to make sure nothing existed currently before I created my own solution.
#4

[eluser]khagendra[/eluser]
Here are the few steps that u have to follow to load the language variabbles.

1. In application/language, crate a folder for example english
now the folder is application/language/english

In this folder u have to create a file with name ended with _lang.
for example test_lang.php

now suppose there is a variable like
Quote: $lang['welcome']="welcome to site";

2. now you have to load the language file in a controller
Code:
class Home extends Controller {

    function Home()
    {
        parent::Controller();    
        
        // loading language file
        $this->lang->load('test', 'english');
    }
    }
while loading the language file just use file name without _lang.php. here i have used test rather than test_lang.php. the second parameter is language name(better say the folder name. here i have used english as the file test_lang.php is inside this folder.

3. check the config/donfig.php for $config['language'] = "english";

4. now to document your language variable use like this
Quote: $this->lang->line('welcome');




Theme © iAndrew 2016 - Forum software by © MyBB