Welcome Guest, Not a member yet? Register   Sign In
Multilanguage support?
#1

[eluser]Y0shi[/eluser]
Hello everybody.

I’ve been having some headaches recently because a client of mine. Since I’ve been working on a CMS which uses CodeIgniter as driving engine development of any kind hasn’t ever been a problem to me. But my new client is the first one who wants to manage multiple languages. So if this was a project from scratch it would be much work anyway but in this case (the CMS has been started getting developed about 1,5 years ago) it’s hard for me to find a nice solution.

Creating articles, managing forms or adjusting options for SEO issues – everything works fine. So how would you (in case you had a CMS which fits the scheme above) start developing a multi-language management in there? Duplicating the database, setting a prefix and write a route? Please tell me your thoughts.

Very excited to hear them Wink

Thanks in advance!

Regards
#2

[eluser]web-johnny[/eluser]
[quote author="Y0shi" date="1306703706"]Hello everybody.

I’ve been having some headaches recently because a client of mine. Since I’ve been working on a CMS which uses CodeIgniter as driving engine development of any kind hasn’t ever been a problem to me. But my new client is the first one who wants to manage multiple languages. So if this was a project from scratch it would be much work anyway but in this case (the CMS has been started getting developed about 1,5 years ago) it’s hard for me to find a nice solution.

Creating articles, managing forms or adjusting options for SEO issues – everything works fine. So how would you (in case you had a CMS which fits the scheme above) start developing a multi-language management in there? Duplicating the database, setting a prefix and write a route? Please tell me your thoughts.

Very excited to hear them Wink

Thanks in advance!

Regards[/quote]
A quick solution may be to add just a lang_id to each table. It will be hidden so the customer will not see it . You will have it though as hidden field. Also the queries will be easy because you will add just a $this->db->where('lang_id',$language);
#3

[eluser]Y0shi[/eluser]
Nice solution but if you think further - are routes like www.domain.com/lang/articles/lorem-ipsum possible?
#4

[eluser]web-johnny[/eluser]
[quote author="Y0shi" date="1306723411"]Nice solution but if you think further - are routes like www.domain.com/lang/articles/lorem-ipsum possible?[/quote]
The route you could write is something like this
Code:
$route["(greece|english|italian)/(.*)"] = '$2';
#5

[eluser]osci[/eluser]
As of the routes you can have a look at URI Language Identifier
#6

[eluser]Y0shi[/eluser]
Thanks a lot for the replies !

Do you think it would be a secure way to do following:
1. Grab web-johnny's idea and implement a lang_id to each entry
2. Add a hidden field of the language id to each form via jQuery
2.1 Alternative would be to set a CONSTANT with for example define('current_language', $this->uri->segment(1)) - or something like it
3. Grab the 1st segment of the route always as lang, interpret it in the core controller and execute mysql queries according to that
3.1 If done with the constant way much time would be saved here

What do you think?

Regards
#7

[eluser]web-johnny[/eluser]
[quote author="Y0shi" date="1306792286"]Thanks a lot for the replies !

Do you think it would be a secure way to do following:
1. Grab web-johnny's idea and implement a lang_id to each entry
2. Add a hidden field of the language id to each form via jQuery
2.1 Alternative would be to set a CONSTANT with for example define('current_language', $this->uri->segment(1)) - or something like it
3. Grab the 1st segment of the route always as lang, interpret it in the core controller and execute mysql queries according to that
3.1 If done with the constant way much time would be saved here

What do you think?

Regards[/quote]
That's right the only thing that you can do extra is not to use the first parameter for the default language. For example
Code:
$language_string = $this->uri->segment(1);
            
            switch ($language_string) {
                case 'italian':
                    $this->language = 'it';
                    $this->lang_segment = $language_string."/";
                    $this->lang_id = 2;
                break;
                
                case 'english':
                    $this->language = 'en';
                    $this->lang_segment = $language_string."/";
                    $this->lang_id = 1;
                break;
                
                default:
                    $this->language = 'gr';
                    $this->lang_segment = "";
                    $this->lang_id = 0;
                break;
            }
#8

[eluser]Y0shi[/eluser]
Well you guys helped me a lot!

But there's a last question - is there a way to append something to every mysql query executed?

For example inserts should alway have a varible set which tells them to insert

'lang_id' => 1,2,3... and so on

The same should occur for updates

update where entry_id = $id and lang_id => 1,2,3, etc...

Would you set this manually or automaticly?

Best regards and many thanks!
#9

[eluser]web-johnny[/eluser]
[quote author="Y0shi" date="1306910188"]Well you guys helped me a lot!

But there's a last question - is there a way to append something to every mysql query executed?

For example inserts should alway have a varible set which tells them to insert

'lang_id' => 1,2,3... and so on

The same should occur for updates

update where entry_id = $id and lang_id => 1,2,3, etc...

Would you set this manually or automaticly?

Best regards and many thanks![/quote]
I actually have a function helper and it something like this :
Code:
if ( ! function_exists('db_language_auto_language_id'))
{
    function db_language_auto_language_id()
    {
        $ci =& get_instance();
        
        $ci->db->where('lang_id', $ci->lang_id);
    }
}
and I put it in every query . For example if you had the query:
Code:
$this->db->where('status','active');
$results = $this->db->get('products')->result();

.......
I just copy the function so it will be
Code:
db_language_auto_language_id();
$this->db->where('status','active');
$results = $this->db->get('products')->result();

.......
and that's it ;-)
#10

[eluser]Y0shi[/eluser]
Thanks a lot Wink Well this all helped me a lot... the last prob are my SEO routes...

I allow my clients to set their routes manually. For example article/showarticle/1 gets lorem-ipsum-is-great as SEO route. So that means surfing to domain.tld/lorem-ipsum-is-great will bring the article with id = 1 up.

The same goes for forms (e.g. domain.tld/contact) and other stuff. I need a method to make sure, that only the routes which are in the current language enviroment (de, en etc.) are loaded. Currently I load my routes dynamicly via a hook. But neither in the hook nor in the config files a constant will be echoed correctly... because it isn't set of course.

So what can I do?

I also got this in my routes:

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

which is from the URI library. I think this will override anything if im trying to include the language abbreviation in my dynamically set routes. For example route['lorem-ipsum-is-great'] would then be route['en/lorem-ipsum-is-great'] and in German route['de/lorem-ipsum-ist-superklasse']...

Any thoughts?

Best regards Wink




Theme © iAndrew 2016 - Forum software by © MyBB