views:

276

answers:

0

Overview

I'd like to hear feedback on my approach for internationalizing an AJAX application. Is this a sound approach? What kind of other approaches would be worth considering? Here's a summary of the app:

  • AJAX app running from a single HTML page generated server-side with i18n
  • HTML page imports JQuery and plugins
  • Uses XHR to load server-generated i18n HTML templates as needed
  • Loads application data in JSON format from REST urls
  • Assembles results using templates and data

Further Details

Build an ajax heavy application that is pretty much just a single standard HTML page. This page is dynamically generated via a server-side framework and is fully internationalized on the server-side. This page loads JQuery as well as several plugins.

From this point on, the application primarily only performs XHR requests. Some of these requests are for HTML templates (snippets of HTML code with placeholders for where real data should go) that are used by JQuery to generate dynamic content on the page. These types of requests typically do not contain any application data, but just placeholders for where the data should be displayed. These snippets are generated dynamically on the server-side and i18n is used. They only need to be requested once per template.

The bulk of the requests as the application is being used are for application data. This data is retrieved via XHR requests to a REST service that outputs JSON data. This raw data is then used by jQuery code to populate the templates and build parts of the page. Arrays of data cause the templates to be repeated. Because this data is what comes from the database, no i18n is performed on it.

Client-side Internationalization

If the UI ends up needing any other i18n strings, they could be stored in JSON and served either as part of the initial HTML page or as a special REST url that returns JSON key/text mappings. Features such as error messages might need this.

Client-side Localization

So this brings me to Localization. Things like dates and money are going to be transferred in normalized formats within the JSON data. So it will be up to the client to display this information in the correct format for the client. I don't think this will be too much of a problem, or will it?

If it will, maybe I should have the server-side return appropriate format strings based on the client locale. The client could use something like DateJS to format dates. I'm not quite sure about that yet, especially since DateJS is so big. But there are other client-side options that are much smaller.

Resources

I've found some jQuery plugins that might help with this. Anyone have anything to say about them? Or know of others?