phparrayslocalizationlangcodeigniter-4

How to load Codeigniter 4 lang file into an array variable


Is there a way to load a file from Codeignier 4 Language directory and assign the array content to a variable. Instead of returning the translated line, I want the whole array.

Like in CI3 we could do $language = $this->lang->load('lang_file','english', TRUE);. But in CI4 I cant seem to find a workaround.


Solution

  • If your lang array has a parent you can just do it like this:

    return [
        'list' => [
            'Apples',
            'Bananas',
            'Grapes',
            'Lemons',
            'Oranges',
            'Strawberries'
        ]
    ];
    
    
    $foo = lang('Fruit.list');
    

    If that is not your case you can just do like @Lawrence Cherone said in the comments and just include the file.

    $language = include('./Language/english.php')