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
Methods
-
async,protected_requestGrammar(lang){String}
-
Request grammar for the provided language. If there is no grammar available for the requested language, no new grammar is set. A grammar is available, if at least one of the following is true for the requested language
- there exists a JSON grammar file (with correct name and at the correct location)
- there exists a compiled JavaScript grammar file (with correct name and at the correct location)
Name Type Description langString The language of the grammar which should be loaded. Returns:
Type Description String The current grammar language -
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(lang){Boolean}
-
If a dictionary exists for the given language, true is returned. Else the method returns false.
Name Type Description langString the Language String, e.g. "en", "de" Returns:
Type Description Boolean True if a dictionary exists for given language. -
existsGrammar(lang, grammarType){Boolean}
-
Checks if either a JSON grammar file or a compiled grammar exists for the given language.
Name Type Description langString Language String or grammar ID, e.g. "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 TRUE if a grammar exists for given language (and if grammarType was given, the existing grammar must also match the given grammar type) -
existsSpeechConfig(lang){Boolean}
-
If a speech-configuration (file) exists for the given language.
Name Type Description langString 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. 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 providerNameString corrections for: "nuance" | "mary" langCodeString 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 pluginIdString featureString | Array.<String> optional OPTIONAL dot-separate path String or "path Array" This parameter may be omitted, if no separatorparameter is used. DEFAULT: "language" (the language feature)separatorString 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 -
getSpeechConfig(){Object}
-
Returns the speech configuration (for ASR/TTS) of the currently used language.
Returns:
Type Description Object The JSON object for the speech-configuration of the currently used language -
getText(textVarName){String}
-
Translates a keyword using the current dictionary and returns the translation.
Name Type Description textVarNameString The keyword which should be looked up Returns:
Type Description String the translation of the keyword -
init(lang){Promise}
-
Name Type Description langString 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(lang, doNotLoadResources){String}
-
Function to set a new language, but only if the new language is different from the current language.
Name Type Description langString the new language code doNotLoadResourcesBoolean optional OPTIONAL if omitted or TRUTHY will only change the current language, but will not try to load language resources (e.g. dictionary, speech configuration, and grammar). If falsewill force (re-)loading the language resources, even iflangis the same as the current language.Returns:
Type Description String The (new) current language