1 define(['commonUtils', 'presentationManager', 'dialogManager'],
  2 	/**
  3      * Set to "backwards compatibility mode" (for pre version 2.0) for LanguageManager.
  4      * 
  5 	 * This function re-adds deprecated and removed functions and
  6      * properties to the CommonUtils instance.
  7      * 
  8      * NOTE that once set to compatibility mode, it cannot be reset to
  9      * non-compatibility mode.
 10      * 
 11      * <p>
 12      * In addition, the following functions of LanguageManager are made accessible
 13      * on the <code>mmir.LanguageManager</code> instance with these additional names
 14      * <ul>
 15      * 	<li> {@link mmir.LanguageManager#getLanguage} as
 16      *          <b><u>getCurrentLanguage() : String</u></b>
 17      *  </li><li>
 18      *  	 {@link mmir.LanguageManager#existsGrammar} as
 19      *          <b><u>existsGrammarForLanguage(String: lang) : Boolean</u></b>
 20      * </li><li>
 21      * 		 {@link mmir.LanguageManager#existsDictionary} as
 22      *          <b><u>existsDictionaryForLanguage(String: lang) : Boolean</u></b>
 23      * </li><li>
 24      * 		 {@link mmir.LanguageManager#existsSpeechConfig} as
 25      *          <b><u>existsSpeakerForLanguage(String: lang) : Boolean</u></b>
 26      * </li><li>
 27      * 		 {@link mmir.LanguageManager#setNextLanguage} as
 28      *          <b><u>cycleLanguages()</u></b>
 29      * </li>
 30      * </ul>
 31      * 
 32      * @param {mmir.LanguageManager} compatibilitySelf
 33      * 			the instance of mmir.LanguageManager to which the compatibility functions etc.
 34      * 			will be attached
 35      * 
 36 	 * 
 37 	 * @class
 38 	 * @name mmir.LanguageManager.setToCompatibilityModeExtension
 39 	 * @static
 40 	 * 
 41 	 * @example
 42 	 * require(['languageManagerCompatibility'], function(setCompatibility){
 43 	 * 		setCompatibility(mmir.LanguageManager);
 44 	 * });
 45 	 * 
 46 	 * @public
 47 	 */
 48 	function(
 49 		commonUtils, presentationManager, dialogManager
 50 ) {
 51 	
 52 		/**
 53          * Set to "backwards compatibility mode" (for pre version 2.0).
 54          * 
 55          * This function re-adds deprecated and removed functions and
 56          * properties to the CommonUtils instance.
 57          * 
 58          * NOTE that once set to compatibility mode, it cannot be reset to
 59          * non-compatibility mode.
 60          * 
 61          * @param {mmir.LanguageManager} compatibilitySelf
 62          * 			the instance of mmir.LanguageManager to which the compatibility functions etc.
 63          * 			will be attached
 64          * 
 65          * @constructs mmir.LanguageManager.setToCompatibilityModeExtension
 66          * 
 67          * @borrows mmir.LanguageManager#getLanguage as
 68          *          this.getCurrentLanguage
 69          * @borrows mmir.LanguageManager#existsGrammar as
 70          *          this.existsGrammarForLanguage
 71          * @borrows mmir.LanguageManager#existsDictionary as
 72          *          this.existsDictionaryForLanguage
 73          * @borrows mmir.LanguageManager#existsSpeechConfig as
 74          *          this.existsSpeakerForLanguage
 75          * @borrows mmir.LanguageManager#setNextLanguage as
 76          *          this.cycleLanguages
 77          */
 78         return setToCompatibilityMode = function(compatibilitySelf) {
 79         	
 80         	/** @scope mmir.LanguageManager.setToCompatibilityModeExtension.prototype *///for jsdoc2
 81         	
 82 //            /**
 83 //             * The instance that holds the extensions for compatibility
 84 //             * mode, which really is the LanguageManager instance.
 85 //             * 
 86 //             * @type mmir.LanguageManager
 87 //             * @private
 88 //             */
 89 //            var compatibilitySelf = this;
 90 
 91             /**
 92              * This function is used to localize the view description
 93              * (ehtml) before they are displayed.
 94              * 
 95              * @function
 96              * @param {String}
 97              *            html The (HTML) string which is to be localized
 98              *            into the currently used language
 99              * @returns {String} The localized (HTML) string
100              * @throws {Error} if {@link mmir.CommonUtils#getTranslationRegExp} is not
101              * 			available (i.e. commonUtils has not been set to compatibility mode)
102              * 
103              * @public
104              * @deprecated used for old template format
105              * 
106              * 
107              * @requires mmir.CommonUtils
108              * @requires requires that CommonUtils is set to
109              *           setToCompatibilityMode:
110              *           {@link mmir.CommonUtils#setToCompatibilityMode}
111              */
112             var translateHTML = function(html) {
113             	
114             	if(commonUtils && !commonUtils.getTranslationRegExp){
115             		throw new Error('No function CommonUtils.getTranslationRegExp(): need to set commonUtils to compatibility mode too!');
116             	}
117             	
118                 var translationRegExp = commonUtils.getTranslationRegExp();
119                 if (html.match(translationRegExp)) {
120                     while (tre = translationRegExp.exec(html)) {
121                         var translated = internalGetText(tre[1]);
122                         html = html.replace(tre[0], translated);
123                     }
124                 }
125                 return html;
126             };
127             compatibilitySelf.translateHTML = translateHTML;
128 
129             /**
130              * 
131              * 
132              * This function changes the application language and, if
133              * requested, renders the current view again, so that the change
134              * of the language is applied to the currently displayed view.
135              * After changing the language (and re-rendering the view) an
136              * event "language_choosen" is raised on the DialogManager.<br>
137              * 
138              * <div class="box important"> <b>Note:</b> Momentarily this
139              * function is used by 'controllers/application.js' to generate
140              * a menu to choose the application language.<br>
141              * This should better be implemented as a partial. </div>
142              * 
143              * @requires mmir.PresentationManager
144              * @requires mmir.DialogManager
145              * 
146              * @function
147              * @param {String}
148              *            newLang The new language which is to be used
149              *            henceforth
150              * @param {Boolean}
151              *            doReRenderView Should the currently displayed view
152              *            be rendered again in the new language?
153              * @returns {String} The translation of the keyword
154              * @public
155              */
156             var changeLanguage = function(newLang, doReRenderView) {
157 
158                 console.debug("[Language] selected " + newLang);// debug
159 
160                 // instance.setLanguage(newLang);
161                 this.setLanguage(newLang);
162 
163                 if (doReRenderView == true) {
164                     presentationManager.reRenderView();
165                 }
166                 dialogManager.raise("language_choosen", newLang);
167             };
168             compatibilitySelf.changeLanguage = changeLanguage;
169 
170             compatibilitySelf.getCurrentLanguage = compatibilitySelf.getLanguage;
171             compatibilitySelf.cycleLanguages = compatibilitySelf.setNextLanguage;
172             
173         };//END: setToCompatibilityMode()
174         
175 });
176