i18n (internationalization) in Fuel Views
-
28-10-2019 - |
Question
What's the best/suggested way to handle i18n (internationalization) strings in views for Fuel PHP? I'm unable to find any references to this in the docs and am considering going with gettext. Any suggestions?
Solution
You can use the lang class, you can use it to load the language file you need. An example of code:
example.php
return array(
'hello' => 'Hello :name',
'something'=> 'something :name!',
'test'=> array(
'hello' => 'Hello',
'something' => 'Plop'
)
);
your file
// Will load the file "example.php" into the "var" variable
Lang::load('example', 'var');
// Get the variable "something"
$this->output = Lang::get('var.test.something');
You can create differente language file, like "en, it" or more, and dinamically load the file based on user's local settings.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow