2

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).

Community
  • 1
  • 1
Mr Shoubs
  • 14,629
  • 17
  • 68
  • 107
  • If it's a static site, it seems more trouble to hack-in a language layer client-side than it does just to convert it to a CMS and do it server-side. – Diodeus - James MacFarlane Jun 19 '12 at 19:56
  • @Diodeus (updated question) This sounds like an approach to consider, (but this isn't a CMS), could you elaborate in an answer? (note the HttpResponse.Filter approach). – Mr Shoubs Jun 19 '12 at 23:22
  • You need to suck it all into some sort of database really, how you serve it up is a separate matter. Patching into the original software may be a choice as well. – Diodeus - James MacFarlane Jun 20 '12 at 02:55
  • @Diodeus The translation is in a database already, the question is about serving it up. – Mr Shoubs Jun 20 '12 at 09:50

2 Answers2

0

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.

Vladimir
  • 408
  • 2
  • 7
  • We have this for various dynamic data, for example category names, or a selection of titles (Mr, Mrs, etc) in a drop down list, however this question really relates to the static text in the page, all the labels etc - they are only different for each language. – Mr Shoubs Jun 20 '12 at 09:49
  • This sounds like a CMS approach though, where the content is what your site is about, this isn't quite the same and we don't have large chunks of translated data, as I mentioned, just labels etc - the static text that appears for every user). – Mr Shoubs Jun 20 '12 at 10:04
0

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.

Community
  • 1
  • 1
Mr Shoubs
  • 14,629
  • 17
  • 68
  • 107