Note that there are some explanatory texts on larger screens.

plurals
  1. POLocalization with mysql/PHP
    primarykey
    data
    text
    <p>I'm currently building a multilingual website using PHP and MySQL and am wondering what the best approach regarding localization is with regards to my data model. Each table contains fields that need to be translated (e.g. <code>name</code>, <code>description</code>....) in several languages.</p> <p>The first idea was to create a field for each language (e.g. <code>name_en</code>, <code>name_de</code>, <code>name_fr</code>) and retrieve the appropriate field from PHP using a variable (e.g. <code>$entry['name_' . LANGUAGE]</code>). While it would work, this approach has in my opinion many drawbacks:<br> -you need as many occurrences of each field as you have languages (bearing in mind you can have en-US, en-CA, en-GB...)<br> -if you add or remove languages you need to modify the database structure accordingly<br> -if you have untranslated fields, they are still created for each entry which doesn't seem very optimized</p> <p>The second idea is to create a translation table that can be used to store the translation of any field of any table in the database:</p> <pre> ---------------- translation ---------------- id INT table_name VARCHAR field_name VARCHAR value VARCHAR language_id VARCHAR </pre> <p>The <code>table_name</code> and <code>field_name</code> will allow identifying which table and which field the translation is about, while <code>language_id</code> will indicate which language that translation if for. The idea is to create models that would replace the value of the translatable fields (e.g. <code>name</code>, <code>description</code>) by their corresponding translation based on the language selected by the user.</p> <p><strong>Can you see drawbacks with this approach? Have you got suggestions to make?</strong></p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload