Class: LanguageManager

mmir. LanguageManager

new mmir.LanguageManager()

A class for managing the language of the application.
It's purpose is to load the controllers and their views / partials and provide functions to find controllers or perform actions or helper-actions. This "class" is structured as a singleton - so that only one instance is in use.

Requires

  • module:mmir.Resources
  • module:mmir.CommonUtils
  • module:mmir.SemanticInterpreter

Members

_requestGrammar

Methods

Chooses a language for the application.

The language selection is done as follows:

  1. check if a default language exists
    if it does and if both (!) grammar and dictionary exist for this language, return this language
  2. walk through all languages alphabetically
    1. if for a language both (!) grammar and dictionary exist, return this language memorize the first language with a grammar (do not care, if a dictionary exists)
  3. test if a grammar exists for the default language - do not care about dictionaries - if it does, return the default language
  4. If a language was found (in Step 2.1) return this language
  5. If still no language is returned take the default language if it has a dictionary
  6. If a language exists, take it (the first one)
  7. Take the default language - no matter what
Returns:
Type Description
String The determined language

existsDictionary(Language){Boolean}

If a dictionary exists for the given language, 'true' is returned. Else the method returns 'false'.
Name Type Description
Language String String, i.e.: en, de
Returns:
Type Description
Boolean True if a dictionary exists for given language.

existsGrammar(lang, grammarType){Boolean|"source"|"bin"}

If a JSON grammar file exists for the given language, 'true' is returned. Else the method returns 'false'.
Name Type Description
lang String Language String, i.e.: en, de
grammarType "source" | "bin" optional OPTIONAL only check grammar specifications ("source", i.e. JSON grammar), or executable grammar ("bin", i.e. compiled grammar) existence
Returns:
Type Description
Boolean | "source" | "bin" TRUE if a grammar exists for given language (and if grammarType was given, when the existing grammar matches the grammar type)

existsSpeechConfig(lang){Boolean}

If a speech-configuration (file) exists for the given language.
Name Type Description
lang String the language for which existence of the configuration should be checked, e.g. en, de
Returns:
Type Description
Boolean trueif a speech-configuration exists for given language. Otherwise false.

fixLang(providerName, langCode){String}

HELPER for dealing with specific language / country code quirks of speech services: Get the language code for a specific ASR or TTS service, that is if the service requires some specific codes/transformations, then the transformed code is retruned by this function (otherwise the unchanged langCode is returned).
Name Type Description
providerName String corrections for: "nuance" | "mary"
langCode String the original language / country code
Returns:
Type Description
String the (possibly "fixed") language-setting/-code
Gets the default language.
Returns:
Type Description
String The default language
Returns the dictionary of the currently used language.
Returns:
Type Description
Object The JSON object for the dictionary of the currently used language
Gets the language currently used for the translation.
Returns:
Type Description
String The current language

getLanguageConfig(pluginId, feature, separator){String}

Get the language code setting for a specific plugin. Returns the default setting, if no specific setting for the specified plugin was defined.
Name Type Description
pluginId String
feature String | Array.<String> optional OPTIONAL dot-separate path String or "path Array" This parameter may be omitted, if no separator parameter is used. DEFAULT: "language" (the language feature)
separator String optional OPTIONAL the speparator-string that should be used for separating the country-part and the language-part of the code
Returns:
Type Description
String the language-setting/-code
Gets an array of all for the translation available languages.
Returns:
Type Description
String An array of all for the translation available languages
Looks up a keyword in the current dictionary and returns the translation.
Name Type Description
textVarName String The keyword which is to be translated
Returns:
Type Description
String The translation of the keyword
Name Type Description
lang String optional OPTIONAL a language code for setting the current language and selecting the corresponding language resources
Returns:
Type Description
Promise a deferred promise that gets resolved when the language manager is initialized
Sets a new language, but only, if the new language is different from the current language.
Returns:
Type Description
String The (new) current language