0

We have done the website content in English language, now we want to add multilingual option to the website. There are more contents in English language, all content needs to convert into new language.

I can Create a table like this

 content_id
 en_title
 ar_title
 fr_title
....

But more existing content are there in English. Any guidance would be appreciated.

iLaYa ツ
  • 3,941
  • 3
  • 32
  • 48

2 Answers2

1

You could devide the page into 2 tables

page
- id
- other info that is generic

part
- id
- part_id
- page_id
- language
- content

Now you can say get the contents of page x with the language y. Also you can "easily" (need to translate a lot :P ) add new languages, just throw them in the part table


I added the part_id to part. This way you can say something like i want from page x the part id y, with language q.

MKroeders
  • 7,562
  • 4
  • 24
  • 39
  • Yeah i can try this logic. But user select language 2 and the content does not exist in db means? is that correct way to display default language content if the selected language content does not exist? – iLaYa ツ May 29 '13 at 11:32
  • That is logic that you should say. I mean is a problem is a part of a language doesn't work. Yes then you need to translate everything. Otherwise you could use a default. You could also add a part that should be used as fallback – MKroeders May 29 '13 at 12:03
0

Most basic implementation for i18n can be done through language files. It involve 3 major steps

Step 1: Define language files

For your example, define 3 files en.php, fr.php and ar.php (or more for more languages). Better keep all these files in 'language' folder. File contents will be like

<?PHP
$LANG_LABEL_TITLE = "Title in specific language";

step 2: Include language file

There must be a common script for all your web accessible files; central controller or at lease a common header. In that file, detect default browser language and set it in session. Again include required language file there.

step 3: Use labels

Once you have required language file included, simple use the label at required position like

<title><?PHP echo $LANG_LABEL_TITLE; ?></title>

Again this is the most basic implementation. Go through it and if you stuck somewhere, ask question specific to that part.

Community
  • 1
  • 1
Kapil Sharma
  • 10,135
  • 8
  • 37
  • 66
  • This can be be done only for static content and labels, what about for dynamic content? – iLaYa ツ May 29 '13 at 11:30
  • Are you sure you really want to translate dynamic contents? If yes, check http://stackoverflow.com/questions/4640378/translate-a-php-string-using-google-translator-api But I'd certainly wont recommend that as no automated translator including google is perfect. – Kapil Sharma May 29 '13 at 11:37
  • No need of google translator here, that is admin part to upload multilingual content. – iLaYa ツ May 29 '13 at 11:44
  • Hmm that part was not included in original question. With new requirements my answer is useless. Still not deleting as it might help future visitors. – Kapil Sharma May 29 '13 at 11:53