Welcome Guest, Not a member yet? Register   Sign In
Call to protected method CodeIgniter\Language\Language::load() from scope CodeIgniter
#1

Hi,

to load translation-files and create some dynamic content, i add the language service to the _construct of my own library.

Code:
"function __construct(){ ... $this->lang = service('language');" ... }"

Now i want to load a language file by calling my lib inside a view-file in this way
Code:
"$ci->mytools->lang->load(filepath', $ci->mytools->request->getLocale(),true)"

The result is the error message: "Call to protected method CodeIgniter\Language\Language::load() from scope CodeIgniter\View\View"

What i do wrong - how i cann load a language file on each point i want?
Reply
#2

No way, this is a system method. You can replace service('language') in Config/Services.php and add the desired methods.
https://github.com/codeigniter4/CodeIgni...e.php#L237
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#3

Where are you getting the $ci from this looks like CodeIgniter 3 code.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

is there no way to load a translation file in a view?
Reply
#5

Do you want to load the whole file to be used in a view or are you looking to use language specific strings in your view?
The most obvious way to use a language string is something like this:
PHP Code:
<?= lang('General.Actions'?>

Where there is an existing file in the Language/en folder with the name 'General.php'.
Content would be:
PHP Code:
<?php

return [
    'Actions'          => 'Actions',
]; 
If this is not what you're looking for, be a bit more specific on what you are trying to achieve.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB