Holidays are closer with each day and it’s getting harder and harder to concentrate on work, when your mind is occupied with loot coming your way.
You know, sort of a present for everyone as it befits this holiday.
There have been few changes since last time . The whole thing has been objectified, but I kept few functions ( stripStr , stripStrML and new one printf ) outside of a class, since they’re too general to belong there. Nice thing about new class is that instead of looking for globally defined translation dictionary, it’s initialized with one. This also means you can use more than one translation object or translation dictionary per page, which sounds cool even if not all that useful.
I made a small correction to method toEntity . A bug was pointed out to me by Opera browser , which is a great browser for testing against standards, if not common sense. I might think it’s OK to fetch a character out of a string with their index value, as you would fetch an element from a list or an object, but I would be wrong. That’s why a string method charAt was defined and if working everywhere except in Opera is not good enough for you, then you must use this method. So, I did.
I also renamed the function _ . It’s a nifty name widely used in other languages, but it doesn’t work quite like that when it’s a method in an object. init.js demonstrates how you can still use it by defining an anonymous function.
This is it for now. I think the library is actually usable, but it’s also lacking few things. printf provides now a method of easily stitching stings together and even using parameters in translations. However, it does require that those parameters are listed in same order as in original text. Better than previously, but still often awkward.
Last but not least, it needs a useful documentation on how to use it and work with it. It will get it.
Update: It turns out my code might be usable, but it’s certainly not good. Some issues were listed in later post and some I discovered just recently. For instance it won’t work if you’re trying to translate text on buttons or if text to be translated includes HTML tags (case of tags is not preserved in DOM tree, which wouldn’t be a problem if Firefox and IE defaulted to the same one).