File size: 982 Bytes
7ae18de
 
 
98719e5
 
 
 
 
 
 
7ae18de
98719e5
a10a73e
98719e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a10a73e
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from chatbot.plugins.languages import LANGUAGES

def get_language_keyboard(buttons_per_row=2):
    """
    Generates an InlineKeyboardMarkup for language selection.
    
    :param buttons_per_row: Number of language buttons per row.
    :return: InlineKeyboardMarkup object.
    """
    keyboard = []
    buttons = []

    for index, lang in enumerate(LANGUAGES, start=1):
        buttons.append(
            InlineKeyboardButton(
                text=lang['name'], 
                callback_data=f"lang_{lang['code']}"
            )
        )
        
        if index % buttons_per_row == 0:
            keyboard.append(buttons)
            buttons = []
    
    # Append any remaining buttons
    if buttons:
        keyboard.append(buttons)
    
    # Add the Cancel button on a new row
    keyboard.append([InlineKeyboardButton("Cancel", callback_data="cancel")])

    return InlineKeyboardMarkup(keyboard)