How to localise static website text from translations stored in a database?

痴心易碎 提交于 2019-12-06 07:18:37

This is how we handle text translations in the database (it may sound pretty obvious but at least this is highly scalable):

  1. Say you have a table tbl_Content with columns [id], [title] and [description] in just one language.

  2. What we do is first create a tbl_Content_Translation with the columns: [id],[languageId], [title] and [description]

  3. Copy whatever you have on the title/description columnns to the translation table to be sure you don't loose anything

  4. Delete the title and description columns in the original table

  5. Change all the SPs that query this table to add a [languageId] parameter.

  6. We attach the SPs to our BLLs.

  7. Finally, either from a web page or a web method, we call the BLL to access our data.

Again, this may seem pretty obvious, but as it is working for us (ajax calls and normal web pages in english, french and vietnamese) i supposed this could be useful.

Mr Shoubs

Server side translation turned out to be rather convoluted.

I thought the simplest approach is to use jQuery localisation to get language scripts generated from the database, however this didn't add any value, so I just get the script from the server manually using an ajax request (each language has a different generated script).

The script I get from the server contains varibles for the translation (the varibles are the same name as control id), which I pass as an array of objects e.g. {id:'controlid', val:controlid} to a method that apply's the translation, so when the script is called, the page gets translated.

It is a shame there doesn't seem to be a good best practice for this, what I have done isn't complex, but it would be nice if there was a library or plug in that did it all.

Simlar to this answer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!