Language for Codeigniter 4
Send translation files to Javascript
Use the package with composer install
> composer require daycry/codeigniter-language
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',
];
$language = new \Daycry\Language\Language( \Config\Services::request()->getLocale() );
$language->loadFile( 'Validation' );
var_dump( $language->getTraductions() );
$language = \Config\Services::language();
$language->loadFile( 'Validation' );
var_dump( $language->getTraductions() );
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>
echo view( 'some_view' );
<script>
var traductions = <?php echo json_encode( $this->language->getTraductions() ); ?>;
console.log( traductions['File']['string'] );
</script>