daycry / codeigniter-language
Load language files as array in Codeigniter 4
v1.0.3
2025-06-17 09:03 UTC
Requires
- php: >=8.1
Requires (Dev)
- codeigniter/coding-standard: ^1.8
- codeigniter/phpstan-codeigniter: ^1.4
- codeigniter4/devkit: ^1
- codeigniter4/framework: ^4
- ergebnis/composer-normalize: *
- fakerphp/faker: ^1.9
- friendsofphp/php-cs-fixer: ^3
- icanhazstring/composer-unused: *
- mikey179/vfsstream: ^1.6
- nexusphp/tachycardia: *
- phpstan/phpstan-strict-rules: ^2
- phpunit/phpcov: ^10
README
Codeigniter Language
Language for Codeigniter 4
Send translation files to Javascript
Installation via composer
Use the package with composer install
> composer require daycry/codeigniter-language
Manual installation
Download this repo and then enable it by editing app/Config/Autoload.php and adding the Daycry\Language namespace to the $psr4 array. For example, if you copied it into app/ThirdParty:
$psr4 = [ 'Config' => APPPATH . 'Config', APP_NAMESPACE => APPPATH, 'App' => APPPATH, 'Daycry\Language' => APPPATH .'ThirdParty/codeigniter-language/src', ];
Usage Loading Library
$language = new \Daycry\Language\Language( \Config\Services::request()->getLocale() ); $language->loadFile( 'Validation' ); var_dump( $language->getTraductions() );
Usage as a Service
$language = \Config\Services::language(); $language->loadFile( 'Validation' ); var_dump( $language->getTraductions() );
Usage In Views
Twig
Use the package with composer install
> composer require daycry/twig
$this->twig->addGlobal( 'traductions', $this->language->getTraductions() );
<script> var traductions = {{ traductions|json_encode|raw }}; console.log( traductions['File']['string'] ); </script>
Codeigniter Views
echo view( 'some_view' );
<script> var traductions = <?php echo json_encode( $this->language->getTraductions() ); ?>; console.log( traductions['File']['string'] ); </script>