Load language array |
I receive the "language segment" from the url (I use CI4)
ex: www.site.com/en/book I would like to load the relative translations array in the controller for the view... so I tried: My controller: $data['tran'] = require_once(APPPATH."/Language/en/file_lang.php"); file_lang.php: <?php //english $lang = array(); $lang['t1'] = "Description"; $lang['t2'] = "list"; $lang['t3'] = "Contact"; $lang['t4'] = "Write"; $lang['t5'] = "Views"; $lang['t6'] = "Cities"; etc. But does not work... why?
And what version of CodeIgniter are you running?
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
I also was interested of this question here but did not find the answer.
So I've decided do not load all translations in controller. I just output translations in view: PHP Code: <div><?= lang('file_lang.t1') ?></div> All translations are displayed in the language (locale) specified in the request. So you need to change locale in the request (if you don't do it) with $this->request->setLocale($locale) - in Controller or in Filter.
(11-16-2020, 07:20 AM)T.O.M. Wrote: I also was interested of this question here but did not find the answer. There were a very symple function in CI 2... $data['menu'] = $this->lang->load('menu'); Why there isn't a simil function? Here the solution: Add: return $lang; at the end of array in the file_lang.php Now it's working
The language files do return an array see below.
Creating Language Files What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |