Hi,

I need to make a multilingual website in php.
It will have text as well as products which come from a database.

I dont have any idea as to how to do this.

Any help, preferably with links to examples, about designing database, creating pages etc will be greatly appreciated.

There will be 4-5 categories in which there will be products for each category.
THe product description will be in each language as the case may be.

The pages will also have text/other elements in the respective language.

regards
Amol.

    Several ways to do this. In concept it is simple.

    1) Store each language translation in a different place
    2) Store a users preference for a language somewhere
    3) Have php choose between language storage locations at page load time

    Here is vanilla pseudo-code example :

    1) In sql you could store one translation table per language
    PRODUCT: id, cost
    PRODUCT_EN: id, english_description
    PRODUCT_ES: id, spanish_description

    2) In sql store a language preference
    USERS: id, login, password, language

    3) When grabbing the product from the database
    so now [url]http://...../viewproduct.php?product=100[/url]

    <?php
    /// find their language preference from database. assuming you know login already
    $user = SELECT * FROM USERS WHERE login = $login
    /// now $user->language = 'ES'
    /// so join your product table with your language table to get description
    $product = SELECT * FROM PRODUCT P, PRODUCT_{$user->language} L where P.id = L.id AND P.id = $_GET['product']
    /// now $product->description = 'something in spanish'
    
    ?>
    
    

    Now essentially you would have to store each translatable sections of text on the page somewhere in a database of some kind. This could get tedious.

    I believe if you use SMARTY Templates to render your html there is a translation or internationalization plugin/addon that will do this language lookup for you based off flat files instead of database tables, but essentially the concept is the same. You would wrap arbitrary text in a language tag {l}like this{/l}. Upon rendering time smarty would look for a language preference, then pull out the text in the tag, see if it has a translation anywhere and replace it with prewritten translation if found.

    essentailly the smarty structure would look like this is described in SQL
    LANGUAGE_EN: text, translation
    LANGUAGE_ES: text, translation

    Where "text" is an arbitrary block of text, or maybe just an md5 of the text, and the translation is the translated text you have to have gotten ahead of time.

      Hi ednark,

      Thanks for taking the trouble to reply.
      Good suggestions you have there.
      I'll surely implement it.

      I'm not using smarty though.
      for text sections of the site i'm thinking of using the define() function in php to define all text which will be needed.
      Pl le me know if you feel this is a good idea. also if there are any performance issues for define.

      thanks again for your suggestions.

      Amol.

        Write a Reply...