Internationalisation of BXE User Interface
Christian Stocker <[email protected]> Thu, 16 Dec 2004 11:27:25 +0100
| Newsgroups | gmane.editors.bitflux.devel,gmane.editors.bitflux.general |
|---|---|
| Message-ID | <[email protected]> |
Hi (I'm CC'ing [email protected], as they might be interested in that as well) I had a request (or more in the last months) for making BXE multi-langual. There's nothing, which stands against doing it, except my precious time ;) But here are my thoughts: We use XML documents for defining the "strings". As we use the cocoon i18n format already in our CMS, it makes a lot of sense to us, to use that XML format. Here's an example (and more info about cocoon's i18n implementation): http://cocoon.apache.org/2.1/userdocs/transformers/i18n-transformer.html#Catalogues+%28Dictionaries%29 What we have to do now, is to provide a class to BXE, which does the translation. The best thing would be to do that BXE independent, so one can use that JS class for other things than only in BXE. Here's a prototype (it's full of coding mistakes, but you should get the idea): *** function i18n (catalogLocation, locale) { this.catalog = document.load(catalogLocation + "_" + locale + ".xml"); } i18n.prototype.getText = function (key) { result = this.catalog.query('/catalogue/message[@key = "'.key.'"]'); if(result && result->length > 0) { return result->item(0)->nodeValue; } return key; } *** And in the actual code, we will simply do then: var i18nObj = new i18n("/xml/catalog","en"); text = i18nObj.getText("some text here"); (of course, we need some kind of singleton, so we don't load the xml document again and again, but you get the idea) One problem with the whole i18n stuff is the order of words, eg. in English it's "Add Element" in German "Element hinzufügen" and Element is usually variable, therefore we need some variable substitution... In cocoon, it's solved the following way: the key would be "Add {0}" and you can provide further arguments. In this case, getText would take a second parameter (an array) for variable substitution.. text = i18nObj.getText("Add {0}", array("Elementname")); and this would return "Add Elementname" in english, but "Elementname hinzufügen" in German. Does this make sense? Additionally, we could also add a transformer, which translates whole XML documents with the i18n syntax of cocoon. Not sure, if we really need that in BXE right now, but that should be doable as well. Any other ideas? Or should I go ahead with that approach? chregu -- christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich phone +41 1 240 56 70 | mobile +41 76 561 88 60 | fax +41 1 240 56 71 http://www.bitflux.ch | [email protected] | gnupg-keyid 0x5CE1DECB -- bx-editor-dev mailing list [email protected] http://lists.bitflux.ch/cgi-bin/listinfo/bx-editor-dev