1

Possible Duplicates:
Create a webpage with Multilanguage in PHP
PHP - how to translate a website into multiple languages?

I want to make a site which will have 3 languages - e.g. English, Arabic and Italian; the content sure will be different from one language to another.

Should I make different table for each language, e.g.:

en_articles
ar_articles
it_articles

each with the same article in different language,

or make one table articles like this:

article_id
article_en_title
article_ar_title
article_it_title

Please advise me.

Community
  • 1
  • 1
Mostafa Elkady
  • 5,645
  • 10
  • 45
  • 69
  • 1
    I guess i would go with multiple tables for each language and have a table with all available languages or the same centralized in an array or something alike. – Prix Jul 04 '10 at 15:14
  • 1
    This has been asked before in a number of variations. Searching SO for "php i18n" and "php multilanguage" should yield some results. – Pekka Jul 04 '10 at 15:27
  • See also: http://stackoverflow.com/questions/954160/php-how-to-translate-a-website-into-multiple-languages – Piskvor left the building Jul 04 '10 at 15:44

6 Answers6

3

Create a table with a list of languages, and an articles table with a language column. That way, if you add a new language, you only need to add it to the languages table.

Example:

table `languages`:
| id | name    |
================
|  1 | English |
|  2 | Arabic  |
|  3 | Italian |

table `articles` (only relevant columns):
| language_id | title      | content                                  |
=======================================================================
|           1 | Some title | Some content in English                  |
|           3 | Ascia      | Dio mio! C'e' un' ascia nella mia testa! |
|           1 | Axe        | Oh my god! There's an axe in my head!    |

This way, you won't need to change the database schema when adding languages. As you can see, there is one articles table with one content column - significantly simpler to use than multiple article tables or multiple content columns.

Piskvor left the building
  • 91,498
  • 46
  • 177
  • 222
1

I would suggest that you create only one table for the articles and put a column for the language. So, if you need to add a new language you don't need to change anything in your db

Ed.
  • 1,934
  • 15
  • 13
  • how if i want to add new one this want a change in the table to add new field with this lang if i used your method – Mostafa Elkady Jul 04 '10 at 15:19
  • In your first method you'd have to create a new table and in your second method you'd have to create a new column. In the method I presented, when you add a new entry, put in the language column the value of the new language – Ed. Jul 04 '10 at 15:33
1

When you use PHP, you can see here: http://www.bitrepository.com/php-how-to-add-multi-language-support-to-a-website.html

why
  • 1,275
  • 4
  • 12
  • 23
1

If you are very sure that you are going to work only with 3 languages, the best option is to use one table, with three columns, one for language:

article_id
article_en_title
article_ar_title
article_it_title

If eventually you need to add other language, only add other column.

If you think that you are going to add other languages, o you want to use the code for others web with differents languages, I think that the best solution is to use 3 tables, one for the languages, one for the articles and other table for relation them

table "languages"

language_iso
language_name

table "articles"

article_id
article_name (Internal name for the article)

table "articles_x_languages"

article_id
language_iso
article_title
article_text

I'm assuming that you are going to have each article in the three languages. Example:

Languages
language_iso | language_name
          en | English
          ar | Arabic
          it | Italian

Articles
article_id | article_name
         1 | Sample 1
         2 | Sample 2

Articles_x_languages
article_id | language_iso | article_title | article_text
         1 |           en | english title | Lorem ipsum ..
         1 |           ar |  arabic title | Lorem ipsum ..
         1 |           it | italian title | Lorem ipsum ..
         2 |           en | english title | Lorem ipsum ..
         2 |           ar |  arabic title | Lorem ipsum ..
         2 |           it | italian title | Lorem ipsum ..
Angel Aparicio
  • 374
  • 2
  • 11
1

If you are writing your website using java you might want to search about JAVA ResourceBundle, here is an example : http://java.sun.com/docs/books/tutorial/i18n/resbundle/propfile.html

If you are working with asp.NET you might want to check this: http://msdn.microsoft.com/en-us/library/ms228208.

Saher Ahwal
  • 9,015
  • 32
  • 84
  • 152
0

If you work with ASP.Net , look at here

http://msdn.microsoft.com/en-us/library/c6zyy3s9.aspx

onurbaysan
  • 1,248
  • 8
  • 27
  • Look at these: http://www.bitrepository.com/php-how-to-add-multi-language-support-to-a-website.html ------------------------------------ http://devzone.zend.com/article/4469 – onurbaysan Jul 04 '10 at 15:20