randydev commited on
Commit
98719e5
·
verified ·
1 Parent(s): dc9f7f9

Update chatbot/plugins/keyboards.py

Browse files
Files changed (1) hide show
  1. chatbot/plugins/keyboards.py +26 -21
chatbot/plugins/keyboards.py CHANGED
@@ -1,28 +1,33 @@
1
  from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
2
  from chatbot.plugins.languages import LANGUAGES
3
 
4
- def get_language_keyboard():
 
 
 
 
 
 
5
  keyboard = []
 
6
 
7
- # Row 1: English, Indonesian
8
- keyboard.append([
9
- InlineKeyboardButton("English", callback_data="lang_en"),
10
- InlineKeyboardButton("Indonesian", callback_data="lang_id")
11
- ])
12
-
13
- # Row 2: Spanish
14
- keyboard.append([
15
- InlineKeyboardButton("Spanish", callback_data="lang_es")
16
- ])
17
-
18
- # Row 3: French, German, Japanese
19
- keyboard.append([
20
- InlineKeyboardButton("French", callback_data="lang_fr"),
21
- InlineKeyboardButton("German", callback_data="lang_de"),
22
- InlineKeyboardButton("Japanese", callback_data="lang_jp")
23
- ])
24
- keyboard.append([
25
- InlineKeyboardButton("Cancel", callback_data="cancel")
26
- ])
27
 
28
  return InlineKeyboardMarkup(keyboard)
 
1
  from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
2
  from chatbot.plugins.languages import LANGUAGES
3
 
4
+ def get_language_keyboard(buttons_per_row=2):
5
+ """
6
+ Generates an InlineKeyboardMarkup for language selection.
7
+
8
+ :param buttons_per_row: Number of language buttons per row.
9
+ :return: InlineKeyboardMarkup object.
10
+ """
11
  keyboard = []
12
+ buttons = []
13
 
14
+ for index, lang in enumerate(LANGUAGES, start=1):
15
+ buttons.append(
16
+ InlineKeyboardButton(
17
+ text=lang['name'],
18
+ callback_data=f"lang_{lang['code']}"
19
+ )
20
+ )
21
+
22
+ if index % buttons_per_row == 0:
23
+ keyboard.append(buttons)
24
+ buttons = []
25
+
26
+ # Append any remaining buttons
27
+ if buttons:
28
+ keyboard.append(buttons)
29
+
30
+ # Add the Cancel button on a new row
31
+ keyboard.append([InlineKeyboardButton("Cancel", callback_data="cancel")])
 
 
32
 
33
  return InlineKeyboardMarkup(keyboard)