Welcome Guest, Not a member yet? Register   Sign In
Multilingual System lang files
#1

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.
Reply
#2

(06-15-2018, 05:08 AM)1tft Wrote: 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.

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
Reply
#3

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!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB