CodeIgniter Forums
modules and language in codeigniter 4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: modules and language in codeigniter 4 (/showthread.php?tid=76978)



modules and language in codeigniter 4 - Ahmad Ali - 07-09-2020

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?


RE: modules and language in codeigniter 4 - InsiteFX - 07-10-2020

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.


RE: modules and language in codeigniter 4 - hammers - 07-17-2020

(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.


RE: modules and language in codeigniter 4 - InsiteFX - 07-17-2020

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.