CodeIgniter Forums
URI Language Identifier and CI 1.6.1 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: URI Language Identifier and CI 1.6.1 (/showthread.php?tid=7989)

Pages: 1 2 3


URI Language Identifier and CI 1.6.1 - El Forum - 04-30-2008

[eluser]Gewa[/eluser]
HI. I tried to fight with your URI langage identifier, but he wins. Please help me Smile


I put CI 1.6.1


my routs file contain only

Code:
$route['default_controller'] = "welcome";
$route['scaffolding_trigger'] = "";

$route['(\w{2})/(.*)'] = '$2';
$route['(\w{2})'] = $route['default_controller'];



my config.php contain

Code:
$config['language']    = "ru";



//default language abbreviation
$config['language_abbr'] = "ru";

//set available language abbreviations
$config['lang_uri_abbr'] = array("en" => "english", "ru" => "russian","de"=>"german");

//ignore this language abbreviation
$config['lang_ignore'] = "ru";


and i have the MY_Language.php in the folder libraries...


Beside that I have htaccess , that removes the index.php



Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|user_guide|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]


but in

Code:
class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();
    }

    function index()
    {
        $lang=$this->config->item('language_abbr');
        echo $lang;
    }
}


WHATEVER You change the url, for example mysite.com/en
it shows "ru"


what is the problem????


URI Language Identifier and CI 1.6.1 - El Forum - 04-30-2008

[eluser]wiredesignz[/eluser]
Please don't private message me to get an answer again. I visit the forums regularly and will see your post.

Your config for language is incorrect.
Code:
//default language
$config['language'] = "russian";

//default language abbreviation
$config['language_abbr'] = "ru";

//set available language abbreviations
$config['lang_uri_abbr'] = array(
        'en'   => 'english',
        'ru'   => 'russian',
        'de'   => 'german'
    );
    
//ignore this language abbreviation
$config['lang_ignore'] = "ru";



URI Language Identifier and CI 1.6.1 - El Forum - 04-30-2008

[eluser]Gewa[/eluser]
I changed to the code, you gave. The same result...


URI Language Identifier and CI 1.6.1 - El Forum - 04-30-2008

[eluser]wiredesignz[/eluser]
It works for me, please check your code again.


URI Language Identifier and CI 1.6.1 - El Forum - 04-30-2008

[eluser]Gewa[/eluser]
can it be from Register Globals or other issue?


URI Language Identifier and CI 1.6.1 - El Forum - 04-30-2008

[eluser]wiredesignz[/eluser]
Probably `other issue`.


URI Language Identifier and CI 1.6.1 - El Forum - 04-30-2008

[eluser]Gewa[/eluser]
I need just to put library in /system/libraries , or also to make some load function?

Maybe this is , that issue?

I just copy and paste this into /system/libraries as MY_Language.php

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* URI Language Identifier
*
* Adds a language identifier prefix to all site_url links
* Loads the default language file
*
* version 0.12 (c) Wiredesignz 2008-04-21
*/
class MY_Language extends CI_Language
{
    function MY_Language()
    {
        parent::CI_Language();

        global $RTR;

        $index_page    = $RTR->config->item('index_page');
        $lang_uri_abbr = $RTR->config->item('lang_uri_abbr');

        //get the language from uri segment
        $lang_abbr = $RTR->uri->segment(1);

        //check for invalid abbreviation
        if(!isset($lang_uri_abbr[$lang_abbr]))
        {
            $base_url  = $RTR->config->item('base_url');
            $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 .= ($index_page) ? "/{$deft_abbr}" : "{$deft_abbr}";

                $uri_string = $RTR->uri->uri_string;

                //remove an invalid abbreviation from uri
                if (strlen($lang_abbr) == 2)
                {
                    $uri_string = str_replace("/{$lang_abbr}", '', $uri_string);
                }

                //redirect
                header("Location:".$base_url.$index_page.$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 .= ($index_page) ? "/{$lang_abbr}" : "{$lang_abbr}";
            }
        }

        //reset the the config index_page value
        $index_page .= ($index_page) ? '/' : '';

        $RTR->config->set_item('index_page', $index_page);

        //load the user language file
        parent::load($user_lang, $user_lang);
    }
}


?>



URI Language Identifier and CI 1.6.1 - El Forum - 04-30-2008

[eluser]wiredesignz[/eluser]
application/libraries NOT system/libraries

Read the User Guide! and the wiki article!!


URI Language Identifier and CI 1.6.1 - El Forum - 04-30-2008

[eluser]xwero[/eluser]
wiredesignz is his merry self again Smile


URI Language Identifier and CI 1.6.1 - El Forum - 04-30-2008

[eluser]wiredesignz[/eluser]
*bows* :lol:

An occasional `thank you for helping` would be nice too.