1 /**
  2  * 
  3  * All content on this website (including text, images, source
  4  * code and any other original works), unless otherwise noted,
  5  * is licensed under a Creative Commons License.
  6  * 
  7  * http://creativecommons.org/licenses/by-nc-sa/2.5/
  8  * 
  9  * Copyright (C) 2004-2007 Open-Xchange, Inc.
 10  * Mail: info@open-xchange.com 
 11  * 
 12  * @author Viktor Pracht <viktor.pracht@open-xchange.com>
 13  * 
 14  */
 15 
 16 register("OX_Configuration_Loaded_Complete", function() {
 17     var modules = configGetKey("availableModules");
 18     if (!modules) return;
 19     for (var i in modules) loadModule(modules[i]);
 20 });
 21 
 22   //////////////////////////////////////////
 23  //   Global names defined for plugins   //
 24 //////////////////////////////////////////
 25 
 26 /**
 27  * Translates a string.
 28  * @function
 29  * @name _
 30  * @param {String} text The original English text to translate.
 31  * @type I18nString
 32  * @return The translated text.
 33  */
 34 
 35 /**
 36  * Translates a string.
 37  * @function
 38  * @name gettext
 39  * @param {String} text The original English text to translate.
 40  * @type I18nString
 41  * @return The translated text.
 42  */
 43 
 44 /**
 45  * Translates a string with context
 46  * @function
 47  * @name pgettext
 48  * @param {String} context A context to differentiate multiple identical texts
 49  * with different translations.
 50  * @param {String} text The original English text to translate.
 51  * @type I18nString
 52  * @return The translated text.
 53  */
 54 
 55 /**
 56  * Translates a string containing numbers.
 57  * @function
 58  * @name ngettext
 59  * @param {String} singular The original English text for the singular form.
 60  * @param {String} plural The original English text for the plural form.
 61  * @param {Number} n The number which determines which text form is used.
 62  * @type I18nString
 63  * @return The translated text.
 64  */
 65 
 66 /**
 67  * Translates a string containing numbers with context.
 68  * @function
 69  * @name npgettext
 70  * @param {String} context A context to differentiate multiple identical texts
 71  * with different translations.
 72  * @param {String} singular The original English text for the singular form.
 73  * @param {String} plural The original English text for the plural form.
 74  * @param {Number} n The number which determines which text form is used.
 75  * @type I18nString
 76  * @return The translated text.
 77  */
 78 
 79 /**
 80  * Converts a string to I18nString without translation.
 81  * @function
 82  * @name noI18n
 83  * @param {String} text The text to conevrt.
 84  * @type I18nString
 85  * @return The untranslated text as I18nString.
 86  */
 87 
 88 //////////////////////////////////////////
 89 
 90 /**
 91  * Loads a module at runtime.
 92  * Loading a module which is already (being) loaded has no effect. 
 93  * The register.js file from the module's directory is converted to the body of
 94  * a function and that function is called without parameters.
 95  * The file is downloaded asynchronously.
 96  * @param {String} name The name of the module to load.
 97  */
 98 function loadModule(name) {
 99     if (name in loadedModules) return;
100     loadedModules[name] = true;
101     (new JSON()).get("plugins/" + name + "/register.js", null,
102         function(js) {
103             if (name.substring(0, 17) == "com.openexchange.")
104                 name = "";
105             else
106                 bindtextdomain(name, "plugins/" + name + "/lang/%s.po");
107             (Function("_", "gettext", "pgettext", "ngettext", "npgettext",
108                 "noI18n", js))(gt, gt, pgt, ngt, npgt, noI18n);
109 
110             /**
111              * @class A translated string. All text strings displayed to
112              * the user must be instances of this class instead of the default
113              * <code>String</code> class. All translation functions return
114              * instances of this class. When the UI language changes,
115              * <code>I18nString</code> objects are retranslated automatically.
116              * Setting the global variable <code>debug</code> to
117              * <code>true</code> will enable console warnings when strings are
118              * used where <code>I18nString</code> is expected.
119              * @name I18nString
120              */
121             function I18nString(f) { return f.toString = f; }
122 
123             function gt(text) {
124                 return I18nString(function() {
125                     return dpgettext(name, "", text);
126                 });
127             }
128             function pgt(context, text) {
129                 return I18nString(function() {
130                     return dpgettext(name, context, text);
131                 });
132             }
133             function ngt(singular, plural, n) {
134                 return I18nString(function() {
135                     return dnpgettext(name, "", singular, plural, n);
136                 });
137             }
138             function npgt(context, singular, plural, n) {
139                 return I18nString(function() {
140                     return dnpgettext(name, context, singular, plural, n);
141                 });
142             }
143             function noI18n(text) {
144                 return I18nString(function() { return text; });
145             }
146         },
147         function(result, status) {
148             delete loadedModules[name];
149             return status == 404;
150         }, true);
151 };
152 
153 // TODO: fill during initialization of modules.
154 var loadedModules = {
155     calendar: true,
156     contacts: true,
157     folder: true,
158     infostore: true,
159     interfaces: true,
160     mail: true,
161     mailaccount: true,
162     portal: true,
163     tasks: true,
164     themes: true    
165 };
166