… or the coding equivalent to wearing your best undies in case you get run over and a doctor sees them (at least that’s what my gran always used to say!)
Back in the dim and distant past we thought we might open source OU Annotate. We’ve never done it, for a number of reasons – some political, some resource, and to a limited amount some technical. I still hold out the hope that our work might be useful to some-one else one day, but this isn’t something we’re discussing really at the moment internally.
So, when I make a coding change that would be of benefit to an open-source community around OU Annotate, it could be seen as the coding equivalent of wearing your best undies. In the main, no-one but you is going to see them and anyway it makes you feel better that everything is lovely. I’ve probably stretched this metaphor about as far as it’ll go … the other software reason for doing this sort of thing is because it will make things easier for you to maintain in future as well.
Recently I added language pack support to the bookmarklet. I posted ages ago some thoughts about how to do this, so I thought I’d share what I eventually did.
1. I declared a global default language, and set it to en_GB. This is done in the defaults definition script that also has things like the base url in.
3. When the user details are pulled across from the annotate database, include the language defined in their profile. Just before the annotations are being loaded onto the screen display, if the language differs from the system default, include the appropriate lang/xxx.js file for their language. By doing this before any screen display, the first things the user sees will be in the correct language, and we’re using an existing AJAX loading() deferred period.
4. I defined a new global function _t which takes a language string identifier as parameter, e.g. _t(“TOOLBAR_SPLASH”). This function looks up and returns the appropriate string in the language pack file. A second parameter can pass through an array of variables to be replaced within the body of the string.
6. Painstakingly identify and convert all strings littered through the bookmarklet code and views (its MVC) to use the new function and put the strings in the language pack.
One extension could be to control all the language strings for both the main OU Annotate system and the bookmarklet from one language pack. I did consider doing this. Basically you’d add:
I decided against this because
a) its another AJAX call between the user and the server which takes time
b) if something goes wrong with the AJAX calls, I can’t give errors in the appropriate language
c) there’s actually very little language string sharing between the two parts of the system.
This is probably the only change that will be included in our June release, but from then OU Annotate will be out there with her new undies on and hopefully you’ll never even notice!