CodeIgniter Forums

Full Version: modules and language in codeigniter 4
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
let assume that the structure of the files as the following
- App
  - Config
  ..... until
  - Modules
    - Admin (inside Admin folder will be controllers and views model config and language)
      - Language
        - en
            - home.php
        - ar
            - home.php

So, my problem is when I want to use lang function I will put the name of the file and then the key of the thing you want to retrieve. Therefore let's say I called the function like that
lang('home.title') home represents the file name and the title represents the key. But it does not retrieve anything from the file and it returns home.title so do I need to put all my translation files
in one folder which is the one inside the app folder? or there is a solution?
Can you try it with single quotes to see if it work, some things just
do not work right with double quotes.

I have lang files in modules and they work fine but I use single quotes.
(07-10-2020, 07:54 AM)InsiteFX Wrote: [ -> ]Can you try it with single quotes to see if it work, some things just
do not work right with roadrunner email double quotes. I have lang files in modules and they work fine but I use single quotes.
I've already tried this but didn't help either.
Did you namespase the Modules and Admin in the Autoloader?

Example:

PHP Code:
    public $psr4 = [
        
APP_NAMESPACE               => APPPATH,                                 // For custom app namespace
        
'Config'                    => APPPATH  'Config',
        
'Myth\Auth'                 => ROOTPATH 'Myth/Auth',                  // Module Myth::Auth
        
'Insitefx'                  => ROOTPATH 'Insitefx',                   // Modules
        
'Insitefx\Blog'             => ROOTPATH 'Insitefx/Blog',              // Module Blog
    
]; 

If  you do not namespace them it will not be able to find them easily.
 
So in your case you would want to add these.

PHP Code:
'Modules'       => APPPATH.'Modules',
'Modules\Admin' => APPPATH.'Modules/Admin'

Then use a use clause to set the path to your language folder.

Something like this not tested.

PHP Code:
use App\Modules\Admin\Language\en

I use phpStorm Editor so it tells me what needs to be done.