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) |