CodeIgniter Forums
Language Bug - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Language Bug (/showthread.php?tid=75347)



Language Bug - ajmeireles - 01-28-2020

Hi!

I'm migrate from CI3 to CI4 and I think have a bug on lang general function. When I call it, according the guide, the system return me the variable and not the message.

In Model:

$teste = lang("Logout.NoUser", [], "pt-BR");
return $teste;

Structure:
app/Language/pt-BR/Logout.php

<?php

return [
    "Logout.NoUser"          => "User not found",
];


When return from model is passed to the view...

View:
[Image: d368c910be.png]


RE: Language Bug - zahhar - 01-29-2020

There is no bug.

CI4 returns key itself when this key cannot be found in referenced language file.

Docs say: "If the value doesn’t match a valid locale as defined in the App configuration file, the default locale will be used in it’s place." (https://codeigniter4.github.io/userguide/outgoing/localization.html)

This is exactly your case. And it happens, because you added extra "Logout" prefix in your language file.

Create language file "app/Language/pt-BR/Logout.php", put the following content:

return [
"NoUser" => "User not found",
];

and use it: lang("Logout.NoUser", [], "pt-BR");

So you should use %Filename%.%Key% pattern in lang() function.
Also, if your key name is "Logout.NoUser", then you would call it "Logout.Logout.NoUser" Smile