![]() |
Multilingual System lang files - 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: Multilingual System lang files (/showthread.php?tid=70898) |
Multilingual System lang files - 1tft - 06-15-2018 Hello, I found the following issue in Codeigniter. Initial situation: I have a multilingual site and using language class of CI. Everything is working fine for own language files. Problem: I want to translate content of (/codeigniter/system/language/english/form_validation_lang.php) and tried following: Created translated file /codeigniter/system/language/german/form_validation_lang.php In controller I use $this->lang->load('form_validation', 'german'); for loading language file, but I still get english translation for form errors. My workaround at the moment: Created dummy (almost empty) file /codeigniter/system/language/english/form_validation_lang.php. Also created /codeigniter/application/language/german/system/form_validation_lang.php and load $this->lang->load('system/form_validation', 'german'); Does anyone know what is the right way to work with translated system lang files? Documention at https://github.com/bcit-ci/codeigniter3-translations is not helping me. RE: Multilingual System lang files - Eduardo Faria - 06-15-2018 (06-15-2018, 05:08 AM)1tft Wrote: Hello, Hi, I have used the following to translate the system messages and validations in codeigniter: In my case I wanted to add 'portuguese-br', but doesn't matter the language: 1) Do not change anything inside the System folder. It will make thigs harder when update codeigniter. 2) I create the file application/language/portuguese-br/form_validation_lang.php with my translation. 3) I introduced in the controller function __construct the following code (this is the main thing): public function __construct(){ parent::__construct(); //Adjust internal codeigniter language $this->idiom = $this->session->userdata('language'); $ci =& get_instance(); $ci->config->set_item('language', $this->idiom); } Note: I use the session variable 'language' = 'portuguese-br' to define the current language. 4) In the function that renders the page I load the language file that I need on the page, not needed to mention the validation file created... in my case: public function pag_registration(){ $this->lang->load('registration','portuguese-br'); $dados['titulo'] = $this->lang->line('titulo'); $dados['subtitulo'] = $this->lang->line('subtitulo'); //Pagina $this->load->view('registration'); } See that have no need to indicate the validation file with translation. Hope it works, Eduardo RE: Multilingual System lang files - 1tft - 06-15-2018 Using $this->config->set_item('language', $language); solves it. With this instruction CI uses the correct lang file under /codeigniter/system/language/ I knew about setting global language file via config file but I didnt have the idea of putting it dynamically. Thank you very much bro! |