From 768ad0bea3284f39ea45f367aca3f2000c81004f Mon Sep 17 00:00:00 2001 From: T4ras123 Date: Tue, 12 Nov 2024 13:51:00 +0400 Subject: [PATCH 1/3] Translate user-facing messages from Russian to English for better accessibility --- app.py | 20 ++++----- handlers/admin/add.py | 50 +++++++++++------------ handlers/admin/orders.py | 4 +- handlers/admin/questions.py | 14 +++---- handlers/user/cart.py | 34 +++++++-------- handlers/user/catalog.py | 8 ++-- handlers/user/delivery_status.py | 10 ++--- handlers/user/menu.py | 18 ++++---- handlers/user/sos.py | 12 +++--- handlers/user/wallet.py | 2 +- keyboards/default/markups.py | 8 ++-- keyboards/inline/products_from_catalog.py | 2 +- 12 files changed, 91 insertions(+), 91 deletions(-) diff --git a/app.py b/app.py index 3e68b6d..7ded46f 100644 --- a/app.py +++ b/app.py @@ -12,8 +12,8 @@ WEBAPP_HOST = "0.0.0.0" WEBAPP_PORT = int(os.environ.get("PORT", 5000)) -user_message = 'Пользователь' -admin_message = 'Админ' +user_message = 'User' +admin_message = 'Admin' @dp.message_handler(commands='start') @@ -23,17 +23,17 @@ async def cmd_start(message: types.Message): markup.row(user_message, admin_message) - await message.answer('''Привет! 👋 + await message.answer('''Hi! 👋 -🤖 Я бот-магазин по подаже товаров любой категории. +🤖 I'm a marketplace bot to by products from any category. -🛍️ Чтобы перейти в каталог и выбрать приглянувшиеся товары возпользуйтесь командой /menu. +🛍️ To access the catalog and see the products use /menu command. -💰 Пополнить счет можно через Яндекс.кассу, Сбербанк или Qiwi. +💰 For deposits you can use Yandex, Sber and Qivi . -❓ Возникли вопросы? Не проблема! Команда /sos поможет связаться с админами, которые постараются как можно быстрее откликнуться. +❓ Have questions? Not a problem! /sos command will help you to cantact the admins. -🤝 Заказать похожего бота? Свяжитесь с разработчиком Nikolay Simakov, он не кусается))) +🤝 Want to order a similar bot? Contact the developer Nikolay Simakov, he doesn't bite))) ''', reply_markup=markup) @@ -44,7 +44,7 @@ async def user_mode(message: types.Message): if cid in config.ADMINS: config.ADMINS.remove(cid) - await message.answer('Включен пользовательский режим.', reply_markup=ReplyKeyboardRemove()) + await message.answer('User mode is on.', reply_markup=ReplyKeyboardRemove()) @dp.message_handler(text=admin_message) @@ -54,7 +54,7 @@ async def admin_mode(message: types.Message): if cid not in config.ADMINS: config.ADMINS.append(cid) - await message.answer('Включен админский режим.', reply_markup=ReplyKeyboardRemove()) + await message.answer('Admin mode is on.', reply_markup=ReplyKeyboardRemove()) async def on_startup(dp): diff --git a/handlers/admin/add.py b/handlers/admin/add.py index 7a3c173..85f0d94 100644 --- a/handlers/admin/add.py +++ b/handlers/admin/add.py @@ -14,8 +14,8 @@ category_cb = CallbackData('category', 'id', 'action') product_cb = CallbackData('product', 'id', 'action') -add_product = '➕ Добавить товар' -delete_category = '🗑️ Удалить категорию' +add_product = '➕ Add product' +delete_category = '🗑️ Delet a category' @dp.message_handler(IsAdmin(), text=settings) @@ -29,9 +29,9 @@ async def process_settings(message: Message): title, callback_data=category_cb.new(id=idx, action='view'))) markup.add(InlineKeyboardButton( - '+ Добавить категорию', callback_data='add_category')) + '+ Add a category', callback_data='add_category')) - await message.answer('Настройка категорий:', reply_markup=markup) + await message.answer('Category settings:', reply_markup=markup) @dp.callback_query_handler(IsAdmin(), category_cb.filter(action='view')) @@ -44,7 +44,7 @@ async def category_callback_handler(query: CallbackQuery, callback_data: dict, s (category_idx,)) await query.message.delete() - await query.answer('Все добавленные товары в эту категорию.') + await query.answer('All products added to the category.') await state.update_data(category_index=category_idx) await show_products(query.message, products, category_idx) @@ -55,7 +55,7 @@ async def category_callback_handler(query: CallbackQuery, callback_data: dict, s @dp.callback_query_handler(IsAdmin(), text='add_category') async def add_category_callback_handler(query: CallbackQuery): await query.message.delete() - await query.message.answer('Название категории?') + await query.message.answer('What\'s the category name?') await CategoryState.title.set() @@ -83,7 +83,7 @@ async def delete_category_handler(message: Message, state: FSMContext): 'DELETE FROM products WHERE tag IN (SELECT title FROM categories WHERE idx=?)', (idx,)) db.query('DELETE FROM categories WHERE idx=?', (idx,)) - await message.answer('Готово!', reply_markup=ReplyKeyboardRemove()) + await message.answer('All ready!', reply_markup=ReplyKeyboardRemove()) await process_settings(message) @@ -98,13 +98,13 @@ async def process_add_product(message: Message): markup = ReplyKeyboardMarkup(resize_keyboard=True) markup.add(cancel_message) - await message.answer('Название?', reply_markup=markup) + await message.answer('Name?', reply_markup=markup) @dp.message_handler(IsAdmin(), text=cancel_message, state=ProductState.title) async def process_cancel(message: Message, state: FSMContext): - await message.answer('Ок, отменено!', reply_markup=ReplyKeyboardRemove()) + await message.answer('Okey, canceled!', reply_markup=ReplyKeyboardRemove()) await state.finish() await process_settings(message) @@ -122,7 +122,7 @@ async def process_title(message: Message, state: FSMContext): data['title'] = message.text await ProductState.next() - await message.answer('Описание?', reply_markup=back_markup()) + await message.answer('Description?', reply_markup=back_markup()) @dp.message_handler(IsAdmin(), text=back_message, state=ProductState.body) @@ -132,7 +132,7 @@ async def process_body_back(message: Message, state: FSMContext): async with state.proxy() as data: - await message.answer(f"Изменить название с {data['title']}?", reply_markup=back_markup()) + await message.answer(f"Change the name from {data['title']}?", reply_markup=back_markup()) @dp.message_handler(IsAdmin(), state=ProductState.body) @@ -142,7 +142,7 @@ async def process_body(message: Message, state: FSMContext): data['body'] = message.text await ProductState.next() - await message.answer('Фото?', reply_markup=back_markup()) + await message.answer('Photo?', reply_markup=back_markup()) @dp.message_handler(IsAdmin(), content_types=ContentType.PHOTO, state=ProductState.image) @@ -156,7 +156,7 @@ async def process_image_photo(message: Message, state: FSMContext): data['image'] = downloaded_file await ProductState.next() - await message.answer('Цена?', reply_markup=back_markup()) + await message.answer('Price?', reply_markup=back_markup()) @dp.message_handler(IsAdmin(), content_types=ContentType.TEXT, state=ProductState.image) @@ -168,11 +168,11 @@ async def process_image_url(message: Message, state: FSMContext): async with state.proxy() as data: - await message.answer(f"Изменить описание с {data['body']}?", reply_markup=back_markup()) + await message.answer(f"Change the description from {data['body']}?", reply_markup=back_markup()) else: - await message.answer('Вам нужно прислать фото товара.') + await message.answer('You need to send the product\'s photo.') @dp.message_handler(IsAdmin(), lambda message: not message.text.isdigit(), state=ProductState.price) @@ -184,11 +184,11 @@ async def process_price_invalid(message: Message, state: FSMContext): async with state.proxy() as data: - await message.answer("Другое изображение?", reply_markup=back_markup()) + await message.answer("Different image?", reply_markup=back_markup()) else: - await message.answer('Укажите цену в виде числа!') + await message.answer('The price should be a number!') @dp.message_handler(IsAdmin(), lambda message: message.text.isdigit(), state=ProductState.price) @@ -203,7 +203,7 @@ async def process_price(message: Message, state: FSMContext): price = data['price'] await ProductState.next() - text = f'{title}\n\n{body}\n\nЦена: {price} рублей.' + text = f'{title}\n\n{body}\n\nPrice: {price} dollars.' markup = check_markup() @@ -214,7 +214,7 @@ async def process_price(message: Message, state: FSMContext): @dp.message_handler(IsAdmin(), lambda message: message.text not in [back_message, all_right_message], state=ProductState.confirm) async def process_confirm_invalid(message: Message, state: FSMContext): - await message.answer('Такого варианта не было.') + await message.answer('There is no such choice.') @dp.message_handler(IsAdmin(), text=back_message, state=ProductState.confirm) @@ -224,7 +224,7 @@ async def process_confirm_back(message: Message, state: FSMContext): async with state.proxy() as data: - await message.answer(f"Изменить цену с {data['price']}?", reply_markup=back_markup()) + await message.answer(f"Change the price from {data['price']}?", reply_markup=back_markup()) @dp.message_handler(IsAdmin(), text=all_right_message, state=ProductState.confirm) @@ -246,7 +246,7 @@ async def process_confirm(message: Message, state: FSMContext): (idx, title, body, image, int(price), tag)) await state.finish() - await message.answer('Готово!', reply_markup=ReplyKeyboardRemove()) + await message.answer('Ready!', reply_markup=ReplyKeyboardRemove()) await process_settings(message) @@ -258,7 +258,7 @@ async def delete_product_callback_handler(query: CallbackQuery, callback_data: d product_idx = callback_data['id'] db.query('DELETE FROM products WHERE idx=?', (product_idx,)) - await query.answer('Удалено!') + await query.answer('Deleted!') await query.message.delete() @@ -268,11 +268,11 @@ async def show_products(m, products, category_idx): for idx, title, body, image, price, tag in products: - text = f'{title}\n\n{body}\n\nЦена: {price} рублей.' + text = f'{title}\n\n{body}\n\nPrice: {price} dollars.' markup = InlineKeyboardMarkup() markup.add(InlineKeyboardButton( - '🗑️ Удалить', callback_data=product_cb.new(id=idx, action='delete'))) + '🗑️ Delete', callback_data=product_cb.new(id=idx, action='delete'))) await m.answer_photo(photo=image, caption=text, @@ -282,4 +282,4 @@ async def show_products(m, products, category_idx): markup.add(add_product) markup.add(delete_category) - await m.answer('Хотите что-нибудь добавить или удалить?', reply_markup=markup) + await m.answer('Want to delete or add something?', reply_markup=markup) diff --git a/handlers/admin/orders.py b/handlers/admin/orders.py index 5e99fce..aaeed04 100644 --- a/handlers/admin/orders.py +++ b/handlers/admin/orders.py @@ -9,7 +9,7 @@ async def process_orders(message: Message): orders = db.fetchall('SELECT * FROM orders') - if len(orders) == 0: await message.answer('У вас нет заказов.') + if len(orders) == 0: await message.answer('You don\t have active orders.') else: await order_answer(message, orders) async def order_answer(message, orders): @@ -17,6 +17,6 @@ async def order_answer(message, orders): res = '' for order in orders: - res += f'Заказ №{order[3]}\n\n' + res += f'Order №{order[3]}\n\n' await message.answer(res) \ No newline at end of file diff --git a/handlers/admin/questions.py b/handlers/admin/questions.py index 8a828c1..166ba65 100644 --- a/handlers/admin/questions.py +++ b/handlers/admin/questions.py @@ -20,7 +20,7 @@ async def process_questions(message: Message): if len(questions) == 0: - await message.answer('Нет вопросов.') + await message.answer('No questions.') else: @@ -28,7 +28,7 @@ async def process_questions(message: Message): markup = InlineKeyboardMarkup() markup.add(InlineKeyboardButton( - 'Ответить', callback_data=question_cb.new(cid=cid, action='answer'))) + 'Answer', callback_data=question_cb.new(cid=cid, action='answer'))) await message.answer(question, reply_markup=markup) @@ -39,7 +39,7 @@ async def process_answer(query: CallbackQuery, callback_data: dict, state: FSMCo async with state.proxy() as data: data['cid'] = callback_data['cid'] - await query.message.answer('Напиши ответ.', reply_markup=ReplyKeyboardRemove()) + await query.message.answer('Write an answer.', reply_markup=ReplyKeyboardRemove()) await AnswerState.answer.set() @@ -50,12 +50,12 @@ async def process_submit(message: Message, state: FSMContext): data['answer'] = message.text await AnswerState.next() - await message.answer('Убедитесь, что не ошиблись в ответе.', reply_markup=submit_markup()) + await message.answer('Make sure everything is correct.', reply_markup=submit_markup()) @dp.message_handler(IsAdmin(), text=cancel_message, state=AnswerState.submit) async def process_send_answer(message: Message, state: FSMContext): - await message.answer('Отменено!', reply_markup=ReplyKeyboardRemove()) + await message.answer('Canceled!', reply_markup=ReplyKeyboardRemove()) await state.finish() @@ -70,9 +70,9 @@ async def process_send_answer(message: Message, state: FSMContext): question = db.fetchone( 'SELECT question FROM questions WHERE cid=?', (cid,))[0] db.query('DELETE FROM questions WHERE cid=?', (cid,)) - text = f'Вопрос: {question}\n\nОтвет: {answer}' + text = f'Question: {question}\n\nAnswer: {answer}' - await message.answer('Отправлено!', reply_markup=ReplyKeyboardRemove()) + await message.answer('Sent!', reply_markup=ReplyKeyboardRemove()) await bot.send_message(cid, text) await state.finish() diff --git a/handlers/user/cart.py b/handlers/user/cart.py index 578df60..23b29ec 100644 --- a/handlers/user/cart.py +++ b/handlers/user/cart.py @@ -19,7 +19,7 @@ async def process_cart(message: Message, state: FSMContext): if len(cart_data) == 0: - await message.answer('Ваша корзина пуста.') + await message.answer('Your cart is empty.') else: @@ -45,7 +45,7 @@ async def process_cart(message: Message, state: FSMContext): data['products'][idx] = [title, price, count_in_cart] markup = product_markup(idx, count_in_cart) - text = f'{title}\n\n{body}\n\nЦена: {price}₽.' + text = f'{title}\n\n{body}\n\nPrice: {price}$.' await message.answer_photo(photo=image, caption=text, @@ -53,9 +53,9 @@ async def process_cart(message: Message, state: FSMContext): if order_cost != 0: markup = ReplyKeyboardMarkup(resize_keyboard=True, selective=True) - markup.add('📦 Оформить заказ') + markup.add('📦 Make an order') - await message.answer('Перейти к оформлению?', + await message.answer('Go to checkout?', reply_markup=markup) @@ -77,7 +77,7 @@ async def product_callback_handler(query: CallbackQuery, callback_data: dict, st else: - await query.answer('Количество - ' + data['products'][idx][2]) + await query.answer('Quantity - ' + data['products'][idx][2]) else: @@ -107,7 +107,7 @@ async def product_callback_handler(query: CallbackQuery, callback_data: dict, st await query.message.edit_reply_markup(product_markup(idx, count_in_cart)) -@dp.message_handler(IsUser(), text='📦 Оформить заказ') +@dp.message_handler(IsUser(), text='📦 Make an order') async def process_checkout(message: Message, state: FSMContext): await CheckoutState.check_cart.set() @@ -123,16 +123,16 @@ async def checkout(message, state): for title, price, count_in_cart in data['products'].values(): tp = count_in_cart * price - answer += f'{title} * {count_in_cart}шт. = {tp}₽\n' + answer += f'{title} * {count_in_cart}items. = {tp}$\n' total_price += tp - await message.answer(f'{answer}\nОбщая сумма заказа: {total_price}₽.', + await message.answer(f'{answer}\nTotal price: {total_price}$.', reply_markup=check_markup()) @dp.message_handler(IsUser(), lambda message: message.text not in [all_right_message, back_message], state=CheckoutState.check_cart) async def process_check_cart_invalid(message: Message): - await message.reply('Такого варианта не было.') + await message.reply('There is no such choice.') @dp.message_handler(IsUser(), text=back_message, state=CheckoutState.check_cart) @@ -144,7 +144,7 @@ async def process_check_cart_back(message: Message, state: FSMContext): @dp.message_handler(IsUser(), text=all_right_message, state=CheckoutState.check_cart) async def process_check_cart_all_right(message: Message, state: FSMContext): await CheckoutState.next() - await message.answer('Укажите свое имя.', + await message.answer('What\'s your name?', reply_markup=back_markup()) @@ -169,7 +169,7 @@ async def process_name(message: Message, state: FSMContext): else: await CheckoutState.next() - await message.answer('Укажите свой адрес места жительства.', + await message.answer('Specify your address.', reply_markup=back_markup()) @@ -178,7 +178,7 @@ async def process_address_back(message: Message, state: FSMContext): async with state.proxy() as data: - await message.answer('Изменить имя с ' + data['name'] + '?', + await message.answer('Change the name from ' + data['name'] + '?', reply_markup=back_markup()) await CheckoutState.name.set() @@ -196,13 +196,13 @@ async def process_address(message: Message, state: FSMContext): async def confirm(message): - await message.answer('Убедитесь, что все правильно оформлено и подтвердите заказ.', + await message.answer('Confirm that everything is correct and proceed with the order.', reply_markup=confirm_markup()) @dp.message_handler(IsUser(), lambda message: message.text not in [confirm_message, back_message], state=CheckoutState.confirm) async def process_confirm_invalid(message: Message): - await message.reply('Такого варианта не было.') + await message.reply('There is no such choice.') @dp.message_handler(IsUser(), text=back_message, state=CheckoutState.confirm) @@ -211,7 +211,7 @@ async def process_confirm(message: Message, state: FSMContext): await CheckoutState.address.set() async with state.proxy() as data: - await message.answer('Изменить адрес с ' + data['address'] + '?', + await message.answer('Change the address from ' + data['address'] + '?', reply_markup=back_markup()) @@ -237,11 +237,11 @@ async def process_confirm(message: Message, state: FSMContext): db.query('DELETE FROM cart WHERE cid=?', (cid,)) - await message.answer('Ок! Ваш заказ уже в пути 🚀\nИмя: ' + data['name'] + '\nАдрес: ' + data['address'] + '', + await message.answer('Your order is on it\'s way 🚀\nName: ' + data['name'] + '\nAddress: ' + data['address'] + '', reply_markup=markup) else: - await message.answer('У вас недостаточно денег на счете. Пополните баланс!', + await message.answer('You don\'t have enough funds. Make a deposit!', reply_markup=markup) await state.finish() diff --git a/handlers/user/catalog.py b/handlers/user/catalog.py index d0cda85..e9a3b43 100644 --- a/handlers/user/catalog.py +++ b/handlers/user/catalog.py @@ -12,7 +12,7 @@ @dp.message_handler(IsUser(), text=catalog) async def process_catalog(message: Message): - await message.answer('Выберите раздел, чтобы вывести список товаров:', + await message.answer('Choose the category to see the products:', reply_markup=categories_markup()) @@ -24,7 +24,7 @@ async def category_callback_handler(query: CallbackQuery, callback_data: dict): AND product.idx NOT IN (SELECT idx FROM cart WHERE cid = ?)''', (callback_data['id'], query.message.chat.id)) - await query.answer('Все доступные товары.') + await query.answer('All available products.') await show_products(query.message, products) @@ -34,7 +34,7 @@ async def add_product_callback_handler(query: CallbackQuery, callback_data: dict db.query('INSERT INTO cart VALUES (?, ?, 1)', (query.message.chat.id, callback_data['id'])) - await query.answer('Товар добавлен в корзину!') + await query.answer('Product added to cart!') await query.message.delete() @@ -42,7 +42,7 @@ async def show_products(m, products): if len(products) == 0: - await m.answer('Здесь ничего нет 😢') + await m.answer('Nothing here 😢') else: diff --git a/handlers/user/delivery_status.py b/handlers/user/delivery_status.py index 347a907..96d0846 100644 --- a/handlers/user/delivery_status.py +++ b/handlers/user/delivery_status.py @@ -9,7 +9,7 @@ async def process_delivery_status(message: Message): orders = db.fetchall('SELECT * FROM orders WHERE cid=?', (message.chat.id,)) - if len(orders) == 0: await message.answer('У вас нет активных заказов.') + if len(orders) == 0: await message.answer('You don\'t have active orders.') else: await delivery_status_answer(message, orders) async def delivery_status_answer(message, orders): @@ -18,11 +18,11 @@ async def delivery_status_answer(message, orders): for order in orders: - res += f'Заказ №{order[3]}' + res += f'Order №{order[3]}' answer = [ - ' лежит на складе.', - ' уже в пути!', - ' прибыл и ждет вас на почте!' + ' in a warehouse.', + ' on its way!', + ' arrived to the post office!' ] res += answer[0] diff --git a/handlers/user/menu.py b/handlers/user/menu.py index 2ebc6ff..1660f06 100644 --- a/handlers/user/menu.py +++ b/handlers/user/menu.py @@ -3,14 +3,14 @@ from loader import dp from filters import IsAdmin, IsUser -catalog = '🛍️ Каталог' -balance = '💰 Баланс' -cart = '🛒 Корзина' -delivery_status = '🚚 Статус заказа' +catalog = '🛍️ Catalog' +balance = '💰 Balance' +cart = '🛒 Cart' +delivery_status = '🚚 Order status' -settings = '⚙️ Настройка каталога' -orders = '🚚 Заказы' -questions = '❓ Вопросы' +settings = '⚙️ Catalog settings' +orders = '🚚 Orders' +questions = '❓ Questions' @dp.message_handler(IsAdmin(), commands='menu') async def admin_menu(message: Message): @@ -18,7 +18,7 @@ async def admin_menu(message: Message): markup.add(settings) markup.add(questions, orders) - await message.answer('Меню', reply_markup=markup) + await message.answer('Menu', reply_markup=markup) @dp.message_handler(IsUser(), commands='menu') async def user_menu(message: Message): @@ -27,4 +27,4 @@ async def user_menu(message: Message): markup.add(balance, cart) markup.add(delivery_status) - await message.answer('Меню', reply_markup=markup) + await message.answer('Menu', reply_markup=markup) diff --git a/handlers/user/sos.py b/handlers/user/sos.py index 5b45288..c79bf20 100644 --- a/handlers/user/sos.py +++ b/handlers/user/sos.py @@ -11,7 +11,7 @@ @dp.message_handler(commands='sos') async def cmd_sos(message: Message): await SosState.question.set() - await message.answer('В чем суть проблемы? Опишите как можно детальнее и администратор обязательно вам ответит.', reply_markup=ReplyKeyboardRemove()) + await message.answer('What\'s the problem? Describe it in detail and the operator will respond soon.', reply_markup=ReplyKeyboardRemove()) @dp.message_handler(state=SosState.question) @@ -19,18 +19,18 @@ async def process_question(message: Message, state: FSMContext): async with state.proxy() as data: data['question'] = message.text - await message.answer('Убедитесь, что все верно.', reply_markup=submit_markup()) + await message.answer('Make sure everythong is correct.', reply_markup=submit_markup()) await SosState.next() @dp.message_handler(lambda message: message.text not in [cancel_message, all_right_message], state=SosState.submit) async def process_price_invalid(message: Message): - await message.answer('Такого варианта не было.') + await message.answer('There is no such choise.') @dp.message_handler(text=cancel_message, state=SosState.submit) async def process_cancel(message: Message, state: FSMContext): - await message.answer('Отменено!', reply_markup=ReplyKeyboardRemove()) + await message.answer('Canceled!', reply_markup=ReplyKeyboardRemove()) await state.finish() @@ -45,10 +45,10 @@ async def process_submit(message: Message, state: FSMContext): db.query('INSERT INTO questions VALUES (?, ?)', (cid, data['question'])) - await message.answer('Отправлено!', reply_markup=ReplyKeyboardRemove()) + await message.answer('Sent!', reply_markup=ReplyKeyboardRemove()) else: - await message.answer('Превышен лимит на количество задаваемых вопросов.', reply_markup=ReplyKeyboardRemove()) + await message.answer('The limit for questions is exceeded.', reply_markup=ReplyKeyboardRemove()) await state.finish() diff --git a/handlers/user/wallet.py b/handlers/user/wallet.py index 4dd15eb..6a92103 100644 --- a/handlers/user/wallet.py +++ b/handlers/user/wallet.py @@ -14,5 +14,5 @@ @dp.message_handler(IsUser(), text=balance) async def process_balance(message: Message, state: FSMContext): - await message.answer('Ваш кошелек пуст! Чтобы его пополнить нужно...') + await message.answer('Your wallet is empty! To make a deposit you need...') diff --git a/keyboards/default/markups.py b/keyboards/default/markups.py index efe1ddb..bc769ba 100644 --- a/keyboards/default/markups.py +++ b/keyboards/default/markups.py @@ -1,9 +1,9 @@ from aiogram.types import ReplyKeyboardMarkup -back_message = '👈 Назад' -confirm_message = '✅ Подтвердить заказ' -all_right_message = '✅ Все верно' -cancel_message = '🚫 Отменить' +back_message = '👈 Back' +confirm_message = '✅ Confirm the order' +all_right_message = '✅ All is correct' +cancel_message = '🚫 Cancel' def confirm_markup(): markup = ReplyKeyboardMarkup(resize_keyboard=True, selective=True) diff --git a/keyboards/inline/products_from_catalog.py b/keyboards/inline/products_from_catalog.py index 212ebcc..2d22ce1 100644 --- a/keyboards/inline/products_from_catalog.py +++ b/keyboards/inline/products_from_catalog.py @@ -10,6 +10,6 @@ def product_markup(idx='', price=0): global product_cb markup = InlineKeyboardMarkup() - markup.add(InlineKeyboardButton(f'Добавить в корзину - {price}₽', callback_data=product_cb.new(id=idx, action='add'))) + markup.add(InlineKeyboardButton(f'Add to cart - {price}$', callback_data=product_cb.new(id=idx, action='add'))) return markup \ No newline at end of file From 57d18f62a89b0862a13d3580197cd92143394da5 Mon Sep 17 00:00:00 2001 From: T4ras123 Date: Tue, 12 Nov 2024 14:03:49 +0400 Subject: [PATCH 2/3] Fix typos and improve user messages for clarity --- app.py | 2 +- handlers/admin/add.py | 6 +++--- handlers/admin/orders.py | 2 +- handlers/user/cart.py | 2 +- handlers/user/sos.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index 7ded46f..9c22830 100644 --- a/app.py +++ b/app.py @@ -25,7 +25,7 @@ async def cmd_start(message: types.Message): await message.answer('''Hi! 👋 -🤖 I'm a marketplace bot to by products from any category. +🤖 I'm a marketplace bot to buy products from any category. 🛍️ To access the catalog and see the products use /menu command. diff --git a/handlers/admin/add.py b/handlers/admin/add.py index 85f0d94..816a2ef 100644 --- a/handlers/admin/add.py +++ b/handlers/admin/add.py @@ -15,7 +15,7 @@ product_cb = CallbackData('product', 'id', 'action') add_product = '➕ Add product' -delete_category = '🗑️ Delet a category' +delete_category = '🗑️ Delete a category' @dp.message_handler(IsAdmin(), text=settings) @@ -55,7 +55,7 @@ async def category_callback_handler(query: CallbackQuery, callback_data: dict, s @dp.callback_query_handler(IsAdmin(), text='add_category') async def add_category_callback_handler(query: CallbackQuery): await query.message.delete() - await query.message.answer('What\'s the category name?') + await query.message.answer('What\'s the category\'s name?') await CategoryState.title.set() @@ -104,7 +104,7 @@ async def process_add_product(message: Message): @dp.message_handler(IsAdmin(), text=cancel_message, state=ProductState.title) async def process_cancel(message: Message, state: FSMContext): - await message.answer('Okey, canceled!', reply_markup=ReplyKeyboardRemove()) + await message.answer('Okay, canceled!', reply_markup=ReplyKeyboardRemove()) await state.finish() await process_settings(message) diff --git a/handlers/admin/orders.py b/handlers/admin/orders.py index aaeed04..46ae46d 100644 --- a/handlers/admin/orders.py +++ b/handlers/admin/orders.py @@ -9,7 +9,7 @@ async def process_orders(message: Message): orders = db.fetchall('SELECT * FROM orders') - if len(orders) == 0: await message.answer('You don\t have active orders.') + if len(orders) == 0: await message.answer('You don\'t have active orders.') else: await order_answer(message, orders) async def order_answer(message, orders): diff --git a/handlers/user/cart.py b/handlers/user/cart.py index 23b29ec..27451e1 100644 --- a/handlers/user/cart.py +++ b/handlers/user/cart.py @@ -237,7 +237,7 @@ async def process_confirm(message: Message, state: FSMContext): db.query('DELETE FROM cart WHERE cid=?', (cid,)) - await message.answer('Your order is on it\'s way 🚀\nName: ' + data['name'] + '\nAddress: ' + data['address'] + '', + await message.answer('Your order is on its way 🚀\nName: ' + data['name'] + '\nAddress: ' + data['address'] + '', reply_markup=markup) else: diff --git a/handlers/user/sos.py b/handlers/user/sos.py index c79bf20..f0098dc 100644 --- a/handlers/user/sos.py +++ b/handlers/user/sos.py @@ -19,7 +19,7 @@ async def process_question(message: Message, state: FSMContext): async with state.proxy() as data: data['question'] = message.text - await message.answer('Make sure everythong is correct.', reply_markup=submit_markup()) + await message.answer('Make sure everything is correct.', reply_markup=submit_markup()) await SosState.next() From 8a17ced4487ad170ae3f3c75ed9ed80bd0f691e7 Mon Sep 17 00:00:00 2001 From: T4ras123 Date: Tue, 26 Nov 2024 11:15:44 +0400 Subject: [PATCH 3/3] Refactor delivery status handling and implement multilingual support for user messages --- data/messages.py | 142 +++++++++++++++++++++++++++++++ handlers/user/delivery_status.py | 30 +++---- handlers/user/menu.py | 32 +++---- 3 files changed, 166 insertions(+), 38 deletions(-) create mode 100644 data/messages.py diff --git a/data/messages.py b/data/messages.py new file mode 100644 index 0000000..5a5a69a --- /dev/null +++ b/data/messages.py @@ -0,0 +1,142 @@ +# messages.py + +MESSAGES = { + 'en': { + # General messages + 'start': '''Hi! 👋 + +🤖 I'm a marketplace bot to buy products from any category. + +🛍️ To access the catalog and see the products, use the /menu command. + +💰 For deposits, you can use Yandex, Sber, and Qiwi. + +❓ Have questions? Not a problem! Use the /sos command to contact the admins. + +🤝 Want to order a similar bot? Contact the developer Nikolay Simakov, he doesn't bite)))''', + + 'user_mode_on': 'User mode is on.', + 'admin_mode_on': 'Admin mode is on.', + 'menu': 'Menu', + + # User menu items + 'catalog': '🛍️ Catalog', + 'balance': '💰 Balance', + 'cart': '🛒 Cart', + 'delivery_status': '🚚 Order status', + + # Admin menu items + 'settings': '⚙️ Catalog settings', + 'orders': '🚚 Orders', + 'questions': '❓ Questions', + + # Cart messages + 'cart_empty': 'Your cart is empty.', + 'cart_product_info': '{title}\n\n{body}\n\nPrice: {price}$.', + 'enter_name': 'Enter your name.', + 'enter_address': 'Specify your address.', + 'change_name': 'Change the name from {name}?', + 'change_address': 'Change the address from {address}?', + 'order_confirmed': 'Your order is on its way 🚀\nName: {name}\nAddress: {address}', + 'not_enough_funds': 'You don\'t have enough funds. Make a deposit!', + + # Catalog messages + 'choose_category': 'Choose the category to see the products:', + + # SOS messages + 'sos_prompt': 'What\'s the problem? Describe it in detail and the operator will respond soon.', + 'sos_sent': 'Sent!', + 'sos_limit_exceeded': 'The limit for questions is exceeded.', + 'no_questions': 'No questions.', + + # Delivery status messages + 'no_active_orders': 'You don\'t have active orders.', + 'order_status': 'Order №{order_number}{status}', + 'status_in_warehouse': ' in a warehouse.', + 'status_on_the_way': ' on its way!', + 'status_arrived': ' arrived at the post office!', + + # Confirmation messages + 'make_sure_correct': 'Make sure everything is correct.', + 'ready': 'Ready!', + 'cancelled': 'Canceled!', + 'sent': 'Sent!', + 'no_such_choice': 'There is no such choice.', + + # Keyboard buttons + 'back': '👈 Back', + 'confirm_order': '✅ Confirm the order', + 'all_correct': '✅ All is correct', + 'cancel': '🚫 Cancel', + 'answer': 'Answer', + }, + 'ru': { + # General messages + 'start': '''Привет! 👋 + +🤖 Я бот-магазин для покупки товаров из любой категории. + +🛍️ Чтобы получить доступ к каталогу и посмотреть товары, используйте команду /menu. + +💰 Для пополнения можно использовать Яндекс, Сбер и Киви. + +❓ Есть вопросы? Не проблема! Команда /sos поможет вам связаться с администраторами. + +🤝 Хотите заказать похожего бота? Свяжитесь с разработчиком Николаем Симаковым, он не кусается)))''', + + 'user_mode_on': 'Режим пользователя включен.', + 'admin_mode_on': 'Режим администратора включен.', + 'menu': 'Меню', + + # User menu items + 'catalog': '🛍️ Каталог', + 'balance': '💰 Баланс', + 'cart': '🛒 Корзина', + 'delivery_status': '🚚 Статус заказа', + + # Admin menu items + 'settings': '⚙️ Настройки каталога', + 'orders': '🚚 Заказы', + 'questions': '❓ Вопросы', + + # Cart messages + 'cart_empty': 'Ваша корзина пуста.', + 'cart_product_info': '{title}\n\n{body}\n\nЦена: {price}₽.', + 'enter_name': 'Введите ваше имя.', + 'enter_address': 'Укажите ваш адрес.', + 'change_name': 'Изменить имя с {name}?', + 'change_address': 'Изменить адрес с {address}?', + 'order_confirmed': 'Ваш заказ в пути 🚀\nИмя: {name}\nАдрес: {address}', + 'not_enough_funds': 'У вас недостаточно средств. Пополните баланс!', + + # Catalog messages + 'choose_category': 'Выберите категорию, чтобы увидеть товары:', + + # SOS messages + 'sos_prompt': 'В чём проблема? Опишите её подробно, и оператор скоро ответит.', + 'sos_sent': 'Отправлено!', + 'sos_limit_exceeded': 'Превышен лимит вопросов.', + 'no_questions': 'Нет вопросов.', + + # Delivery status messages + 'no_active_orders': 'У вас нет активных заказов.', + 'order_status': 'Заказ №{order_number}{status}', + 'status_in_warehouse': ' на складе.', + 'status_on_the_way': ' в пути!', + 'status_arrived': ' прибыл на почту!', + + # Confirmation messages + 'make_sure_correct': 'Убедитесь, что всё правильно.', + 'ready': 'Готово!', + 'cancelled': 'Отменено!', + 'sent': 'Отправлено!', + 'no_such_choice': 'Такого выбора нет.', + + # Keyboard buttons + 'back': '👈 Назад', + 'confirm_order': '✅ Подтвердить заказ', + 'all_correct': '✅ Всё верно', + 'cancel': '🚫 Отмена', + 'answer': 'Ответить', + } +} \ No newline at end of file diff --git a/handlers/user/delivery_status.py b/handlers/user/delivery_status.py index 96d0846..fcaaabc 100644 --- a/handlers/user/delivery_status.py +++ b/handlers/user/delivery_status.py @@ -1,31 +1,23 @@ from aiogram.types import Message -from loader import dp, db -from .menu import delivery_status +from aiogram.types import Message +from loader import dp, db, get_user_language +from data.messages import MESSAGES from filters import IsUser -@dp.message_handler(IsUser(), text=delivery_status) +@dp.message_handler(IsUser(), text=lambda msg: msg.text == MESSAGES[get_user_language(msg.from_user.id)]['delivery_status']) async def process_delivery_status(message: Message): - + language = get_user_language(message.from_user.id) orders = db.fetchall('SELECT * FROM orders WHERE cid=?', (message.chat.id,)) - if len(orders) == 0: await message.answer('You don\'t have active orders.') - else: await delivery_status_answer(message, orders) - -async def delivery_status_answer(message, orders): + if len(orders) == 0: + await message.answer(MESSAGES[language]['no_active_orders']) + else: + await delivery_status_answer(message, orders, language) +async def delivery_status_answer(message, orders, language): res = '' - for order in orders: - - res += f'Order №{order[3]}' - answer = [ - ' in a warehouse.', - ' on its way!', - ' arrived to the post office!' - ] - - res += answer[0] + res += MESSAGES[language]['order_status'].format(order_number=order[3], status=MESSAGES[language]['status_in_warehouse']) res += '\n\n' - await message.answer(res) \ No newline at end of file diff --git a/handlers/user/menu.py b/handlers/user/menu.py index 1660f06..1753797 100644 --- a/handlers/user/menu.py +++ b/handlers/user/menu.py @@ -1,30 +1,24 @@ - -from aiogram.types import Message, CallbackQuery, ReplyKeyboardMarkup -from loader import dp +# handlers/user/menu.py +from aiogram.types import Message, ReplyKeyboardMarkup +from loader import dp, get_user_language from filters import IsAdmin, IsUser - -catalog = '🛍️ Catalog' -balance = '💰 Balance' -cart = '🛒 Cart' -delivery_status = '🚚 Order status' - -settings = '⚙️ Catalog settings' -orders = '🚚 Orders' -questions = '❓ Questions' +from data.messages import MESSAGES @dp.message_handler(IsAdmin(), commands='menu') async def admin_menu(message: Message): + language = get_user_language(message.from_user.id) markup = ReplyKeyboardMarkup(selective=True) - markup.add(settings) - markup.add(questions, orders) + markup.add(MESSAGES[language]['settings']) + markup.add(MESSAGES[language]['questions'], MESSAGES[language]['orders']) - await message.answer('Menu', reply_markup=markup) + await message.answer(MESSAGES[language]['menu'], reply_markup=markup) @dp.message_handler(IsUser(), commands='menu') async def user_menu(message: Message): + language = get_user_language(message.from_user.id) markup = ReplyKeyboardMarkup(selective=True) - markup.add(catalog) - markup.add(balance, cart) - markup.add(delivery_status) + markup.add(MESSAGES[language]['catalog']) + markup.add(MESSAGES[language]['balance'], MESSAGES[language]['cart']) + markup.add(MESSAGES[language]['delivery_status']) - await message.answer('Menu', reply_markup=markup) + await message.answer(MESSAGES[language]['menu'], reply_markup=markup)