add locales

This commit is contained in:
unknown 2025-09-06 06:07:14 +03:00
parent ae071d9cdb
commit 48b833d449
3 changed files with 221 additions and 0 deletions

43
app/core/localizer.py Normal file
View File

@ -0,0 +1,43 @@
import json
import os
from PySide6.QtCore import QSettings
import config
class Localizer:
"""Класс для загрузки и работы с переводами"""
def __init__(self):
self.settings = QSettings("volna_desktop_app", "Localization")
self.lang = self.settings.value("language", "ru") # Загружаем сохраненный язык
#self.locales_path = os.path.join(os.path.dirname(__file__), "locales")
self.locales_path = os.path.join("app/locales")
self.translations = {}
self.load_language(self.lang)
def load_language(self, lang):
"""Загружает перевод из JSON-файла"""
lang_file = os.path.join(self.locales_path, f"{lang}.json")
if os.path.exists(lang_file):
with open(lang_file, "r", encoding="utf-8") as file:
self.translations = json.load(file)
self.lang = lang
self.settings.setValue("language", lang) # Сохраняем выбор языка
if config.DEBUG: print(f"[Localizer.load_language] ✅ Язык загружен: {lang}")
else:
if config.DEBUG: print(f"[Localizer.load_language] ❌ Файл локализации не найден: {lang_file}")
def translate(self, key, code=None):
"""Возвращает перевод слова"""
text = self.translations.get(key, key)
if code is not None:
text = f"{text} {code}" # Подставляем код ошибки в строку, если он есть
return text
def switch_language(self, lang):
"""Переключает языки"""
if lang not in ["ru", "en"]:
lang = "ru"
self.load_language(lang)
# Создаем глобальный экземпляр, чтобы использовать в любом месте
localizer = Localizer()

67
app/locales/en.json Normal file
View File

@ -0,0 +1,67 @@
{
"title_error": "Error",
"auth_qLabel_text": "Volna",
"auth_title_login_windows": "Вход",
"auth_placeholder_text_login": "Email or number",
"auth_placeholder_text_password": "Password",
"auth_button_sign_in": "Sign in",
"auth_service_ping_error_else1": "⚠️ Server unavailable",
"auth_service_ping_error_exception1": "⚠️ Server unreachable",
"auth_service_login_error_else1": "🔴 Authentication error",
"auth_service_login_error_exception1": "🔴 Server connection failed",
"auth_service_user_not_employee_else1": "You are not an employee",
"auth_service_user_not_employee_exception1": "User validation error",
"json_output_data_error": "❌ Error",
"json_output_data_details": "❌ Error description",
"json_output_data_diagnosis": "📋 Diagnosis",
"json_output_data_recommendations": "💡 Recommendations",
"json_output_data_apri": "🎯 APRI",
"json_output_data_fib4": "🎯 FIB4",
"json_output_data_child_pugh_score": "🎯 Child-Pugh Score",
"json_output_data_child_pugh_class": "🎯 Child-Pugh Class",
"json_input_data_code_name": "🔍 Analysis code",
"json_input_data_parameters": "📊 Parameters",
"json_input_data_AST": "🩸 AST (U/L)",
"json_input_data_ALT": "🩸 ALT (U/L)",
"json_input_data_Platelets": "🩸 Platelets (×10⁹/L)",
"json_input_data_Bilirubin": "🟡 Bilirubin (mg/dL)",
"json_input_data_Albumin": "⚪ Albumin (g/dL)",
"json_input_data_Age": "👶 Age",
"json_input_data_AST_ULN": "🔼 AST (Upper Limit)",
"json_input_data_Ascites": "💧 Ascites",
"json_input_data_Jaundice": "🟡 Jaundice",
"json_input_data_Encephalopathy": "🧠 Encephalopathy",
"json_input_data_LiverFibrosis": "🔄 Liver Fibrosis",
"json_input_data_GGT": "🟢 GGT (U/L)",
"json_input_data_ALP": "🔵 ALP (U/L)",
"json_input_data_INR": "🩸 INR",
"json_input_data_CRP": "🔴 CRP (mg/L)",
"json_input_data_Ferritin": "🟠 Ferritin (ng/mL)",
"none": "❌ None",
"False": "❌ No",
"True": "✅ Yes",
"test_status_-1": "❌ Error",
"test_status_0": "🆕 New",
"test_status_1": "⚙️ In Progress",
"test_status_2": "✅ Completed",
"no cirrhosis": "No cirrhosis",
"possible cirrhosis": "Possible cirrhosis",
"high risk of cirrhosis": "High risk of cirrhosis",
"monitor liver function": "Monitor liver function",
"consult hepatologist": "Consult a hepatologist",
"immediate medical attention required": "Immediate medical attention required",
"Possible cholestasis detected": "Possible cholestasis detected",
"Possible liver failure detected": "Possible liver failure detected",
"Possible inflammatory liver disease": "Possible inflammatory liver disease",
"A (Compensated)": "Class A (Compensated Cirrhosis)",
"B (Decompensated)": "Class B (Decompensated Cirrhosis)",
"C (Severe Decompensated)": "Class C (Severe Decompensated Cirrhosis)"
}

111
app/locales/ru.json Normal file
View File

@ -0,0 +1,111 @@
{
"title_error": "Ошибка",
"auth_qLabel_text": "Volna",
"auth_title_login_windows": "Вход",
"auth_placeholder_text_login": "Почта или номер",
"auth_placeholder_text_password": "Пароль",
"auth_button_sign_in": "Войти",
"auth_service_ping_error_else1": "⚠️ Сервер недоступен",
"auth_service_ping_error_exception1": "⚠️ Сервер недоступен",
"auth_service_login_error_else1": "🔴 Ошибка авторизации",
"auth_service_login_error_exception1": "🔴 Ошибка подключения к серверу",
"auth_service_user_not_employee_else1": "Вы не являетесь сотрудником",
"auth_service_user_not_employee_exception1": "Ошибка проверки пользователя",
"json_output_data_error": "❌ Ошибка",
"json_output_data_details": "❌ Описание ошибки",
"json_output_data_diagnosis": "📋 Диагноз",
"json_output_data_recommendations": "💡 Рекомендации",
"json_output_data_apri": "🎯 APRI",
"json_output_data_fib4": "🎯 FIB4",
"json_output_data_child_pugh_score": "🎯 Чайлд-Пью Баллы",
"json_output_data_child_pugh_class": "🎯 Чайлд-Пью Класс",
"json_input_data_code_name": "🔍 Код анализа",
"json_input_data_parameters": "📊 Параметры",
"json_input_data_AST": "🩸 AST (Ед/л)",
"json_input_data_ALT": "🩸 ALT (Ед/л)",
"json_input_data_Platelets": "🩸 Тромбоциты (×10⁹/л)",
"json_input_data_Bilirubin": "🟡 Билирубин (мг/дл)",
"json_input_data_Albumin": "⚪ Альбумин (г/дл)",
"json_input_data_Age": "👶 Возраст",
"json_input_data_AST_ULN": "🔼 AST (верхний предел)",
"json_input_data_Ascites": "💧 Асцит",
"json_input_data_Jaundice": "🟡 Желтуха",
"json_input_data_Encephalopathy": "🧠 Энцефалопатия",
"json_input_data_LiverFibrosis": "🔄 Фиброз печени",
"json_input_data_GGT": "🟢 GGT (Ед/л)",
"json_input_data_ALP": "🔵 ALP (Ед/л)",
"json_input_data_INR": "🩸 INR",
"json_input_data_CRP": "🔴 CRP (мг/л)",
"json_input_data_Ferritin": "🟠 Ферритин (нг/мл)",
"AST": "AST (Ед/л)",
"ALT": "ALT (Ед/л)",
"Platelets": "Тромбоциты (×10⁹/л)",
"Bilirubin": "Билирубин (мг/дл)",
"Albumin": "Альбумин (г/дл)",
"Age": "Возраст",
"AST_ULN": "AST (верхний предел)",
"Ascites": "Асцит",
"Jaundice": "Желтуха",
"Encephalopathy": "Энцефалопатия",
"LiverFibrosis": "Фиброз печени",
"GGT": "GGT (Ед/л)",
"ALP": "ALP (Ед/л)",
"INR": "INR",
"CRP": "CRP (мг/л)",
"Ferritin": "Ферритин (нг/мл)",
"json_input_data_True": "да",
"json_input_data_False": "нет",
"json_input_data_mild": "легкая",
"json_input_data_moderate": "умеренный",
"json_input_data_severe": "тяжелая",
"json_output_data_dynamic_forecast": "📈 Аналитика",
"json_output_data_dynamic_forecast_slope": "Темпы изменения",
"json_output_data_dynamic_forecast_interpretation": "💬 Интерпретации",
"json_output_data_slope": "📈 Прогнозирование рисков:",
"json_output_data_slope_apri": "📈 Изменения APRI",
"json_output_data_slope_fib4": "📈 Изменения FIB-4",
"json_output_data_slope_child_pugh": "📈 Изменения Чайлд-Пью",
"json_output_data_slope_childpugh": "📈 Изменения Чайлд-Пью",
"json_output_data_slope_ChildPugh": "📈 Изменения Чайлд-Пью",
"advanced fibrosis or early cirrhosis": "Продвинутый фиброз или ранний цирроз",
"consider elastography or biopsy": "Рассмотреть эластографию или биопсию",
"json_output_data_dynamic_forecast_slope_apri": "📈 Изменения APRI",
"json_output_data_dynamic_forecast_slope_APRI": "📈 Изменения APRI",
"json_output_data_dynamic_forecast_slope_fib4": "📈 Изменения FIB-4",
"json_output_data_dynamic_forecast_slope_FIB4": "📈 Изменения FIB-4",
"json_output_data_dynamic_forecast_slope_childpugh": "📈 Изменения Чайлд-Пью",
"json_output_data_dynamic_forecast_slope_ChildPugh": "📈 Изменения Чайлд-Пью",
"none": "❌ Нет",
"False": "❌ Нет",
"True": "✅ Да",
"test_status_-1": "❌ Ошибка",
"test_status_0": "🆕 Новый",
"test_status_1": "⚙️ В работе",
"test_status_2": "✅ Завершен",
"no cirrhosis": "Нет цирроза",
"possible cirrhosis": "Возможный цирроз",
"high risk of cirrhosis": "Высокий риск цирроза",
"monitor liver function": "Мониторинг функции печени",
"consult hepatologist": "Консультация с гепатологом",
"immediate medical attention required": "Требуется немедленная медицинская помощь",
"Possible cholestasis detected": "Возможен холестаз",
"Possible liver failure detected": "Возможна печёночная недостаточность",
"Possible inflammatory liver disease": "Возможное воспалительное заболевание печени",
"A (Compensated)": "Класс A (Компенсированный цирроз)",
"B (Decompensated)": "Класс B (Декомпенсированный цирроз)",
"C (Severe Decompensated)": "Класс C (Тяжёлый декомпенсированный цирроз)"
}