I'm a novice, in fuelphp and framewoks, I've done the blog tutorial to start, now I want to make this blog in two languages, I don't know how to do it... can someone explain to me how to use the Lang class, I'vs check the docs but it's not clear for me. thank you
Another question, how can I reach 2 langues files, i can reach the file for the default langue but can't reach another file for the 2e langue. can someone helpe me please.
If you use
Lang::load('example');
It'll try and load fuel/app/lang/example.php
example.php should read something like this:
<?php
return array(
'hello' => 'Hello :name',
'something'=> 'something :name!',
'test'=> array('hello' => 'Hello', 'something' => 'Plop') // Group
);
and that's it.
You can echo `Hello :name` like so
echo Lang::line('hello');
You can also use
echo __('hello');
That's a double underscore.
The array within the array can be reached using dots.
echo __('test.hello');
Will echo `Hello`
thanks for your answer!
and how can I reach an another langue, I have made 2 directories fuel/app/lang/fr/example.php and fuel/app/lang/it/example.php, I can, display fuel/app/lang/fr/example.php but not fuel/app/lang/it/example.php, fr is my default language in my config file
You can set your default in your config file. To change the language during the execution of the app you could use Config::set('language', 'it'); before using Lang::get(...);
Setting this in the before() method of a controller or base controller will set it at the start of the execution.
can you give me a hand with my code, I have made 2 directories fuel/app/lang/fr/example.php and fuel/app/lang/it/lingua.php, I can, display fuel/app/lang/fr/langue.php , fr is my default language in my config file
in my index controller I have
public function action_index()
{
Lang::load('langue');
$this->template->label = __('test.hello');
$data = Welcome::find_all();
$data = WelcomeNouvelle::find_all();
$this->template->title = "bienvenue sur l'intranet";
$this->template->content = View::forge('welcome/index', $data);
}
this work
but for the other language it doesn't work
public function action_index()
{
Lang::load('lingua'); // file in my it folder
Config::set('language','it');
$this->template->label = __('test.hello');
$data = Welcome::find_all();
$data = WelcomeNouvelle::find_all();
$this->template->title = "bienvenue sur l'intranet ";
$this->template->content = View::forge('welcome/index', $data);
}
it seems that it doesn't find the it folder
can someone help me here,
thanks
You should have the same files in each folder
it/global.php
fr/global.php
it/register.php
fr/register.php
Then you load the language file
Lang::load('register');
I have named my to file langue.php on my folder it et fr
and changed my code as follow:
public function action_index()
{
Lang::load('langue');
Config::set('language','it');
Lang::get('test.something');
$this->template->label = Lang::Line('test.something');
$data = Welcome::find_all();
$data = WelcomeNouvelle::find_all();
$this->template->title = "bienvenue sur l'intranet ";
$this->template->content = View::forge('welcome/index', $data);
}
and I still have the french who is display instead of the italian... Am I forgetting something?
I don't think that we have to use config::set inside controllers. There's an issue on documentation of Lang class. The Lang::load() method actualy takes three parameters: $file, $group and $lang. So Lang::load('langfile', 'group', 'it') will load the Italian version of langfile. If you deal with a multilingual application, as third parameter you can provide the user prefered language saved in cookie or session. Correct me if i'm wrong.
I cannot get language data from \Lang::get() withoutgroup in it.
This is how i load language \Lang::load('account');
This is how i echo language data echo \Lang::get('account_username');
It should show the text 'Username'. but it show nothing.
if i use the code below, it's work but i just don't want to call language with group. \Lang::load('account', 'account'); echo \Lang::get('account.account_username');
I don't see an immediate reason why this should not work.
Can you see the loaded strings when you do
\Debug::dump(\Lang::$lines);
But I find it not very logical, by using "account.username" instead of "account_username", you make it more managable, have simpler language files, and avoid possible collisions, without adding any complexity to your code.