From 80e9b7c6ed9393ce0ffd4c414e817a32d9569069 Mon Sep 17 00:00:00 2001 From: miker Date: Wed, 16 Apr 2008 00:50:26 +0000 Subject: [PATCH 1/1] backend i18n dojo wrapper git-svn-id: svn://svn.open-ils.org/ILS/trunk@9366 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/js/dojo/openils/I18N.js | 63 ++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Open-ILS/web/js/dojo/openils/I18N.js diff --git a/Open-ILS/web/js/dojo/openils/I18N.js b/Open-ILS/web/js/dojo/openils/I18N.js new file mode 100644 index 0000000000..4d7ce0d111 --- /dev/null +++ b/Open-ILS/web/js/dojo/openils/I18N.js @@ -0,0 +1,63 @@ +/* --------------------------------------------------------------------------- + * Copyright (C) 2008 Georgia Public Library Service + * Copyright (C) 2008 Equinox Software, Inc + * Mike Rylander + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * --------------------------------------------------------------------------- + */ + +if(!dojo._hasResource["openils.I18N"]) { + + dojo._hasResource["openils.I18N"] = true; + dojo.provide("openils.I18N"); + dojo.require("fieldmapper.dojoData"); + dojo.require("dojo.data.ItemFileWriteStore"); + + dojo.declare('openils.I18N', null, {}); + + openils.I18N.BaseLocales = { + "en" : "English", + "en_us" : "US English", + "en_ca" : "Canadian English", + "es" : "Spanish", + "es_us" : "US Spanish", + "fr" : "French", + "fr_ca" : "Canadian French" + }; + + openils.I18N.localeStore = new dojo.data.ItemFileWriteStore( { data : {identifier : 'locale', label : 'label', items : [] } } ); + + for (var i in openils.I18N.BaseLocales) { + openils.I18N.localeStore.newItem({ locale : i, label : openils.I18N.BaseLocales[i] }); + } + + openils.I18N.getTranslations = function ( obj /* Fieldmapper object */, field /* Field to translate */, locale /* optional locale */) { + var classname = obj.classname; + + // XXX need to derive identity field from IDL... + var ident_field = fieldmapper[classname].Identifier || 'id'; + var ident_value = obj[ident_field](); + + var fielder_args = { query : { fq_field : classname + '.' + field, identity_value : ident_value } }; + if (locale) fielder_args.translation = locale; + + var hash_list = fieldmapper.standardRequest( [ 'open-ils.fielder', 'open-ils.fielder.i18n.atomic'], [ fielder_args ] ); + var obj_list = dojo.map( hash_list, function (t) { return new fieldmapper.i18n().fromHash( t ) } ); + + if (locale) return obj_list[0]; + return obj_list; + } + + //dojo.declare('openils.I18N.TranslationInput', [dijit.form.DropDownButton], { }); +} + + -- 2.43.2