Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: CI4 won't recognise current namespace for language files #3867

Closed
LucasKovacs opened this issue Nov 8, 2020 · 1 comment
Closed

Bug: CI4 won't recognise current namespace for language files #3867

LucasKovacs opened this issue Nov 8, 2020 · 1 comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@LucasKovacs
Copy link

Describe the bug
I'm working on a project that has 4 different modules, but for simplicity let's keep it on 2 (admin, site). Both modules have a language file inside located under Languages/en/global_lang.php. Due to an issue, and debugging I've notice that CI goes through all namespaces looking for that languages path and file.

array(2) {
  [0]=>
  string(51) "/var/www/html/website/admin/Language/en/global_lang.php"
  [1]=>
  string(50) "/var/www/html/website/site/Language/en/global_lang.php"
}

The method Language::requireFile will load both files, regardless of the current namespace, and set unneeded language lines.

According to CI docs:

Language files are located automatically from defined namespaces when using the lang() method, as long as the file follows the same directory structures as the main application directory.

Problem with that, is that it adds a lot of extra load of unnecessary files. I should have a way to indicate in which namespace the file that I want is, or some way to the lang() function only goes to look on my current module namespace and not all around.

CodeIgniter 4 version
4.0.4

Affected module(s)
Language

Expected behavior, and steps to reproduce if appropriate
Steps to reproduce

  • Create two modules with language files on them, same language and same file name.
  • load language on any controller of those modules
  • print all language lines, you'll see lines from both files, even the one that's outside the namespace.

Expected

  • I only get the language lines from the file within the namespace

Context

  • OS: [Linux]
  • Web server [Apache/2.4.38 (Debian)]
  • PHP version [7.4.10]
@LucasKovacs LucasKovacs added the bug Verified issues on the current code behavior or pull requests that will fix them label Nov 8, 2020
@michalsn
Copy link
Member

michalsn commented Jan 3, 2021

Sorry, but it's not a bug - it is the desired behavior.

The way it's working this way is because we want to have the ability to override language files loaded from the external modules in our application.

The easiest solution seems to be renaming the language files. Unless you have a different idea that will allow us to stick to the current behavior and at the same time meet your needs.

@michalsn michalsn closed this as completed Jan 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

2 participants