Welcome Guest, Not a member yet? Register   Sign In
Different languages URIs
#1

[eluser]aka_kalle[/eluser]
Hi there!
I have a page that will be available in a lot of different languages and for it to be as SEO optimized and good looking as possible I need the URIs to be in different languages as well.

For example:
www.mypage.com/news - English
www.mypage.com/nyheter - Swedish

There will be a lot of pages so a htaccess rewrite is not possible. The controller called should always be "news" but somewhere I need a check to change "nyheter" to "news" before the control is loaded - I don't want a different controller for each page and language.

Any ideas how to solve this? I would prefer not to edit too much in the main CI files. Thank you!
#2

[eluser]umefarooq[/eluser]
Hi check check the following multi lang library it will help you to solve you problem, here no need to change any thing in you controller you have to check which language you are using and can display that language content with same controller, and no need to change in .htaccess file and you link will also SEO friendly.

http://maestric.com/doc/php/codeigniter_i18n
#3

[eluser]aka_kalle[/eluser]
Hi, thank you for your reply. This looks good but it still doesn't help me with localizing the URL's. As said in the comments to i18 you don't want the URL to be in English is the site is in Swedish, like "News" would be "Nyheter" in Swedish. Im thinking I could fetch the segments in the routes files and check it against the db, what do you think?
#4

[eluser]Flak[/eluser]
maybe you have solved this, but I think you need to get url segmet and query like where slug= segment(1) or you need a complex query where you check slug get id and langid, get content and convert them back.

If you have any solution let me know, I need that too. Smile

Flak.
#5

[eluser]aka_kalle[/eluser]
[quote author="Flak" date="1257811422"]maybe you have solved this, but I think you need to get url segmet and query like where slug= segment(1) or you need a complex query where you check slug get id and langid, get content and convert them back.

If you have any solution let me know, I need that too. Smile

Flak.[/quote]

Hi Flak!
I did solve this just the other day. The solution I used was using the RouterHook:

Code:
class RouterHook{
    function GetRoutes(){
        global $DB_ROUTES;
        global $SHORTNAME;
        
        $db_conn = mysql_connect('localhost','root','');
        mysql_select_db('ebs',$db_conn);
        $sql = "SELECT * FROM routes_" . $SHORTNAME;
        $query = mysql_query($sql,$db_conn);
        $routes = array();
        while ($route = mysql_fetch_array($query, MYSQL_ASSOC)) {
            $routes[$route['route']] = $route['controller'];
        }
        mysql_free_result($query);
        mysql_close($db_conn);
        $DB_ROUTES = $routes;
    }
}

Where shortname would be the shortname of the language selected. The route would be "nyheter" and controller the route shown to CI (the controller to be loaded), "news". Hope this helps!




Theme © iAndrew 2016 - Forum software by © MyBB