Welcome Guest, Not a member yet? Register   Sign In
Static website in 2 languages
#1

[eluser]Berik[/eluser]
Hi there!

I'm working on a website that will be in french and english. About 90% of the site is static text and I'm wondering what would be the best way to manage the dual language part.

1 - make controllers/views in each language.

OR

2 - put all the text in a database and just pull it out depending on the language selected.

The site itself will have around 6 pages per language and I'm figuring it would be quicker to just have different views and controllers to avoid having to use models and database connectivity...

What would you do ?

Cheers - Erik
#2

[eluser]überfuzz[/eluser]
I'd make one view file per text layout.
Example:
Code:
<html stuff>
<head>stuff</head>
<body>

<?php
echo "<h1>".$title."</h1>";
foreach($stuff AS content)
{
   echo "<h2>".$content['subtitle']."</h2>";
   echo "<p>".$content['text']."</p>";
}
&lt;/body&gt;
&lt;/html&gt;

Now you can use the controllers to load or pass different $stuff to the viewer. Make a model content.php to get the info from the database, use two methods english & french. Call them accordantly.

Code:
$this->load->model('content');
$this->content->english() // or
$this->content->french()
#3

[eluser]Berik[/eluser]
Thanks for your insight überfuzz Smile
#4

[eluser]jegbagus[/eluser]
actually CI already provide multi language support...
this is my code (placed in extend controller), just change the cookies with your language name.
Code:
/*
     *  lang retriever
     *     load appropriate lang for site
     */
    private function load_lang(){        
        // get lang from cookies
        $lang = get_cookie('lang');
        
        // default language is english if lang not set or lang was invalid
        if($lang == null || $lang == '' || !in_array($lang,$this->available_lang)) {
            $lang = 'english';
            
            // set cookies            
            $cookie = array(
                'name'   => 'lang',
                'value'  => $lang,
                'expire' => '216000',
            );
            set_cookie($cookie);        
        }        
        // load appropriate lang file
        $this->data['lang'] = $lang;                      
        $this->lang->load('site',$lang);        
    }

in your application folder, it will be :
Code:
application
|
| language
   | english
     | site_lang.php
   | your lang
     | site_lang.php

site_lang example
Code:
&lt;?php if(!defined('BASEPATH')) exit("Hack Attempt?");

$lang['home'] = 'Home';
$lang['aboutus'] = 'About Us';
$lang['faq'] = 'FAQ';
$lang['contactus'] = 'Contact Us';
$lang['news'] = 'News';
$lang['pollresult'] = 'Poll Result';
$lang['profile'] = 'Profile';
#5

[eluser]Berik[/eluser]
Well yes CI does have language support built in but I was thinking that it was bulky for translating the entire content and not just the menus and site actions.

This is why I was thinking of having different views and/or controllers, making it easier for text/layout updating. As it's a very small site (few pages) it seemed reasonnable. Of course for a larger scale site the problem would have to be taken differently Smile

Anyway it's nice to see what you guys are doing in this area, thank you for your help!
#6

[eluser]Fatih[/eluser]
Please be careful that if you store language variables to cookies and don't place to url line, search engine robots shall not be crawl your web site regularly.

Please also evaluate this situation.




Theme © iAndrew 2016 - Forum software by © MyBB