Multilingual fields in DB tables

前端 未结 5 482
北海茫月
北海茫月 2020-12-19 15:07

I have an application that needs to support a multilingual interface, five languages to be exact. For the main part of the interface the standard ResourceBundle approach can

5条回答
  •  渐次进展
    2020-12-19 15:18

    The approach I've seen in an application with a similar problem is that we use a "text id" column to store a reference, and we have a single table with all the translations. This provides some flexibility also in reusing the same keys to reduce the amount of required translations, which is an expensive part of the project.

    It also provides a good separation between the data, and the translations which in my opinion is more of an UI thing.

    If it is the case that the strings you require are not that many after all, then you can just load them all in memory once and use some method to provide translations by checking a data structure in memory.

    With this approach, your beans won't have getters for each language, but you would use some other translator object:

     MyTranslator.translate(myBean.getNameTextId());
    

提交回复
热议问题