Source: tools/extensions/LanguageManagerV1Compatibility.js

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