Welcome Guest, Not a member yet? Register   Sign In
problem changing the language
#1

[eluser]keevitaja[/eluser]
now i have problem with languages.

Code:
<?php
class Subtest extends Controller {
  function index() {
    echo $this->config->item('language').'<br>'; //prints estonian, set in config file, default
    $this->config->set_item('language', 'english');
    echo $this->config->item('language').'<br>'; //prints english
    echo $this->lang->line('site_select_language'); //still prints out the estonian version
  }
}

i have both estonian and english versions in language folder
isn't it possible to change the language like that?

however if i change the config file and set $config['language'] = "english"; it will print out the english version!
#2

[eluser]Kamarg[/eluser]
You want to use $this->load->lang as documented in the user guide.
#3

[eluser]tomcode[/eluser]
You cannot change the language after You have loaded language files, only before.

I. You can fetch a language file and keep the values in a variable, but only for language files You do not have already loaded.

This works :
Code:
$lang = $this->lang->load('filename', 'language', true);
// change language
// ..
$this->lang->load('filename', 'language');

This not :
Code:
$this->lang->load('filename', 'language');
// change language
// ..
$lang = $this->lang->load('filename', 'language', true);



II. I've written an extension to switch the language, it reloads all previous loaded language files

Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Language extends CI_Language {

    var $language   = array();
    var $is_loaded  = array();

    /**
     * Resets the class variables
     *
     * @access  public
     * @param   void
     * @return  void
     */
    function reset()
    {
        $this->language = array();
        $this->is_loaded = array();
    }

    // --------------------------------------------------------------------

    /**
     * Reloads all currently loaded language files
     *
     * @access  public
     * @param   void
     * @return  void
     */
    function reload()
    {
        log_message('debug', 'MY_Language reloading all language files');
        
        $is_loaded = $this->is_loaded;
        
        $this->reset();
        
        foreach($is_loaded as $langfile)
        {
            $this->load($langfile);
        }
    }

}
#4

[eluser]keevitaja[/eluser]
i'm not sure why, but i can't change the languages

Code:
$this->load->library('language');
    $lang = $this->lang->load('site', 'english', true);
    $this->language->reload();
    $this->lang->load('site', 'english');
    
    echo $this->lang->line('site_select_language');

i still get the default(estonian) output
#5

[eluser]tomcode[/eluser]
Code:
// You do not need to load the library language, it is auto loaded by the system.

// Here You load the estonian language file, i.e. the language set in Your config
$this->lang->load('site');

// Now change the language
$this->config->set_item('language', 'english');

// Reload all currently loaded language files, using the english set
$this->language->reload();
    
// Should output the english string
echo $this->lang->line('site_select_language');
#6

[eluser]keevitaja[/eluser]
i must be really stupid or missing something...

Code:
&lt;?php

//$config['language']    = "english";
//$autoload['language'] = array();

class Test extends Controller {
  function index() {
    $this->load->library('language'); //must be loaded, otherwise get the error
    
    $this->lang->load('site');
    $this->config->set_item('language', 'estonian');
    $this->language->reload();
    
    //$this->lang->load('site', 'estonian'); //redeclared after reload gives no results!
    
    echo $this->lang->line('site_username'); //still prints the english version
    
    //site_lang.php present in estonian and english folders
    //changeing the config.php file will do the job!
  }
}
#7

[eluser]keevitaja[/eluser]
can anyone help me with this test.php controller? why isn't it working?

site_lang.php file is located in

languages/english
languages/estonian

there is a value:

$lang['site_username'] = 'Username';

when i change the language in config file, appropriate language will be used!
#8

[eluser]keevitaja[/eluser]
this is resolved thanx to:

http://ellislab.com/forums/viewthread/64118/#339962




Theme © iAndrew 2016 - Forum software by © MyBB