function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vijay Kumar YadavVijay Kumar Yadav 

How to display chatbot content based on the page language

I want to display chatbot dialogs and messages based on the page language. On community if i am selecting a spanish language then in the browser url we are setting language parameter as language = es_US. Is there any way we can read this browser url language parameter from einstein chatbot and based on the language selected on page we can display dialogs and messages in that language.
 
I dont want user to select language option on chat
Prateek Prasoon 25Prateek Prasoon 25
Hey Vijay,

It's possible to read the language parameter from the browser URL in your Einstein Chatbot and display dialogs and messages in the selected language.
Here's how you can do it:

In your community, make sure the language parameter is included in the URL for each language. For example, for Spanish, the URL should look like this: https://yourcommunityurl.com/es_US/yourpage
In your Einstein Chatbot, create separate sets of dialogs and messages for each supported language.
Use the getPageReference() method to get the current page URL in your Apex controller, and then use the getParameters() method to read the language parameter from the URL. For example:
 
String language = ApexPages.currentPage().getParameters().get('language');

Pass the language parameter to your Einstein Chatbot by setting it as a user attribute. For example:
ChatbotUser user = new ChatbotUser();
user.setAttribute('language', language);
ChatbotSession session = ChatbotSession.createChatbotSession(user);

In your Einstein Chatbot, use the getUserAttribute() method to read the language attribute from the user object and display the appropriate set of dialogs and messages. For example:
String language = ChatbotSession.getChatbotSession().getUser().getAttribute('language');
// Use the language value to display the appropriate dialogs and messages

With this approach, the language selected on the community page will be automatically passed to the Einstein Chatbot and used to display the appropriate dialogs and messages.

If you find my answer helpul, please mark it as the best answer. Thanks!