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.Constants
- module:mmir.CommonUtils
- module:mmir.SemanticInterpreter
Classes
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:
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:
if a dictionary exists for given language.
-
existsGrammar(Language){Boolean}
-
If a JSON grammar file exists for the given language, 'true' is returned. Else the method returns 'false'.
Name Type Description Language
String String, i.e.: en, de Returns:
if a grammar exists for given language.
-
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:
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:
(possibly "fixed") language-setting/-code
-
getDefaultLanguage(){String}
-
Gets the default language.
Returns:
default language
-
getDictionary(){Object}
-
Returns the dictionary of the currently used language.
Returns:
JSON object for the dictionary of the currently used language
-
getLanguage(){String}
-
Gets the language currently used for the translation.
Returns:
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:
language-setting/-code
-
getLanguages(){String}
-
Gets an array of all for the translation available languages.
Returns:
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:
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:
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:
(new) current language