• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 144
  • Last Modified:

localization using Jquery

I need to make my web app multi lingual
Its currently done using asp.net 4.5 webforms and Jquery

I figured I could just name each DOM element with and ID and lookup the translation in an XML file containing the translations

Has anyone done this? and can you shed some light/ examples on the best way to achieve it
performance and being able to do it quickly is key
Ideally it would cache too
0
websss
Asked:
websss
  • 2
1 Solution
 
Alexandre SimõesManager / Technology SpecialistCommented:
In my opinion, if it's a server-side application you should bring the page already translated.
The problem of translating in the client-side is that the user will see labels popping up here and there while the translations are being applied. To avoid this you need to hide the form until the translation process is finished.

Another problem is that you have to load the full translation resource to the client, even if he only uses a part of it. Of course you can implement a partition strategy splitting translations by page but there will always be shared translations across pages and is something you have to deal with.

When user changes language probably you'll need to refresh the whole page anyway depending on the kind of data you're showing so I think for ASP.net apps, server-side translation approach is the best.
Save the user language in the session and apply it on every page rendering as easy as using the server-side tags in your html:
<%= i18n("user.name") %>

Open in new window

For this to work, just create a static method called i18n or create a base form that all forms inherit from (I like this one better) and implement your logic there, receiving a translation key and returning the translated value.
Store your translations either in textfiles (plain, JSON or XML that you can easily deserialize), database or even resource files it really doesn't matter as long as you abstract the way you fetch this information in your own i18n method.
This way you can even change your translation strategy in the future without the need to mess up with what's already in place.

Just as a justification why to store the translations in the DB, the best argument is if you have reports, specially in SSRS.
You'll want to reuse the same translations in both application and reports.
0
 
websssAuthor Commented:
Thanks
So you say do it server side....but not use Resx files?
I thought this was the obvious option for server side?

I write HTML server side and its generated by Javascript, so it would have to exist on both server and client
I was thinking it would be easier to do in one place

...also about your comment with labels changing.... I can imagine this happening if you are using a default language, i.e. default to english then switch to other language if needed ....instead of having blank values and populating with a specific en/fr/es/de etc  JSON file

What are other down sides about using client side?
0
 
Alexandre SimõesManager / Technology SpecialistCommented:
I thought this was the obvious option for server side?
Depends on what you are doing. I explained above why it's a good idea to abstract your translation logic and why it might be a good idea to put your translations in the DB.

I write HTML server side and its generated by Javascript, so it would have to exist on both server and client
I was thinking it would be easier to do in one place
You can also request the translations to the backend and receive a JSON object with the key value pairs for the language.
This way, even if you have a mixed internationalization strategy, the translation files are only in one place.
Basically the most part will arrive with the static HTML and only the dynamic part will have to be translated with javascript.
Anyway, and if you're generating HTML in javascript, consider applying the translation directly to the templates when the page loads.

instead of having blank values and populating with a specific en/fr/es/de etc  JSON file
You'll still see the translated values popping up, specially on slower machines.
It's fast but looks clumsy. The best solution if to simply hide the whole thing until the translations are all applied.
At the end it will still look like the page is loading.
Another side effect is that different languages have different text lengths. While applying the translation in javascript, the user will see the page moving and adjusting while the text is being applied.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now