Current location: Hot Scripts Forums » Other Discussions » Database » multilingual website databases schemas


multilingual website databases schemas

Reply
  #1 (permalink)  
Old 03-30-11, 11:23 AM
samaa's Avatar
samaa samaa is offline
Newbie Coder
 
Join Date: Oct 2007
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation multilingual website databases schemas

hello guys .. I need your advice for my current project.
Q for programmers and DB Administrators .. if you planning to Build a multilingual website, what is the best databases schemas to use?
1- duplicate the column name(field). example : (title_en , title_ar)
2- duplicate the row for each record & using a field to specify the langue (content_lang)
* I know there is another ways for multilingual website like Translation table but I don't want to uses these becuse I will have just 2 languages.

thanx (f)
Reply With Quote
  #2 (permalink)  
Old 04-01-11, 06:40 AM
dgreenhouse's Avatar
dgreenhouse dgreenhouse is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: San Francisco
Posts: 457
Thanks: 0
Thanked 3 Times in 3 Posts
That's a really good question...

A possible method would be to have a separate table for the translations and then to issue a query with a coalesce function in the where clause.

i.e.
possible structure for language_table: (could have better naming)

1- id, text_field_name, field_text, lang
2- id, text_field_id, field_text, lang

Queries:

1- select field_text from language_table where text_field_name = "the_field_name" and lang = coalesce("target_lang","default_lang")

2- select field_text from language_table where text_field_id = the_id and lang = coalesce("target_lang","default_lang")

An added benefit is that you can add any number of languages with little effort.

For these queries to work, YOU SHOULD have a text entry for the default language or the query will return a null record if you forget to add translation text for the “non-default” language you’re trying to retrieve.

Query option 2 above will be faster, but you'll incur additional overhead in determining the id of the translation text. This overhead will be incurred both when you add new text and when retrieving existing text. Possibly obviated by having a (field_name <==> field_id) joining table but still causing more complexity.

Of course with either option the columns should be properly indexed.

Finally; and back to what you're trying to avoid , the fasted method would be to have separate language tables in case there's lots of translation text.

i.e.

Code:
  // base lang = us-en
   
  $lang = 'fr-ch'; // desired language Swiss French
  $field_name = 'site-title'; // Get the site title
   
  $query =
     sprint(
       'select field_text from %stranslation_table '
     . 'where text_field_name = "%s"',$lang,$field_name
     );
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
multilingual website databases schemas samaa Database 1 03-30-11 10:01 PM


All times are GMT -5. The time now is 05:16 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.