Developers

Integration Options

Language Detection Overview

The Search API and SDK provide, respectively, an endpoint and a method that make it possible to detect the language of a user query. If your Inbenta solution includes multiple Inbenta instances in different languages, this allows you to suggest which one of these instances appears to be the best suited to provide results for this content. If you only have one instance, that instance obviously becomes the best and only option.

Language detection at Inbenta only provides detection of the languages within your instances. If you need other languages to be detected as well, you may need to use another language detection system from a third-party provider.

Integration Options

There are several ways you can use the language detector functionality. The diagram below shows the two solutions that are more frequently used by Inbenta clients:

  • Option one (left, recommended by Inbenta), does the search first. If it does not get results, it checks the languages of the user question. If the question is in the expected language, the flow proceeds with the "no results" process. 
  • Option two (right) checks the language of all incoming user questions first, then decides to do the search or not, depending on the result.

There are two factors to consider when you decide to adopt one solution over the other:

  • the number of API requests (and thus the cost of the solution), and
  • the number of user questions that you receive in an unexpected language.
 
Important

Take into account that if you use the first option, all user question, including the ones in unexpected languages, are registered in the system as user questions.

The solution that performs less requests to the API, and thus is more cost effective, depends on the number of user questions that you receive that are in an unexpected language. This is why Inbenta recommends the first option: if you get very few of these questions, then the second option is very expensive for minimal gains. It only becomes cheaper if you typically receive roughly a third or more of your user questions in an unexpected language.

Integration when unexpected language is detected

Option 1: Redirect the user to the proper site (recommended by Inbenta)

Even if the search returns an instance of the language, a proper implementation shows a specific message to users. This message redirects them to the Help Center in the relevant language. That is particularly recommended for clients who use the JS Client.

You can even set this message as a parameter and bypass the user question. This way, the implementation in the other language automatically shows the results of the user question.

Option 2: Automatically redirect the user question to another instance

If you have an instance in the language that was detected, you can use the API to redirect the user question automatically to this other instance, as shown in the diagram below. This may delay the request, especially if there is no prior authorization to the other instance.

 
Note

In the same way the results of a user question are cached, you must also cache the language received for each user question to reduce the number of requests to the API.

You can do the same implementation using the JS Client. However, this means that you must initialize a JS Client for each instance on the same site. Make sure to handle the display and tracking of these different instances accordingly.

Example

The following example shows how to redirect the user query to a specific French page when the language detected in the query is French. If it is not in French, the normal submit process specified by the form happens:

// Suppose that you have a form with id 'form' and an input with the query with id 'query'
var form = document.getElementById('form');
form.addEventListener('submit', function (event) {
    event.preventDefault()
    var query = document.getElementById('query').value;
    sdk.client.detectLanguage(query).then(function (detection) {
        // Redirect to the specific page if language is detected as French
        if (detection.language === 'fr') {
            location.href = 'https://www.inbenta.com/fr/search/?query=' + encodeURI(query);
        // Otherwise submit the form as normal
        } else {
            form.submit();
        }
    })
})