ASP.Net / MySQL : Translating content into several languages

后端 未结 2 1881
执念已碎
执念已碎 2021-01-06 11:49

I have an ASP.Net website which uses a MySQL database for the back end. The website is an English e-commerce system, and we are looking at the possibility of translating it

相关标签:
2条回答
  • 2021-01-06 12:11

    It's not good idea just to add new columns to existing table. It will be really hard to add a new language in the feature. The lookup table is much more better but I think you can have problem with performance because number of translated records.

    I think best solution is to have a shared table:

    products: id, categoryid, 
    

    and same tables for every language

    products_en, products_de: product_id (fk), title, price, description, ...
    

    You will just select from the shared one and join table with your language. The advantage is that you can localize even the price, category, ...

    0 讨论(0)
  • 2021-01-06 12:28

    In your case, I would recommend using two tables:

    Product
    -------------------------------
    ProductID  |  Price   |  Stock 
    -------------------------------
    10         |   10     |   15
    
    
    ProductLoc
    -----------------------------------------------
    ProductID  | Lang   | Name      |  Description
    -----------------------------------------------
     10        |  EN    | Bike      |  Excellent Bike 
     10        |  ES    | Bicicleta |  Excelente bici 
    

    This way you can use:

    SELECT * FROM 
    Product LEFT JOIN ProductLoc ON Product.ProductID = ProductLoc.ProductID 
                                   AND ProductLoc.Lang = @CurrentLang
    

    (Left join just in case there is no record for the current lang in the ProductLoc table)

    0 讨论(0)
提交回复
热议问题