Welcome Guest, Not a member yet? Register   Sign In
URI Language Identifier not working anymore
#1

[eluser]hykoh[/eluser]
Hello,

i've updated my website to CI Reactor 2.0. It seems to work fine, except my language extension. I've seen that the Language Library is now within the "Core" and renamed to "Lang.php". I tried to refactoring my class to "MY_Lang", but it isnt working ... is it still possible to extend the lang class ???

I was using the wiredesignz URI Language identifier from the wiki.

Or is there now any other way to use language files via the uri ? for example: http://www.example.com/en/controller/method, http://www.example.com/de/controller/method etc.

Thanks for any help!
#2

[eluser]wiredesignz[/eluser]
URI Language Identifier wiki page is updated for CI 2.0
#3

[eluser]hykoh[/eluser]
Hey wiredesignz, thanks for the fast update. But i get another problem now .. in the old versions of URI Language Identifier, the main language file was loaded automatically. It is removed now. If i append it to the source, it will result in an error:

Code:
Fatal error: Class 'CI_Controller' not found in /var/www/blabla/system/core/CodeIgniter.php on line 210

I'm just added the parent::load($user_lang, $user_lang); in the code:

Code:
class MY_Lang extends CI_Lang
{
    function __construct() {
        
        global $RTR;
        
        $index_page    = $RTR->config->item('index_page');
        $lang_uri_abbr = $RTR->config->item('lang_uri_abbr');
        
        /* get the lang_abbr from uri segments */
        $lang_abbr = current($RTR->uri->segments);
            
        /* check for invalid abbreviation */
        if( ! isset($lang_uri_abbr[$lang_abbr])) {            
            
            $deft_abbr = $RTR->config->item('language_abbr');
            
            /* check for abbreviation to be ignored */
            if ($deft_abbr != $RTR->config->item('lang_ignore')) {
                
                /* check and set the default uri identifier */
                $index_page .= empty($index_page) ? $deft_abbr : "/$deft_abbr";
            
                /* redirect after inserting language id */
                header('Location: '.$RTR->config->item('base_url').$index_page.$RTR->uri->uri_string);
            }
            
            /* get the language name */
            $user_lang = $lang_uri_abbr[$deft_abbr];
        
        } else {
        
            /* get the language name */
            $user_lang = $lang_uri_abbr[$lang_abbr];
            
            /* reset config language to match the user language */
            $RTR->config->set_item('language', $user_lang);
            $RTR->config->set_item('language_abbr', $lang_abbr);
        
            /* check for abbreviation to be ignored */
            if ($lang_abbr != $RTR->config->item('lang_ignore')) {
            
                /* check and set the user uri identifier */
                   $index_page .= empty($index_page) ? $lang_abbr : "/$lang_abbr";
                
                /* reset uri segments and uri string */
                $RTR->uri->_reindex_segments(array_shift($RTR->uri->segments));
                $RTR->uri->uri_string = str_replace("/$lang_abbr/", '/', $RTR->uri->uri_string);
            }
        }
        parent::load($user_lang, $user_lang);
        /* reset the index_page value */
        $RTR->config->set_item('index_page', $index_page);
        log_message('debug', "MY_Language Class Initialized");
    }
}

Why is there now an error ? Or how can i implement a default language file automatically ???




Theme © iAndrew 2016 - Forum software by © MyBB