Advice on ASP.NET Multi-Lingual Strategy

前端 未结 2 1426
花落未央
花落未央 2021-01-14 18:05

Hi brothers and sisters,

I am wondering if anyone would share their experience on what they think as the best strategy to enable dynamic multi-lingual system using .

2条回答
  •  抹茶落季
    2021-01-14 18:21

    There are several options available.


    First, to the labels and elements of UI.

    Here are generally two options possible, you either use resources (*.resx) or roll out your own multilingual support on the database level. They both have their advantages and disadvantages.

    Resoures:

    [+] Easy solution, everything is ready for immediate use. You define a textual resource in a family of files named like Orders.en.resx, Orders.fr.resx etc. In code you reference these strings as Resources.Orders.Title. So it is a simple solution for static elements of UI.

    [+] Resource files are basically simple XML documents that can quickly be read and parsed, so not much overhead or performance loss.

    [-] If you need to change something, you will have to recompile the project. That consequently means you will need the development environment (VS) installed for anyone who may consider updating texts. Then, you will also need to deploy the recompiled version again. The same applied for introduction of new languages into the system.

    [-] Will not work for non-technical stuff, since participation of specialists required.

    Custom database-driven multilingual solution:

    [-] Will require some effort and time to design and implement

    [-] Every single UI text will be pulled from the database, which means performance drop and extra load on the database

    [+] Will allow dynamic on-the-fly change of texts and deletion/addition of new languages. No recompilation or deployment will be required.

    [+] Now a huge plus. Since no technical skills are required to work on texts, you can outsource this work to any location. You may implement a web interface and change tracking system for professional translation service shops to correct your texts and perform translations to any language you need quickly after new texts are discovered.


    Now to the dynamic texts (actual content).

    Here you can either split each text to be stored as an extra record per language in some table or to merge all translations into a single entity.

    Multiple records:

    Imagine following database model:

    [Language]
    -----------------
    ID    Description
    
    [Translation]
    ------------------
    ID    FallbackText
    
    [TranslationText]
    --------------------------------
    ID    TRID    LanguageID    Text
    
    [Order]
    ------------------------------------------------
    ID    TitleTRID    DescriptionTRID    RemarkTRID
    

    Everywhere in the database where you need to store a multilingual text, you will instead reference some TranslationID. Then dependent on the active language, you system will look for an appropriate translation or, if not found, return a default text (usually set by developers).

    Single entity:

    You keep all translations for a given text in one string by using some means of distinguishing particular translations. XML naturally works here.

    
      Order
      Bestellung
      Commande
    
    

    Here you database model will be simpler but you will need to parse every single text to extract the needed version.


    These are the widely used strategies. Which one will work best for you will depend on your needs and your expected usage scenarios.

    Hope that helps. :)

提交回复
热议问题