From 513539df068b5a53b61d8ee6af7c78af661b3b94 Mon Sep 17 00:00:00 2001 From: PyMaster <59120866+pystorage@users.noreply.github.com> Date: Sat, 15 Jan 2022 21:55:59 +0300 Subject: [PATCH] Add files via upload --- README.md | 46 ++++++++++++++++++++++++++++++++++- pykeyboard/__init__.py | 2 +- pykeyboard/inline_keyboard.py | 36 +++++++++++++++++++++++++++ setup.py | 2 +- 4 files changed, 83 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6144bc2..c6e26b5 100644 --- a/README.md +++ b/README.md @@ -23,14 +23,16 @@ - [Pagination 9 pages](#pagination-9-pages) - [Pagination 100 pages](#pagination-100-pages) - [Pagination 150 pages and buttons](#pagination-150-pages-and-buttons) + - [Languages inline keyboard](#languages-inline-keyboard) - [Reply Keyboard](#reply-keyboard) - [Reply Keyboard add buttons](#reply-keyboard-add-buttons) - [Reply Keyboard row buttons](#reply-keyboard-row-buttons) # What's new? -- Added a new method to InlineKeyboard for working with pagination. The InlinePaginationKeyboard class will be removed in a future version. +- Added a new method to InlineKeyboard for working with pagination. The InlinePaginationKeyboard class will be removed in a future version. - Overriding the KeyboardButton, ReplyKeyboardRemove, ForceReply, InlineKeyboardButton methods in ReplyButton, ReplyKeyboardRemove, ForceReply, InlineButton. +- Added new method InlineKeyboard. To send language selection keyboard. # Installation @@ -190,6 +192,48 @@ keyboard.row(

pagination_keyboard_150

+### Languages inline keyboard + +```python +from pykeyboard import InlineKeyboard +``` + +#### Parameters: + +- callback_pattern (string) - use of the `{locale}` pattern is required +- locales (string | list) - list of language codes + - be_BY - Belarusian + - de_DE - German + - zh_CN - Chinese + - en_US - English + - fr_FR - French + - id_ID - Indonesian + - it_IT - Italian + - ko_KR - Korean + - tr_TR - Turkish + - ru_RU - Russian + - es_ES - Spanish + - uk_UA - Ukrainian + - uz_UZ - Uzbek +- row_width (integer, default 2) +

P.S. To add new languages, write to me in @PyMaster telegram.

+ +#### Code + +```python +from pykeyboard import InlineKeyboard + + +keyboard = InlineKeyboard(row_width=3) +keyboard.languages( + 'languages:{locale}', ['en_US', 'ru_RU', 'id_ID'], 2 +) +``` + +#### Result + +

languages_keyboard

+ ## Reply Keyboard ```python diff --git a/pykeyboard/__init__.py b/pykeyboard/__init__.py index 0eb7c21..2d4799d 100644 --- a/pykeyboard/__init__.py +++ b/pykeyboard/__init__.py @@ -1,5 +1,5 @@ __title__ = 'pykeyboard' -__version__ = '0.1.3' +__version__ = '0.1.4' __author__ = 'PyMaster' __license__ = 'MIT License' __copyright__ = 'Copyright 2020-2022 PyMaster' diff --git a/pykeyboard/inline_keyboard.py b/pykeyboard/inline_keyboard.py index 0a872b7..e47b185 100644 --- a/pykeyboard/inline_keyboard.py +++ b/pykeyboard/inline_keyboard.py @@ -1,4 +1,6 @@ +from pyrogram.emoji import * from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton +from typing import List, Union class InlineKeyboard(InlineKeyboardMarkup): @@ -7,6 +9,23 @@ class InlineKeyboard(InlineKeyboardMarkup): _SYMBOL_CURRENT_PAGE = '· {} ·' _SYMBOL_NEXT_PAGE = '{} ›' _SYMBOL_LAST_PAGE = '{} »' + _LOCALES = { + 'be_BY': f'{FLAG_BELARUS} Беларуская', # Belarusian - Belarus + 'de_DE': f'{FLAG_GERMANY} Deutsch', # German - Germany + 'zh_CN': f'{FLAG_CHINA} 中文', # Chinese - China + # English - United States + 'en_US': f'{FLAG_UNITED_KINGDOM} English', + 'fr_FR': f'{FLAG_FRANCE} Français', # French - France + # Indonesian - Indonesia + 'id_ID': f'{FLAG_INDONESIA} Bahasa Indonesia', + 'it_IT': f'{FLAG_ITALY} Italiano', # Italian - Italy + 'ko_KR': f'{FLAG_SOUTH_KOREA} 한국어', # Korean - Korea + 'tr_TR': f'{FLAG_TURKEY} Türkçe', # Turkish - Turkey + 'ru_RU': f'{FLAG_RUSSIA} Русский', # Russian - Russia + 'es_ES': f'{FLAG_SPAIN} Español', # Spanish - Spain + 'uk_UA': f'{FLAG_UKRAINE} Українська', # Ukrainian - Ukraine + 'uz_UZ': f'{FLAG_UZBEKISTAN} Oʻzbekcha', # Uzbek - Uzbekistan + } def __init__(self, row_width=3): self.inline_keyboard = list() @@ -106,6 +125,23 @@ class InlineKeyboard(InlineKeyboardMarkup): return self.inline_keyboard.append(self._build_pagination) + def languages(self, callback_pattern: str, locales: Union[str, List[str]], + row_width: int = 2): + locales = locales if isinstance(locales, list) else [locales] + + buttons = [ + InlineKeyboardButton( + text=self._LOCALES.get(locales[i], 'Invalid locale'), + callback_data=callback_pattern.format(locale=locales[i]) + ) + for i in range(0, len(locales)) + ] + + self.inline_keyboard = [ + buttons[i:i + row_width] + for i in range(0, len(buttons), row_width) + ] + class InlineButton(InlineKeyboardButton): def __init__(self, text=None, callback_data=None, url=None, diff --git a/setup.py b/setup.py index ba5a42e..45c4077 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f: setup( name='pykeyboard', - version='0.1.3', + version='0.1.4', author='PyMaster', author_email='', description='Best Keyboard and Pagination for the Pyrogram Library.',