Skip to main content

Configuration

When importing the languageDetector module, you can pass an object with settings to it. All fields of this object are optional.

When to detect language

FieldTypeBy defaultDescription
detectorModestringdefaultLanguage detection mode:
  • first: the bot detects the language only in the first request. If it has fewer than two words, the bot detects the language in the second request.
  • default: the bot detects the language in the first and second requests. If the first request contains fewer than two words, the bot detects the language in the second and third requests.
  • every: the bot detects the language in each request. If the first request contains fewer than two words, the bot does not detect the language in it.
firstShortQueryCheckbooleanfalseDetect the language in the first request, even if it contains fewer than two words.
detectorStatesarray<string>List of states that always require language detection when the bot transitions to them, regardless of detectorMode.
noDetectorStatesarray<string>List of states that do not require language detection when the bot transitions to them, regardless of detectorMode.

Logic for language selection

FieldTypeBy defaultDescription
defaultLanguagestring

Default language. Specify the ISO code. If the bot cannot detect the language, then the bot uses the default language.

You may not specify defaultLanguage only if you write the value in $session.language in the startup state yourself.

previousLanguagePreferencebooleanfalseWrite the language of the previous request to $session.language, if the bot cannot detect the language. If the value is false, the bot uses defaultLanguage.
targetLanguagesarray<string>List of ISO codes of target languages:
  1. The bot detects the language.
  2. If the list is specified and the language is not in the list, then the bot selects a related language using sameGroupLanguageReplacement.
sameGroupLanguageReplacementbooleantrue

Replace the received language with a related one if the received language belongs to the same group as one of the languages in targetLanguages. If two or more languages in targetLanguages belong to this group, the bot will not replace the language.

Language groups are specified in languageDetector/languageGroups.yaml

Detection methods settings

FieldTypeBy defaultDescription
confidenceThresholdfloat1.5

Threshold value when detecting language using Detect Language API. If the confidence value is less than the threshold, the bot considers that the language could not be detected.

To use the API, add a key to the project.

onlyCailaMethodbooleanfalseUse only the $caila.detectLanguage method to detect the language.

Additional states

FieldTypeDescription
stateWithLanguageQuestionstring

State with a question of which language to speak. If the bot cannot detect the language, it will transition to this state. In this state, you must assign the ISO language code to the $session.language variable.

If the bot transitions to this state, it sets the value of $session.noDetectLanguage to true. As a result, for all subsequent requests, the bot will not detect the language. The exception is the states from detectorStates.

You can see the code for such a state in the example.

stateForChangingLanguagestring

State with the intent to change the language. In this state, you must assign the ISO language code to the $session.language variable.

If the bot transitions to this state, it sets the value of $session.noDetectLanguage to true. As a result, for all subsequent requests, the bot will not detect the language. The exception is the states from detectorStates.

You can see the code for such a state in the example.