Angular and i18n

Well it has been a long while again, but I’ve been crazy busy at work.

I worked on a couple of interesting Single Page Applications written with Angular and I really like it because the Framework is so simple to use and very well documented with a crapload of nice plugins and extensions from the community. Anyhow I needed to implement some sort of internationalization and angular has a nifty extension called angular-translate which I used for that. In the process we created an i18n self hosted service in c# with nancy with a simple rest api where I can get a list of available languages for specific domains. Domains in this context are just language sections so that I only have to request and transfer the sections actually in use. The angular plugin has a nice way of supporting it with „partials“

so include the partials-loader and url-loader for angular-translate and set it up the following way:

 

This sets up the angular-translate plugin to work with partials which are loaded on demand from an rest service.

Since we are lazy we wanted to have some sort of automatically adding missing translations to the system.

The registered function in useMissingTranslationHandler handles this for us.

The handler is implemented as a angular factory and sends missing translations to a Model which hols a queue to bulk insert the translations to the i18n service.

This is done since we would exceed the allowed number of ajax connections on large applications at the first startup

I’m quite happy with this solution even though I think it has some room for Improvement.

Kommentar verfassen