localizate add errors
This commit is contained in:
parent
95e39b72cf
commit
c1307aca0d
17
app/core/theme.py
Normal file
17
app/core/theme.py
Normal file
@ -0,0 +1,17 @@
|
||||
from PySide6.QtCore import QSettings
|
||||
|
||||
class ThemeManager:
|
||||
def __init__(self):
|
||||
self.settings = QSettings("yobble_messenger", "Theme")
|
||||
self.theme = self.settings.value("theme", "dark")
|
||||
|
||||
def is_dark(self):
|
||||
return self.theme == "dark"
|
||||
|
||||
def set_theme(self, theme: str):
|
||||
if theme in ("dark", "light"):
|
||||
self.theme = theme
|
||||
self.settings.setValue("theme", theme)
|
||||
|
||||
# Глобальный экземпляр
|
||||
theme_manager = ThemeManager()
|
||||
@ -14,5 +14,23 @@
|
||||
"Пожалуйста, исправьте ошибки в форме": "Please correct the form errors",
|
||||
"Неверный логин или пароль": "Incorrect username or password",
|
||||
"Пароли не совпадают": "Passwords do not match",
|
||||
"Регистрация прошла успешно для": "Successfully registered for"
|
||||
"Регистрация прошла успешно для": "Successfully registered for",
|
||||
|
||||
"Login must be between 3 and 32 characters long": "Login must be between 3 and 32 characters long",
|
||||
"Login must not contain whitespace characters": "Login must not contain whitespace characters",
|
||||
"Login must not start with an underscore": "Login must not start with an underscore",
|
||||
"Login must not contain consecutive underscores": "Login must not contain consecutive underscores",
|
||||
"Login must contain only English letters, digits, and underscores": "Login must contain only English letters, digits, and underscores",
|
||||
|
||||
"Invite must be between 3 and 32 characters long": "Invite must be between 3 and 32 characters long",
|
||||
"Invite must not contain whitespace characters": "Invite must not contain whitespace characters",
|
||||
"Invite must not start with an underscore": "Invite must not start with an underscore",
|
||||
"Invite must not contain consecutive underscores": "Invite must not contain consecutive underscores",
|
||||
"Invite must contain only English letters, digits, and underscores": "Invite must contain only English letters, digits, and underscores",
|
||||
|
||||
"Password must be between 8 and 128 characters long": "Password must be between 8 and 128 characters long",
|
||||
"Password must not contain whitespace characters": "Password must not contain whitespace characters",
|
||||
"Password must contain at least one uppercase letter": "Password must contain at least one uppercase letter",
|
||||
"Password must contain at least one digit": "Password must contain at least one digit",
|
||||
"Password must contain at least one special character": "Password must contain at least one special character"
|
||||
}
|
||||
|
||||
@ -14,5 +14,23 @@
|
||||
"Пожалуйста, исправьте ошибки в форме": "Пожалуйста, исправьте ошибки в форме",
|
||||
"Неверный логин или пароль": "Неверный логин или пароль",
|
||||
"Пароли не совпадают": "Пароли не совпадают",
|
||||
"Регистрация прошла успешно для": "Регистрация прошла успешно для"
|
||||
"Регистрация прошла успешно для": "Регистрация прошла успешно для",
|
||||
|
||||
"Login must be between 3 and 32 characters long": "Логин должен быть от 3 до 32 символов",
|
||||
"Login must not contain whitespace characters": "Логин не должен содержать пробелы",
|
||||
"Login must not start with an underscore": "Логин не должен начинаться с символа подчёркивания",
|
||||
"Login must not contain consecutive underscores": "Логин не должен содержать подряд идущие подчёркивания",
|
||||
"Login must contain only English letters, digits, and underscores": "Логин может содержать только английские буквы, цифры и подчёркивания",
|
||||
|
||||
"Invite must be between 3 and 32 characters long": "Инвайт-код должен быть от 3 до 32 символов",
|
||||
"Invite must not contain whitespace characters": "Инвайт-код не должен содержать пробелы",
|
||||
"Invite must not start with an underscore": "Инвайт-код не должен начинаться с символа подчёркивания",
|
||||
"Invite must not contain consecutive underscores": "Инвайт-код не должен содержать подряд идущие подчёркивания",
|
||||
"Invite must contain only English letters, digits, and underscores": "Инвайт-код может содержать только английские буквы, цифры и подчёркивания",
|
||||
|
||||
"Password must be between 8 and 128 characters long": "Пароль должен быть от 8 до 128 символов",
|
||||
"Password must not contain whitespace characters": "Пароль не должен содержать пробелы",
|
||||
"Password must contain at least one uppercase letter": "Пароль должен содержать хотя бы одну заглавную букву",
|
||||
"Password must contain at least one digit": "Пароль должен содержать хотя бы одну цифру",
|
||||
"Password must contain at least one special character": "Пароль должен содержать хотя бы один специальный символ"
|
||||
}
|
||||
|
||||
@ -9,37 +9,35 @@ from common_lib.utils.validators import (
|
||||
validate_password as common_validate_password
|
||||
)
|
||||
from app.core.localizer import localizer
|
||||
from app.core.theme import theme_manager
|
||||
|
||||
def validate_username(username, is_login=False):
|
||||
if is_login:
|
||||
if len(username) < 3 or len(username) > 32:
|
||||
msg = "Неверный логин или пароль (валидатор)"
|
||||
msg = localizer.translate("Неверный логин или пароль (валидатор)")
|
||||
return False, msg
|
||||
return True, username
|
||||
return common_validate_username(username, need_back=True)
|
||||
|
||||
is_validate, msg = common_validate_username(username, need_back=True)
|
||||
if not is_validate: msg = localizer.translate(msg)
|
||||
return is_validate, msg
|
||||
|
||||
def validate_invite_code(invite_code):
|
||||
# Login must be between 3 and 32 characters long
|
||||
# Login must not contain whitespace characters
|
||||
# Login must not start with an underscore
|
||||
# Login must not contain consecutive underscores
|
||||
# Login must contain only English letters, digits, and underscores
|
||||
is_validate, msg = common_validate_username(invite_code, field_name="invite", need_back=True)
|
||||
if not is_validate: msg = localizer.translate(msg)
|
||||
return is_validate, msg
|
||||
|
||||
# Invite must be between 3 and 32 characters long
|
||||
# Invite must not contain whitespace characters
|
||||
# Invite must not start with an underscore
|
||||
# Invite must not contain consecutive underscores
|
||||
# Invite must contain only English letters, digits, and underscores
|
||||
|
||||
return common_validate_username(invite_code, field_name="invite", need_back=True)
|
||||
|
||||
def validate_password(password, is_login=False):
|
||||
if is_login:
|
||||
if len(password) < 8 or len(password) > 128:
|
||||
msg = "Неверный логин или пароль (валидатор)"
|
||||
msg = localizer.translate("Неверный логин или пароль (валидатор)")
|
||||
return False, msg
|
||||
return True, password
|
||||
return common_validate_password(password, need_back=True)
|
||||
|
||||
is_validate, msg = common_validate_password(password, need_back=True)
|
||||
if not is_validate: msg = localizer.translate(msg)
|
||||
return is_validate, msg
|
||||
|
||||
def validate_name(name):
|
||||
# Optional field
|
||||
@ -54,15 +52,19 @@ class LoginView(QWidget):
|
||||
def __init__(self, on_login):
|
||||
super().__init__()
|
||||
self.on_login = on_login
|
||||
self.is_dark_theme = theme_manager.is_dark()
|
||||
print("self.is_dark_theme", self.is_dark_theme)
|
||||
self.setWindowTitle("yobble messenger")
|
||||
self.setFixedSize(400, 550)
|
||||
|
||||
self.is_dark_theme = True
|
||||
self.lang_combo = None
|
||||
self.is_registration = False
|
||||
|
||||
self.init_ui()
|
||||
self.apply_dark_theme()
|
||||
if self.is_dark_theme:
|
||||
self.apply_dark_theme()
|
||||
else:
|
||||
self.apply_light_theme()
|
||||
|
||||
def init_ui(self):
|
||||
# Переключатель темы и языка
|
||||
@ -265,6 +267,7 @@ class LoginView(QWidget):
|
||||
|
||||
def toggle_theme(self):
|
||||
self.is_dark_theme = not self.is_dark_theme
|
||||
theme_manager.set_theme("dark" if self.is_dark_theme else "light")
|
||||
if self.is_dark_theme:
|
||||
self.apply_dark_theme()
|
||||
else:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user