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.
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
-
determineLanguage(){String}
-
Chooses a language for the application.
The language selection is done as follows:
- check if a default language exists
if it does and if both (!) grammar and dictionary exist for this language, return this language - walk through all languages alphabetically
- 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)
- test if a grammar exists for the default language - do not care about dictionaries - if it does, return the default language
- If a language was found (in Step 2.1) return this language
- If still no language is returned take the default language if it has a dictionary
- If a language exists, take it (the first one)
- Take the default language - no matter what
Returns:
Type Description String The determined language - check if a default language exists
-
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 true
if a speech-configuration exists for given language. Otherwisefalse
. -
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 -
getDefaultLanguage(){String}
-
Gets the default language.
Returns:
Type Description String The default language -
getDictionary(){Object}
-
Returns the dictionary of the currently used language.
Returns:
Type Description Object The JSON object for the dictionary of the currently used language -
getLanguage(){String}
-
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 -
getLanguages(){String}
-
Gets an array of all for the translation available languages.
Returns:
Type Description String An array of all for the translation available languages -
getText(textVarName){String}
-
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 -
init(lang){Promise}
-
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 -
setLanguage(){String}
-
Sets a new language, but only, if the new language is different from the current language.
Returns:
Type Description String The (new) current language