I need to design a translation mechanism/strategy for the static text in my (scalable) web applications - which are based on HTML, JQuery/JavaScript in an ASP.NET environment (but no server side controls) with dynamic data loaded from asynchronous jQuery calls to http handlers.
I have successfully localised numbers, dates, etc using Globalize, however now need to sort out the text translation.
Translated text is stored appropriately in a database (maintained by native partners in another application), therefore, I do not want to use a file based ResX equivalent, like jQuery Localisation/jQuery Localize/jQuery-i18n-properties approaches, instead I am after a solution similar to extending the Resource-Provider Model that localises ASP.NET controls (which I don't have), to get the translation from the database.
Client Side Approach: I just stumbled across i18next's dynamic (non-static) resouce route and am trying to work out if I can return something like that from a http handler (and caching in JStorage/LawnChair) to fill in place-holders/tags using the jQuery function or take a similar approach with Moustache or hogan.js templates.
Server Side Approach: Modify the HTML before it is served, for example this answer suggests using the HttpResponse.Filter to modify the response server side (see this article). As the buffer is chunked, I'd have to capture the entire stream as suggested here, which does lead to a performance hit, however, I hope I can mitigate this by caching each (language) version of the page.
Or use HTTP Handlers like this looks like simpler approach, though I am less sure how to cache multiple versions of the page in this instance.
Does anyone else have experience with these approaches or know of anything similar or 'best practices' that meets the requirements especially in terms of performance, scalability and maintainability?
If anything isn't clear, please let me know, I am new to web development. :)
Note: This is for web applications running on tablets/hand-held devices for data capture, it isn't a CMS or static site (the previous incarnation used to run on the .Net Compact Framework, for about 5 years and it's time for an update so users can use non-windows devices such as android and IPad).
This is how we handle text translations in the database (it may sound pretty obvious but at least this is highly scalable):
Say you have a table tbl_Content with columns [id], [title] and [description] in just one language.
What we do is first create a tbl_Content_Translation with the columns: [id],[languageId], [title] and [description]
Copy whatever you have on the title/description columnns to the translation table to be sure you don't loose anything
Delete the title and description columns in the original table
Change all the SPs that query this table to add a [languageId] parameter.
We attach the SPs to our BLLs.
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.
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.
来源:https://stackoverflow.com/questions/11107773/how-to-localise-static-website-text-from-translations-stored-in-a-database