From bed2fabbb64318279ad53ebd34b5a29a8e37ec0b Mon Sep 17 00:00:00 2001 From: Hiddify <114227601+hiddify-com@users.noreply.github.com> Date: Wed, 10 Jul 2024 23:04:46 +0000 Subject: [PATCH] setup translation --- hiddifypanel_bot/cli.py | 21 ++++-------------- hiddifypanel_bot/translations/en.json | 31 +++++++++++++++++++++++++++ hiddifypanel_bot/translations/fa.json | 31 +++++++++++++++++++++++++++ hiddifypanel_bot/utils/__init__.py | 1 + hiddifypanel_bot/utils/translation.py | 8 +++++++ project.inlang/settings.json | 24 +++++++++++++++++++++ requirements.txt | 2 ++ 7 files changed, 101 insertions(+), 17 deletions(-) create mode 100644 hiddifypanel_bot/translations/en.json create mode 100644 hiddifypanel_bot/translations/fa.json create mode 100644 hiddifypanel_bot/utils/__init__.py create mode 100644 hiddifypanel_bot/utils/translation.py create mode 100644 project.inlang/settings.json diff --git a/hiddifypanel_bot/cli.py b/hiddifypanel_bot/cli.py index cf4bc14..96e957a 100644 --- a/hiddifypanel_bot/cli.py +++ b/hiddifypanel_bot/cli.py @@ -7,22 +7,9 @@ - Start a web application - Import things from your .base module """ - +from . import utils def main(): # pragma: no cover - """ - The main function executes on commands: - `python -m hiddifypanel_bot` and `$ hiddifypanel_bot `. - - This is your program's entry point. - - You can change this function to do whatever you want. - Examples: - * Run a test suite - * Run a server - * Do some other stuff - * Run a command line application (Click, Typer, ArgParse) - * List all available tasks - * Run an application (Flask, FastAPI, Django, etc.) - """ - print("This will do something") + utils.setup_translation() + import i18n + print(i18n.t("start",locale='fa')) \ No newline at end of file diff --git a/hiddifypanel_bot/translations/en.json b/hiddifypanel_bot/translations/en.json new file mode 100644 index 0000000..0037f12 --- /dev/null +++ b/hiddifypanel_bot/translations/en.json @@ -0,0 +1,31 @@ +{ + "start": "Welcome to the Hiddify bot.\n Use the menu below to manage.", + "unauthorized": "You do not have permission to use this bot.", + "authorized": "Unauthorized", + "error": "Your request cannot be executed", + "uuid": "Please enter your UUID:", + "adduser": "Add User", + "showuser": "Show User", + "serverinfo": "Server Information", + "backup": "Backup", + "reset": "User successfully updated", + "resettime": "User time limit updated", + "resetgb": "User data limit updated", + "addname": "Enter user name:", + "adddays": "Enter user duration:", + "addgb": "Enter user data amount:", + "help": "Help", + "helpme": "To find out your user info, you need to enter your user UUID after clicking the Show User button and wait for the information to be displayed.", + "admin": "Admin", + "addadmin": "Add", + "showadmin": "Show", + "deleteadmin": "Delete", + "backmainmenu": "Back", + "adminmenu": "Admin Menu", + "adminfail": "Error in the process", + "adminuuid": "Enter the admin UUID to delete:", + "admindeleted": "Admin successfully deleted.", + "adminnotdeleted": "Error deleting admin.", + "invaliddays": "Please enter numeric values.", + "invalidgb": "Please enter numeric values." +} diff --git a/hiddifypanel_bot/translations/fa.json b/hiddifypanel_bot/translations/fa.json new file mode 100644 index 0000000..1252735 --- /dev/null +++ b/hiddifypanel_bot/translations/fa.json @@ -0,0 +1,31 @@ +{ + "start": "به ربات هیدیفای خوش آمدید.\n از منو زیر برای مدیریت استفاده کنید ${test}", + "unauthorized": "شما مجوز استفاده از این ربات را ندارید.", + "authorized": "غیرمجاز", + "error": "درخواست شما قابل اجرا نمیباشد", + "uuid": "لطفا UUID خود را وارد نمایید :", + "adduser": "افزودن کاربر", + "showuser": "نمایش کاربر", + "serverinfo": "اطلاعات سرور", + "backup": "بکاپ", + "reset": "کاربر با موفقیت بروزرسانی شد", + "resettime": "محدودیت زمان کاربر بروزرسانی شد", + "resetgb": "محدودیت حجم کاربر بروزرسانی شد", + "addname": "نام کاربر را وارد کنید:", + "adddays": "مدت زمان کاربر را وارد کنید:", + "addgb": "مقدار حجم کاربر را وارد کنید:", + "help": "آموزش", + "helpme": "برای اطلاع از یوزر خود باید UUID یوزر خود را بعد از زدن روی کلید نمایش کاربر وارد کرده و منتظر نمایش اطلاعات باشید", + "admin": "ادمین", + "addadmin": "افزودن", + "showadmin": "نمایش", + "deleteadmin": "حذف", + "backmainmenu": "برگشت", + "adminmenu": "منو ادمین", + "adminfai": "خطا در انجام فرایند", + "adminuuid": "برای حذف UUID ادمین را وارد کنید:", + "admindeleted": "ادمین با موفقیت حذف شد.", + "adminnotdeleted": "خطایی در حذف ادمین وجود دارد.", + "invaliddays": "لطفا مقادیر با عدد وارد نمایید.", + "invalidgb": "لطفا مقادیر با عدد وارد نمایید." +} diff --git a/hiddifypanel_bot/utils/__init__.py b/hiddifypanel_bot/utils/__init__.py new file mode 100644 index 0000000..d88d9e7 --- /dev/null +++ b/hiddifypanel_bot/utils/__init__.py @@ -0,0 +1 @@ +from .translation import setup_translation \ No newline at end of file diff --git a/hiddifypanel_bot/utils/translation.py b/hiddifypanel_bot/utils/translation.py new file mode 100644 index 0000000..488447c --- /dev/null +++ b/hiddifypanel_bot/utils/translation.py @@ -0,0 +1,8 @@ +def setup_translation(): + import i18n + import hiddifypanel_bot + i18n.load_path.append(hiddifypanel_bot.__path__[0]+'/translations') + i18n.set('file_format', 'json') + i18n.set('skip_locale_root_data',True) + i18n.set('filename_format', '{locale}.{format}') + i18n.set('placeholder_delimiter','$') \ No newline at end of file diff --git a/project.inlang/settings.json b/project.inlang/settings.json new file mode 100644 index 0000000..4f01054 --- /dev/null +++ b/project.inlang/settings.json @@ -0,0 +1,24 @@ +{ + "$schema": "https://inlang.com/schema/project-settings", + "sourceLanguageTag": "en", + "languageTags": [ + "en", + "pt", + "fa", + "ru", + "zh" + ], + "modules": [ + "https://cdn.jsdelivr.net/npm/@inlang/plugin-i18next@4/dist/index.js", + "https://cdn.jsdelivr.net/npm/@inlang/message-lint-rule-empty-pattern@1/dist/index.js", + "https://cdn.jsdelivr.net/npm/@inlang/message-lint-rule-identical-pattern@1/dist/index.js", + "https://cdn.jsdelivr.net/npm/@inlang/message-lint-rule-without-source@1/dist/index.js", + "https://cdn.jsdelivr.net/npm/@inlang/message-lint-rule-missing-translation@1/dist/index.js" + ], + "plugin.inlang.i18next": { + "pathPattern": "./hiddifypanel_bot/translations/{languageTag}.i18n.json", + "variableReferencePattern": [ + "@:" + ] + } + } \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index b05f2a6..41fa431 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,5 @@ # Add the requirements you need to this file. # or run `make init` to create this file automatically based on the template. # You can also run `make switch-to-poetry` to use the poetry package manager. + +i18nice==0.15.5 \ No newline at end of file