def locale_button(bot, update): chat = update.effective_chat user = update.effective_user # type: optional[User] query = update.callback_query lang_match = re.findall(r"id|en|pt", query.data) if lang_match: if lang_match[0]: switch_to_locale(chat.id, lang_match[0]) query.answer(text="Language changed!") else: query.answer(text="Error!", show_alert=True) try: LANGUAGE = prev_locale(chat.id) locale = LANGUAGE.locale_name curr_lang = list_locales[locale] except: curr_lang = "English" text = "*Select language* \n" text += "User language : `{}`".format(curr_lang) conn = connected(bot, update, chat, user.id, need_admin=False) if not conn == False: try: chatlng = prev_locale(conn).locale_name chatlng = list_locales[chatlng] text += "\nConnected chat language : `{}`".format(chatlng) except: chatlng = "English" text += "*\n\nSelect new user language:*" query.message.reply_text( text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton("Indonesia 🇮🇩", callback_data="set_lang_id") ]] + [[ InlineKeyboardButton("English 🇺🇸", callback_data="set_lang_en") ]] + [[ InlineKeyboardButton("Português 🇧🇷", callback_data="set_lang_pt") ]] + [[InlineKeyboardButton("⬅️ Back", callback_data="bot_start")]])) print(lang_match) query.message.delete() bot.answer_callback_query(query.id)
def locale(bot, update, args): chat = update.effective_chat if len(args) > 0: locale = args[0].lower() if locale in list_locales: if locale in ('en|pt'): switch_to_locale(chat.id, locale) update.message.reply_text( tld(chat.id, 'Switched to {} successfully!').format( list_locales[locale])) else: update.message.reply_text( tld( chat.id, "{} is not supported yet!".format( list_locales[locale]))) else: update.message.reply_text( tld( chat.id, "Is that even a valid language code? Use an internationally accepted ISO code!" )) else: LANGUAGE = prev_locale(chat.id) if LANGUAGE: locale = LANGUAGE.locale_name native_lang = list_locales[locale] update.message.reply_text(tld( chat.id, "Current locale for this chat is: *{}*".format(native_lang)), parse_mode=ParseMode.MARKDOWN) else: update.message.reply_text( "Current locale for this chat is: *English*", parse_mode=ParseMode.MARKDOWN)
def tld_help(chat_id, t): LANGUAGE = prev_locale(chat_id) print("tld_help ", chat_id, t) if LANGUAGE: LOCALE = LANGUAGE.locale_name t = t + "_help" print("Test2", t) if LOCALE in ('pt') and t in PortugueseBrStrings: return PortugueseBrStrings[t] else: return False else: return False
def tld_help(chat_id, t): LANGUAGE = prev_locale(chat_id) print("tld_help ", chat_id, t) if LANGUAGE: LOCALE = LANGUAGE.locale_name t = t + "_help" print("Test2", t) if LOCALE in ('id') and t in IndonesiaStrings: return IndonesiaStrings[t] else: return False else: return False
def tld(chat_id, t, show_none=True): LANGUAGE = prev_locale(chat_id) print(chat_id, t) if LANGUAGE: LOCALE = LANGUAGE.locale_name if LOCALE in ('pt') and t in PortugueseBrStrings: return PortugueseBrStrings[t] else: if t in EnglishStrings: return EnglishStrings[t] else: return t elif show_none: if t in EnglishStrings: return EnglishStrings[t] else: return t