fix translate

This commit is contained in:
cheykrym 2025-10-05 03:25:45 +03:00
parent 53b90dc646
commit f4266369f2
4 changed files with 77 additions and 38 deletions

View File

@ -60,7 +60,7 @@ class AuthService {
request.httpBody = jsonData
} catch {
DispatchQueue.main.async {
completion(false, NSLocalizedString("AuthService_error_serialization", comment: ""))
completion(false, NSLocalizedString("Не удалось сериализовать данные запроса.", comment: ""))
}
return
}
@ -68,32 +68,32 @@ class AuthService {
let task = URLSession.shared.dataTask(with: request) { data, response, error in
DispatchQueue.main.async {
if let error = error {
let errorMessage = String(format: NSLocalizedString("AuthService_error_network", comment: ""), error.localizedDescription)
let errorMessage = String(format: NSLocalizedString("Ошибка сети: %@", comment: ""), error.localizedDescription)
completion(false, errorMessage)
return
}
guard let httpResponse = response as? HTTPURLResponse else {
completion(false, NSLocalizedString("AuthService_error_invalid_response", comment: ""))
completion(false, NSLocalizedString("Некорректный ответ от сервера.", comment: ""))
return
}
guard (200...299).contains(httpResponse.statusCode) else {
if httpResponse.statusCode == 401{
completion(false, NSLocalizedString("AuthService_error_invalid_credentials", comment: ""))
completion(false, NSLocalizedString("Неверный логин или пароль.", comment: ""))
} else if httpResponse.statusCode == 502{
completion(false, NSLocalizedString("AuthService_error_server_unavailable", comment: ""))
completion(false, NSLocalizedString("Сервер не отвечает. Попробуйте позже.", comment: ""))
} else if httpResponse.statusCode == 429 {
completion(false, NSLocalizedString("AuthService_error_too_many_requests", comment: ""))
completion(false, NSLocalizedString("Слишком много запросов.", comment: ""))
} else {
let errorMessage = String(format: NSLocalizedString("AuthService_error_server_error", comment: ""), "\(httpResponse.statusCode)")
let errorMessage = String(format: NSLocalizedString("Ошибка сервера: %@", comment: ""), "\(httpResponse.statusCode)")
completion(false, errorMessage)
}
return
}
guard let data = data else {
completion(false, NSLocalizedString("AuthService_error_empty_response", comment: ""))
completion(false, NSLocalizedString("Пустой ответ от сервера.", comment: ""))
return
}
@ -108,7 +108,7 @@ class AuthService {
completion(true, nil)
} catch {
completion(false, NSLocalizedString("AuthService_error_parsing_response", comment: ""))
completion(false, NSLocalizedString("Не удалось обработать ответ сервера.", comment: ""))
}
}
}
@ -133,7 +133,7 @@ class AuthService {
request.httpBody = jsonData
} catch {
DispatchQueue.main.async {
completion(false, NSLocalizedString("AuthService_error_serialization", comment: ""))
completion(false, NSLocalizedString("Не удалось сериализовать данные запроса.", comment: ""))
}
return
}
@ -141,18 +141,18 @@ class AuthService {
let task = URLSession.shared.dataTask(with: request) { data, response, error in
DispatchQueue.main.async {
if let error = error {
let errorMessage = String(format: NSLocalizedString("AuthService_error_network", comment: ""), error.localizedDescription)
let errorMessage = String(format: NSLocalizedString("Ошибка сети: %@", comment: ""), error.localizedDescription)
completion(false, errorMessage)
return
}
guard let httpResponse = response as? HTTPURLResponse else {
completion(false, NSLocalizedString("AuthService_error_invalid_response", comment: ""))
completion(false, NSLocalizedString("Некорректный ответ от сервера.", comment: ""))
return
}
guard let data = data else {
completion(false, NSLocalizedString("AuthService_error_empty_response", comment: ""))
completion(false, NSLocalizedString("Пустой ответ от сервера.", comment: ""))
return
}
@ -169,11 +169,11 @@ class AuthService {
completion(true, "Регистрация и вход выполнены успешно.")
} else {
// Регистрация успешна, но логин не удался покажем сообщение
completion(false, loginMessage ?? NSLocalizedString("AuthService_login_success_but_failed", comment: ""))
completion(false, loginMessage ?? NSLocalizedString("Регистрация выполнена, но вход не удался.", comment: ""))
}
}
} catch {
completion(false, NSLocalizedString("AuthService_error_parsing_response", comment: ""))
completion(false, NSLocalizedString("Не удалось обработать ответ сервера.", comment: ""))
}
} else {
// Ошибка сервера пробуем распарсить message
@ -187,44 +187,44 @@ class AuthService {
if httpResponse.statusCode == 400 {
if message.contains("Invalid invitation code") {
completion(false, NSLocalizedString("AuthService_error_invalid_invitation_code", comment: ""))
completion(false, NSLocalizedString("Неверный код приглашения.", comment: ""))
} else if message.contains("This invitation is not active") {
completion(false, NSLocalizedString("AuthService_error_invitation_not_active", comment: ""))
completion(false, NSLocalizedString("Приглашение не активно.", comment: ""))
} else if message.contains("This invitation has reached its usage limit") {
completion(false, NSLocalizedString("AuthService_error_invitation_usage_limit", comment: ""))
completion(false, NSLocalizedString("Приглашение достигло лимита использования.", comment: ""))
} else if message.contains("This invitation has expired") {
completion(false, NSLocalizedString("AuthService_error_invitation_expired", comment: ""))
completion(false, NSLocalizedString("Приглашение истекло.", comment: ""))
} else if message.contains("Login already registered") {
completion(false, NSLocalizedString("AuthService_error_login_already_registered", comment: ""))
completion(false, NSLocalizedString("Логин уже занят.", comment: ""))
} else {
completion(false, message)
}
} else if httpResponse.statusCode == 403 {
if message.contains("Registration is currently disabled") {
completion(false, NSLocalizedString("AuthService_error_registration_disabled", comment: ""))
completion(false, NSLocalizedString("Регистрация временно недоступна.", comment: ""))
} else {
completion(false, message)
}
} else if httpResponse.statusCode == 429 {
completion(false, NSLocalizedString("AuthService_error_too_many_requests", comment: ""))
completion(false, NSLocalizedString("Слишком много запросов.", comment: ""))
} else if httpResponse.statusCode == 502{
completion(false, NSLocalizedString("AuthService_error_server_unavailable", comment: ""))
completion(false, NSLocalizedString("Сервер не отвечает. Попробуйте позже.", comment: ""))
} else {
let errorMessage = String(format: NSLocalizedString("AuthService_error_server_error", comment: ""), "\(httpResponse.statusCode)")
let errorMessage = String(format: NSLocalizedString("Ошибка сервера: %@", comment: ""), "\(httpResponse.statusCode)")
completion(false, errorMessage)
}
} else {
// Не удалось распарсить JSON fallback
if httpResponse.statusCode == 400 {
completion(false, NSLocalizedString("AuthService_error_invalid_request", comment: ""))
completion(false, NSLocalizedString("Неверный запрос (400).", comment: ""))
} else if httpResponse.statusCode == 403 {
completion(false, NSLocalizedString("AuthService_error_registration_forbidden", comment: ""))
completion(false, NSLocalizedString("Регистрация запрещена.", comment: ""))
} else if httpResponse.statusCode == 429 {
completion(false, NSLocalizedString("AuthService_error_too_many_requests", comment: ""))
completion(false, NSLocalizedString("Слишком много запросов.", comment: ""))
} else if httpResponse.statusCode == 502{
completion(false, NSLocalizedString("AuthService_error_server_unavailable", comment: ""))
completion(false, NSLocalizedString("Сервер не отвечает. Попробуйте позже.", comment: ""))
} else {
let errorMessage = String(format: NSLocalizedString("AuthService_error_server_error", comment: ""), "\(httpResponse.statusCode)")
let errorMessage = String(format: NSLocalizedString("Ошибка сервера: %@", comment: ""), "\(httpResponse.statusCode)")
completion(false, errorMessage)
}
}

View File

@ -6,9 +6,6 @@
},
"AuthService_error_empty_response" : {
},
"AuthService_error_invalid_credentials" : {
},
"AuthService_error_invalid_invitation_code" : {
@ -115,24 +112,45 @@
},
"Логин должен быть от 3 до 32 символов (английские буквы, цифры, _)" : {
"comment" : "Логин должен быть от 3 до 32 символов (английские буквы, цифры, _)"
},
"Не удалось сериализовать данные запроса." : {
},
"Неверный логин" : {
"comment" : "Неверный логин"
},
"Неверный логин или пароль." : {
},
"Неверный пароль" : {
"comment" : "Неверный пароль"
},
"Неизвестная ошибка" : {
},
"Неизвестная ошибка." : {
},
"Некорректный ответ от сервера." : {
},
"Нет аккаунта? Регистрация" : {
"comment" : "Регистрация"
},
"Ошибка авторизации" : {
},
"Ошибка при деавторизации." : {
},
"Ошибка регистрация" : {
"comment" : "Ошибка"
},
"Ошибка сервера: %@" : {
},
"Ошибка сети: %@" : {
},
"Пароли не совпадают" : {
"comment" : "Пароли не совпадают"
@ -145,9 +163,18 @@
},
"Подтверждение пароля" : {
"comment" : "Подтверждение пароля"
},
"Произошла ошибка." : {
},
"Регистрация" : {
"comment" : "Регистрация"
},
"Сервер не отвечает. Попробуйте позже." : {
},
"Слишком много запросов." : {
}
},
"version" : "1.0"

View File

@ -36,7 +36,7 @@ class LoginViewModel: ObservableObject {
self?.isLoggedIn = true
} else {
self?.isLoggedIn = false
self?.errorMessage = error ?? "Произошла ошибка."
self?.errorMessage = error ?? NSLocalizedString("Произошла ошибка.", comment: "")
self?.showError = false
}
self?.isLoading = false
@ -55,7 +55,7 @@ class LoginViewModel: ObservableObject {
if success {
self?.isLoggedIn = true
} else {
self?.errorMessage = error ?? "Неизвестная ошибка"
self?.errorMessage = error ?? NSLocalizedString("Неизвестная ошибка", comment: "")
self?.showError = true
}
}
@ -85,7 +85,7 @@ class LoginViewModel: ObservableObject {
self?.username = ""
self?.password = ""
self?.isLoggedIn = false
self?.errorMessage = error ?? "Ошибка при деавторизации."
self?.errorMessage = error ?? NSLocalizedString("Ошибка при деавторизации.", comment: "")
self?.showError = false
}
}

View File

@ -9,7 +9,8 @@ import SwiftUI
struct LoginView: View {
@ObservedObject var viewModel: LoginViewModel
@AppStorage("isDarkMode") private var isDarkMode: Bool = true
@EnvironmentObject private var themeManager: ThemeManager
@Environment(\.colorScheme) private var colorScheme
@State private var isShowingRegistration = false
@ -40,7 +41,7 @@ struct LoginView: View {
}
Spacer()
Button(action: toggleTheme) {
Image(systemName: isDarkMode ? "moon.fill" : "sun.max.fill")
Image(systemName: themeIconName)
.padding()
}
}
@ -148,8 +149,19 @@ struct LoginView: View {
private var themeIconName: String {
switch themeManager.theme {
case .system:
return colorScheme == .dark ? "moon.fill" : "sun.max.fill"
case .light:
return "sun.max.fill"
case .dark:
return "moon.fill"
}
}
private func toggleTheme() {
isDarkMode.toggle()
themeManager.toggleTheme(from: colorScheme)
}
private func openLanguageSettings() {