Your Location is: Home > Php

Include language array in Codeigniter 4

From: Germany View: 2938 Henry8 

Question

I receive the "language segment" from the url (I use CodeIgniter 4)

ex: www.site.com/en/book

I would like to load the relative translations array in the controller ready for the view... so I tried:

My controller:

$data['tran'] = array(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";

In my view

echo ($tran['t1']);  

I receive this error: Undefined index: t1

Does not work... why?

Best answer