Skip to main content

Life-Hack #8: Multilingual Bot

This Life-Hack will allow you to create a multilingual bot with a language change on pressing START.

Life-Hack - involves the use of existing functionality in non-obvious and rather ingenious ways, creating functions in your bot, that were not originally built by the constructors’s developers.

In this section, we publish various options and turnkey solutions for what can be created using the capabilities that are already available in the @MenuBuilderBot constructor. When creating such manuals, it is assumed that you, to one degree or another, are already familiar with the basic functions of the constructor and the basic mechanisms for working with it. If in the process of studying the presented material your basic knowledge is not enough, we advise you to study the basics before continuing.

❖ The easiest way (not Life-Hack yet)

The easiest and FREE way to create a multilingual menu is to add the required number of buttons in the Main Menu of the bot - one for each language - and within these buttons create a menu in the corresponding language. Done!

And now, based on the described mechanics, a version for those who want to create something more interesting...

❖ Acquiring of functionality

All functionality is purchased IN YOUR BOT, for this go to your bot:
☞ 🔐Admin | 🧩Extensions

IMPORTANT: The purchase of functionality for the bot is available only to the Creator (owner) of the bot. Admins CANNOT buy functionality!


You will need:

1. Variables - 1 piece
☞ 🔐Admin | 🧩Extensions | 📂Variables

2. Actions - 4 pieces
☞ 🔐Admin | 🧩Extensions | 📂Actions

3. (Optional) Token of Functions Package
☞ 🔐Admin | 🧩Extensions | 📂Actions

4. Conditions for buttons
☞ 🔐Admin | 🧩Extensions | 📂Buttons

5. Macros and expressions for buttons
☞ 🔐Admin | 🧩Extensions | 📂Buttons

6. Create your own navigation buttons
☞ 🔐Admin | 🧩Extensions | 📂Customization

❖ Creating a bilingual menu

How it works

Two buttons with languages names are crated In the Main Menu - each of them, once pressed, will assign a different number to a variable. The number assigned by the button is a sort of identifier for the selected language. The System Navigation will be hidden in the bot, and the commands of the custom navigation buttons, containing macros with the identifier of the selected language, will move the user inside the corresponding menus. The change of the language is done by pressing START.

WARNING: It must be emphasized that the method described below, allows the user to change the language ONLY for the menu you have created. However, the language of the system buttons and messages, shown to the user in certain scenarios of using the bot, will keep the language that was chosen by the owner of the bot, for himself as the System one. Therefore, for multilingual bots, the system language should be the language that is more or less accessible and understandable to most of the bot's users, regardless of their preferences - most often it is English or Russian.

1. Create variables

Variable (Numeric) - Go to your bot:
☞ 🔐Admin | 🗄Variables | 📙Numeric | ➕Create Variable
Variable name: lng, (you can use your own).

2. Create Language Buttons

To demonstrate the approach, we will manually create both of the menu buttons for different languages. When the sequence of creation and the mechanism of their work become clear to you, it is better to create one branch completely and then copy it using the copy function (described below).

2.1 English menu branch

In the Main Menu, go to the "Button Editor" and create a button for the English menu branch with a command and an Action:

● Name: English
● Command: /home0
Command Option: Move by Command
● Pre-Action: Numbers
Variable: lng
Operation Type: Set Value
Value: 0
Condition: {%lng% != 0}

Going to the "Post Editor" add a message to the button:
● Button message: "This is English menu".

2.2 Russian menu branch

In the Main Menu, go to the "Button Editor" and create a button for the Russian menu branch with a command and an Action:

● Name: Russian
● Command:  /home1
Command Option: Move by Command
● Pre-Action: Numbers
Variable: lng
Operation Type: Set Value
Value: 1
Condition: {%lng% != 1}

Going to the "Post Editor" add a message to the button:
● Button message: "This is a Russian menu".

3. Create navigation

3.1 Disabling system navigation

Before we can create our own navigation, we need to disable the system navigation buttons.
To disable go to:
☞ 🔐Admin | 🎚Bot Customization | Hide Navigation

3.2 Navigation in the English menu

After disabling the system, we need to create our own navigation in each of the menu sections. We return to the English menu with the "Button Editor" enabled. For clarity and demonstration of creating custom navigation, let's create Buttons inside the English menu.
● Name: Button 1
● Name: Button 2

These will be the "Main Menu" buttons for the English branch of your bot.

Inside the "Button 1" button, create a sub-menu with two buttons:
● Name: Button 1.1
● Name: Main Menu

The button with the name "Main Menu" when pressed should transfer the user to the Main Menu - of the English branch. Add Action of Commands to it:

● Pre-Action: Command
Command: /home%lng%

As you can see, there is a language variable's (%lng%) macros in the command. When this command is processed, the macros will be replaced by the value from this variable, which corresponds to the language selected by the user.

This macros is used to demonstrate the approach and facilitate copying. If you do not use Copy in your Bot, then you can use the language's identifier directly in the command. Since this button is intended to navigate the English menu, the command without a macro will look like this:
/home0
Zero - "0" is the default value of a numeric variable and in our bot it corresponds to the English language.

A sub-menu for the button "Button2" is created same way if need be.

3.3 Navigation in the Russian menu

Navigation can be created manually, but if there are a lot of buttons, then copying is better.

3.3.1 Copy setting (optional)

To enable go to:
☞ 🔐Admin | ⚙️Bot Settings | Button "Copy"

If you do not have "Additional Tokens of Functions" (this feature does not work with monthly renewable tokens), then this setting can be left disabled.

If you have enabled copying in your Bot, then copy that newly created navigation button of the English menu. And without leaving the Buttons Editor, go to the Russian menu. We insert the navigation button inside the "Button 1".

Change the name of the inserted button to: "Main Menu Ru". Action of Commands once copied remains the same, since the value of the variable %lng% for the user in the Russian menu branch will correspond to the Russian language.

As a matter of fact, the language variable macros in the command, was used for the convenience of copying the navigation buttons.

If you did not use copying, then assign Action to Commands, the command:
/home1
Which will correspond to the Russian menu.

❖ Switching menu languages

Switching with START buttons

In the bilingual bot implementation approach described above, the user will need to restart the bot with the START command to switch the language. This will take him to the System's "Main Menu" which contains language selection buttons.

You may have your own vision on the interface design of changing the language, so we will describe some alternative methods that we know.

Switching by commands in the Main Menu

If you do not want to show the language selection buttons after pressing START, but, for example, prefer to provide your user a message with commands for this, then you can specify those commands that you have assigned to the language buttons (in the example above, these are /home0 and /home1) in the "Message for START" and allow users to go to the appropriate menu - by pressing commands. Don't forget to hide language menu buttons using:

Invisible Buttons and Messages
To add feature, in your bot go to:
☞ 🔐Admin | 🧩Extensions | 📂Buttons

Switching by inline buttons

For obvious reasons, you may not like the look of commands with numbers instead of languages themselves. In this case, you can also create a "Message for Start" with a choice of language, but instead of showing commands directly in the text of the message, you can use inline buttons in command mode. Buttons can be assigned with any name, and commands will not be visible.

Names of languages ​​in commands

If none of the above methods suits you and you still want to switch languages ​​with commands, in this case the language can be saved in a text variable - for example, in the form: "en" and "ru" abbreviations. In this case, the commands for switching languages ​​will look better.

PRECAUTION: Using text variables for this kind of mechanic is not the most rational idea from the optimization point of view, but it does solve the issue with the appearance of the language selection commands.

Dedicated settings menu with language switching

Switching languages ​​in the Main Menu after pressing START is essential for new users - so you can't go without it completely. However, in order not to force your users to restart the bot to change the language (some users finding such a way to switch languages as counterintuitive, in some cases), you can duplicate it in any section of your bot's menu - where user can easily find it. To do this, in the desired section, you can create a "Language" button and place buttons that are identical in functionality to the navigation buttons with Action of Commands - for each language (obviously using a macro in this case is impossible and the language change command will need to be specified without referring to a variable), or a message with commands, same as inline buttons that described above.