]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/dojo/openils/I18N.js
move the translation widget out to openils.widget
[Evergreen.git] / Open-ILS / web / js / dojo / openils / I18N.js
1 /* ---------------------------------------------------------------------------
2  * Copyright (C) 2008  Georgia Public Library Service
3  * Copyright (C) 2008  Equinox Software, Inc
4  * Mike Rylander <miker@esilibrary.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * ---------------------------------------------------------------------------
16  */
17
18 if(!dojo._hasResource["openils.I18N"]) {
19
20     dojo._hasResource["openils.I18N"] = true;
21     dojo.provide("openils.I18N");
22     dojo.require("fieldmapper.dojoData");
23     dojo.require("DojoSRF");
24         dojo.require("dojo.data.ItemFileWriteStore");
25         dojo.require("dijit._Widget");
26         dojo.require("dijit._Templated");
27         dojo.require("dijit.layout.ContentPane");
28         dojo.require("dijit.Dialog");
29         dojo.require("dijit.form.Button");
30         dojo.require("dijit.form.TextBox");
31         dojo.require("dijit.form.ComboBox");
32
33
34     dojo.declare('openils.I18N', null, {});
35
36     openils.I18N.BaseLocales = {
37                 "en" : "English",
38                 "en_us" : "US English",
39                 "en_ca" : "Canadian English",
40                 "es" : "Spanish",
41                 "es_us" : "US Spanish",
42                 "fr" : "French",
43                 "fr_ca" : "Canadian French"
44         };
45
46         openils.I18N.localeStore = new dojo.data.ItemFileWriteStore( { data : {identifier : 'locale', label : 'label', items : [] } } );
47
48         for (var i in openils.I18N.BaseLocales) {
49                 openils.I18N.localeStore.newItem({ locale : i, label : openils.I18N.BaseLocales[i] });
50         }
51
52         openils.I18N.getTranslations = function ( obj /* Fieldmapper object */,  field /* Field to translate */, locale /* optional locale */) {
53                 var classname = obj.classname;
54
55                 // XXX need to derive identity field from IDL...
56                 var ident_field = fieldmapper[classname].Identifier || 'id';
57                 var ident_value = obj[ident_field]();
58
59                 var fielder_args = { query : { fq_field : classname + '.' + field, identity_value : ident_value } };
60                 if (locale) fielder_args.translation = locale;
61
62                 var hash_list = fieldmapper.standardRequest( [ 'open-ils.fielder', 'open-ils.fielder.i18n.atomic'], [ fielder_args ] );
63                 var obj_list = dojo.map( hash_list, function (t) { return new fieldmapper.i18n().fromHash( t ) } );
64
65                 if (locale) return obj_list[0];
66                 return obj_list;
67         }
68
69 }
70
71