0

I've been researching for hours and hours, but I could not find a clear, efficient way to solve my problem.

I have 2 templates(header+content+footer) in Arabic & french. For each language different pages and different functions are in my controller. How can I make a multilingual website?

To pass in my link ?lang=fr or ?lang=ar without compromising my link which is similar to: localhost/site/controleur/method/id

Ps: i'm using a mysql db .

Hasnae Idem
  • 39
  • 1
  • 10

4 Answers4

1

Yes you can create a separate lang folder(for each language) having a file with similar keys but the value(text) will be according to language type. And then include that particular language file(folder) on request by identifier.

MaNKuR
  • 2,578
  • 1
  • 19
  • 31
  • what about the text position ?? we read arabic at right , and french by left .. – Hasnae Idem Apr 04 '13 at 23:00
  • 1
    I think in this case you have to load all the `lang` library and customized the `lang` files further by adding a position like french to left then its each key will start with LEFT_KEY_NAME. and using `if` clause can determine the text position. Means dynamically you can switch the `lang` position Hope this will make sense to you :) – MaNKuR Apr 05 '13 at 07:21
0

Why don't you just use sub-folders for your controllers based on the language?

controllers/ar/my_controller.php
controllers/fr/my_controller.php

http://www.example.com/fr/home
http://www.example.com/ar/home
stormdrain
  • 7,915
  • 4
  • 37
  • 76
0

Why do you need different pages for your website? IMO, you need to switch templates or load different controllers based on the language

Just in case and if you are just starting your project, you may find Bonfire much better suited for this. It supports templating and internationalization in a much easier way.

Chibueze Opata
  • 9,856
  • 7
  • 42
  • 65
  • thanks for answering , i need different pages because i'm using 2 differents languages on reading , we read arabic from the right , french from the left , so we gave me 2 distinct templates with different css – Hasnae Idem Apr 04 '13 at 17:21
0

Codeigniter has already provided with multi language facility, Its internationalization support,

All you need is a controller, language files, and view.

Based on the selected language, your controller will load the respective language file, and the view file will display the templates written in the language file.

Your language file will look something like this

$lang['language_key'] = "The actual message to be shown";

Your controller, the value of the siteLang can be retrieved either from the url, or you can have it stored as cookie in the browser.

function home(){ 
    $this->lang->load('home', $this->siteLang);   
}

Your view will look like, through this the value of the language_key will be displayed on that controller.

<?php echo $this->lang->line('language_key'); ?>

Some key points like the nomencalature of the lang files etc, You can find more about it, at the below link http://ellislab.com/codeigniter/user-guide/libraries/language.html

Nishant
  • 3,614
  • 1
  • 20
  • 26