fix translate
This commit is contained in:
parent
53b90dc646
commit
f4266369f2
@ -60,7 +60,7 @@ class AuthService {
|
|||||||
request.httpBody = jsonData
|
request.httpBody = jsonData
|
||||||
} catch {
|
} catch {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
completion(false, NSLocalizedString("AuthService_error_serialization", comment: ""))
|
completion(false, NSLocalizedString("Не удалось сериализовать данные запроса.", comment: ""))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -68,32 +68,32 @@ class AuthService {
|
|||||||
let task = URLSession.shared.dataTask(with: request) { data, response, error in
|
let task = URLSession.shared.dataTask(with: request) { data, response, error in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
if let error = error {
|
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)
|
completion(false, errorMessage)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let httpResponse = response as? HTTPURLResponse else {
|
guard let httpResponse = response as? HTTPURLResponse else {
|
||||||
completion(false, NSLocalizedString("AuthService_error_invalid_response", comment: ""))
|
completion(false, NSLocalizedString("Некорректный ответ от сервера.", comment: ""))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
guard (200...299).contains(httpResponse.statusCode) else {
|
guard (200...299).contains(httpResponse.statusCode) else {
|
||||||
if httpResponse.statusCode == 401{
|
if httpResponse.statusCode == 401{
|
||||||
completion(false, NSLocalizedString("AuthService_error_invalid_credentials", comment: ""))
|
completion(false, NSLocalizedString("Неверный логин или пароль.", comment: ""))
|
||||||
} else if httpResponse.statusCode == 502{
|
} else if httpResponse.statusCode == 502{
|
||||||
completion(false, NSLocalizedString("AuthService_error_server_unavailable", comment: ""))
|
completion(false, NSLocalizedString("Сервер не отвечает. Попробуйте позже.", comment: ""))
|
||||||
} else if httpResponse.statusCode == 429 {
|
} else if httpResponse.statusCode == 429 {
|
||||||
completion(false, NSLocalizedString("AuthService_error_too_many_requests", comment: ""))
|
completion(false, NSLocalizedString("Слишком много запросов.", comment: ""))
|
||||||
} else {
|
} else {
|
||||||
let errorMessage = String(format: NSLocalizedString("AuthService_error_server_error", comment: ""), "\(httpResponse.statusCode)")
|
let errorMessage = String(format: NSLocalizedString("Ошибка сервера: %@", comment: ""), "\(httpResponse.statusCode)")
|
||||||
completion(false, errorMessage)
|
completion(false, errorMessage)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let data = data else {
|
guard let data = data else {
|
||||||
completion(false, NSLocalizedString("AuthService_error_empty_response", comment: ""))
|
completion(false, NSLocalizedString("Пустой ответ от сервера.", comment: ""))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ class AuthService {
|
|||||||
|
|
||||||
completion(true, nil)
|
completion(true, nil)
|
||||||
} catch {
|
} catch {
|
||||||
completion(false, NSLocalizedString("AuthService_error_parsing_response", comment: ""))
|
completion(false, NSLocalizedString("Не удалось обработать ответ сервера.", comment: ""))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ class AuthService {
|
|||||||
request.httpBody = jsonData
|
request.httpBody = jsonData
|
||||||
} catch {
|
} catch {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
completion(false, NSLocalizedString("AuthService_error_serialization", comment: ""))
|
completion(false, NSLocalizedString("Не удалось сериализовать данные запроса.", comment: ""))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -141,18 +141,18 @@ class AuthService {
|
|||||||
let task = URLSession.shared.dataTask(with: request) { data, response, error in
|
let task = URLSession.shared.dataTask(with: request) { data, response, error in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
if let error = error {
|
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)
|
completion(false, errorMessage)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let httpResponse = response as? HTTPURLResponse else {
|
guard let httpResponse = response as? HTTPURLResponse else {
|
||||||
completion(false, NSLocalizedString("AuthService_error_invalid_response", comment: ""))
|
completion(false, NSLocalizedString("Некорректный ответ от сервера.", comment: ""))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let data = data else {
|
guard let data = data else {
|
||||||
completion(false, NSLocalizedString("AuthService_error_empty_response", comment: ""))
|
completion(false, NSLocalizedString("Пустой ответ от сервера.", comment: ""))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,11 +169,11 @@ class AuthService {
|
|||||||
completion(true, "Регистрация и вход выполнены успешно.")
|
completion(true, "Регистрация и вход выполнены успешно.")
|
||||||
} else {
|
} else {
|
||||||
// Регистрация успешна, но логин не удался — покажем сообщение
|
// Регистрация успешна, но логин не удался — покажем сообщение
|
||||||
completion(false, loginMessage ?? NSLocalizedString("AuthService_login_success_but_failed", comment: ""))
|
completion(false, loginMessage ?? NSLocalizedString("Регистрация выполнена, но вход не удался.", comment: ""))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
completion(false, NSLocalizedString("AuthService_error_parsing_response", comment: ""))
|
completion(false, NSLocalizedString("Не удалось обработать ответ сервера.", comment: ""))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Ошибка сервера — пробуем распарсить message
|
// Ошибка сервера — пробуем распарсить message
|
||||||
@ -187,44 +187,44 @@ class AuthService {
|
|||||||
|
|
||||||
if httpResponse.statusCode == 400 {
|
if httpResponse.statusCode == 400 {
|
||||||
if message.contains("Invalid invitation code") {
|
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") {
|
} 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") {
|
} 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") {
|
} 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") {
|
} else if message.contains("Login already registered") {
|
||||||
completion(false, NSLocalizedString("AuthService_error_login_already_registered", comment: ""))
|
completion(false, NSLocalizedString("Логин уже занят.", comment: ""))
|
||||||
} else {
|
} else {
|
||||||
completion(false, message)
|
completion(false, message)
|
||||||
}
|
}
|
||||||
} else if httpResponse.statusCode == 403 {
|
} else if httpResponse.statusCode == 403 {
|
||||||
if message.contains("Registration is currently disabled") {
|
if message.contains("Registration is currently disabled") {
|
||||||
completion(false, NSLocalizedString("AuthService_error_registration_disabled", comment: ""))
|
completion(false, NSLocalizedString("Регистрация временно недоступна.", comment: ""))
|
||||||
} else {
|
} else {
|
||||||
completion(false, message)
|
completion(false, message)
|
||||||
}
|
}
|
||||||
} else if httpResponse.statusCode == 429 {
|
} else if httpResponse.statusCode == 429 {
|
||||||
completion(false, NSLocalizedString("AuthService_error_too_many_requests", comment: ""))
|
completion(false, NSLocalizedString("Слишком много запросов.", comment: ""))
|
||||||
} else if httpResponse.statusCode == 502{
|
} else if httpResponse.statusCode == 502{
|
||||||
completion(false, NSLocalizedString("AuthService_error_server_unavailable", comment: ""))
|
completion(false, NSLocalizedString("Сервер не отвечает. Попробуйте позже.", comment: ""))
|
||||||
} else {
|
} else {
|
||||||
let errorMessage = String(format: NSLocalizedString("AuthService_error_server_error", comment: ""), "\(httpResponse.statusCode)")
|
let errorMessage = String(format: NSLocalizedString("Ошибка сервера: %@", comment: ""), "\(httpResponse.statusCode)")
|
||||||
completion(false, errorMessage)
|
completion(false, errorMessage)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Не удалось распарсить JSON — fallback
|
// Не удалось распарсить JSON — fallback
|
||||||
if httpResponse.statusCode == 400 {
|
if httpResponse.statusCode == 400 {
|
||||||
completion(false, NSLocalizedString("AuthService_error_invalid_request", comment: ""))
|
completion(false, NSLocalizedString("Неверный запрос (400).", comment: ""))
|
||||||
} else if httpResponse.statusCode == 403 {
|
} else if httpResponse.statusCode == 403 {
|
||||||
completion(false, NSLocalizedString("AuthService_error_registration_forbidden", comment: ""))
|
completion(false, NSLocalizedString("Регистрация запрещена.", comment: ""))
|
||||||
} else if httpResponse.statusCode == 429 {
|
} else if httpResponse.statusCode == 429 {
|
||||||
completion(false, NSLocalizedString("AuthService_error_too_many_requests", comment: ""))
|
completion(false, NSLocalizedString("Слишком много запросов.", comment: ""))
|
||||||
} else if httpResponse.statusCode == 502{
|
} else if httpResponse.statusCode == 502{
|
||||||
completion(false, NSLocalizedString("AuthService_error_server_unavailable", comment: ""))
|
completion(false, NSLocalizedString("Сервер не отвечает. Попробуйте позже.", comment: ""))
|
||||||
} else {
|
} else {
|
||||||
let errorMessage = String(format: NSLocalizedString("AuthService_error_server_error", comment: ""), "\(httpResponse.statusCode)")
|
let errorMessage = String(format: NSLocalizedString("Ошибка сервера: %@", comment: ""), "\(httpResponse.statusCode)")
|
||||||
completion(false, errorMessage)
|
completion(false, errorMessage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,9 +6,6 @@
|
|||||||
},
|
},
|
||||||
"AuthService_error_empty_response" : {
|
"AuthService_error_empty_response" : {
|
||||||
|
|
||||||
},
|
|
||||||
"AuthService_error_invalid_credentials" : {
|
|
||||||
|
|
||||||
},
|
},
|
||||||
"AuthService_error_invalid_invitation_code" : {
|
"AuthService_error_invalid_invitation_code" : {
|
||||||
|
|
||||||
@ -115,24 +112,45 @@
|
|||||||
},
|
},
|
||||||
"Логин должен быть от 3 до 32 символов (английские буквы, цифры, _)" : {
|
"Логин должен быть от 3 до 32 символов (английские буквы, цифры, _)" : {
|
||||||
"comment" : "Логин должен быть от 3 до 32 символов (английские буквы, цифры, _)"
|
"comment" : "Логин должен быть от 3 до 32 символов (английские буквы, цифры, _)"
|
||||||
|
},
|
||||||
|
"Не удалось сериализовать данные запроса." : {
|
||||||
|
|
||||||
},
|
},
|
||||||
"Неверный логин" : {
|
"Неверный логин" : {
|
||||||
"comment" : "Неверный логин"
|
"comment" : "Неверный логин"
|
||||||
|
},
|
||||||
|
"Неверный логин или пароль." : {
|
||||||
|
|
||||||
},
|
},
|
||||||
"Неверный пароль" : {
|
"Неверный пароль" : {
|
||||||
"comment" : "Неверный пароль"
|
"comment" : "Неверный пароль"
|
||||||
|
},
|
||||||
|
"Неизвестная ошибка" : {
|
||||||
|
|
||||||
},
|
},
|
||||||
"Неизвестная ошибка." : {
|
"Неизвестная ошибка." : {
|
||||||
|
|
||||||
|
},
|
||||||
|
"Некорректный ответ от сервера." : {
|
||||||
|
|
||||||
},
|
},
|
||||||
"Нет аккаунта? Регистрация" : {
|
"Нет аккаунта? Регистрация" : {
|
||||||
"comment" : "Регистрация"
|
"comment" : "Регистрация"
|
||||||
},
|
},
|
||||||
"Ошибка авторизации" : {
|
"Ошибка авторизации" : {
|
||||||
|
|
||||||
|
},
|
||||||
|
"Ошибка при деавторизации." : {
|
||||||
|
|
||||||
},
|
},
|
||||||
"Ошибка регистрация" : {
|
"Ошибка регистрация" : {
|
||||||
"comment" : "Ошибка"
|
"comment" : "Ошибка"
|
||||||
|
},
|
||||||
|
"Ошибка сервера: %@" : {
|
||||||
|
|
||||||
|
},
|
||||||
|
"Ошибка сети: %@" : {
|
||||||
|
|
||||||
},
|
},
|
||||||
"Пароли не совпадают" : {
|
"Пароли не совпадают" : {
|
||||||
"comment" : "Пароли не совпадают"
|
"comment" : "Пароли не совпадают"
|
||||||
@ -145,9 +163,18 @@
|
|||||||
},
|
},
|
||||||
"Подтверждение пароля" : {
|
"Подтверждение пароля" : {
|
||||||
"comment" : "Подтверждение пароля"
|
"comment" : "Подтверждение пароля"
|
||||||
|
},
|
||||||
|
"Произошла ошибка." : {
|
||||||
|
|
||||||
},
|
},
|
||||||
"Регистрация" : {
|
"Регистрация" : {
|
||||||
"comment" : "Регистрация"
|
"comment" : "Регистрация"
|
||||||
|
},
|
||||||
|
"Сервер не отвечает. Попробуйте позже." : {
|
||||||
|
|
||||||
|
},
|
||||||
|
"Слишком много запросов." : {
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"version" : "1.0"
|
"version" : "1.0"
|
||||||
|
|||||||
@ -36,7 +36,7 @@ class LoginViewModel: ObservableObject {
|
|||||||
self?.isLoggedIn = true
|
self?.isLoggedIn = true
|
||||||
} else {
|
} else {
|
||||||
self?.isLoggedIn = false
|
self?.isLoggedIn = false
|
||||||
self?.errorMessage = error ?? "Произошла ошибка."
|
self?.errorMessage = error ?? NSLocalizedString("Произошла ошибка.", comment: "")
|
||||||
self?.showError = false
|
self?.showError = false
|
||||||
}
|
}
|
||||||
self?.isLoading = false
|
self?.isLoading = false
|
||||||
@ -55,7 +55,7 @@ class LoginViewModel: ObservableObject {
|
|||||||
if success {
|
if success {
|
||||||
self?.isLoggedIn = true
|
self?.isLoggedIn = true
|
||||||
} else {
|
} else {
|
||||||
self?.errorMessage = error ?? "Неизвестная ошибка"
|
self?.errorMessage = error ?? NSLocalizedString("Неизвестная ошибка", comment: "")
|
||||||
self?.showError = true
|
self?.showError = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ class LoginViewModel: ObservableObject {
|
|||||||
self?.username = ""
|
self?.username = ""
|
||||||
self?.password = ""
|
self?.password = ""
|
||||||
self?.isLoggedIn = false
|
self?.isLoggedIn = false
|
||||||
self?.errorMessage = error ?? "Ошибка при деавторизации."
|
self?.errorMessage = error ?? NSLocalizedString("Ошибка при деавторизации.", comment: "")
|
||||||
self?.showError = false
|
self?.showError = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,8 @@ import SwiftUI
|
|||||||
|
|
||||||
struct LoginView: View {
|
struct LoginView: View {
|
||||||
@ObservedObject var viewModel: LoginViewModel
|
@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
|
@State private var isShowingRegistration = false
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ struct LoginView: View {
|
|||||||
}
|
}
|
||||||
Spacer()
|
Spacer()
|
||||||
Button(action: toggleTheme) {
|
Button(action: toggleTheme) {
|
||||||
Image(systemName: isDarkMode ? "moon.fill" : "sun.max.fill")
|
Image(systemName: themeIconName)
|
||||||
.padding()
|
.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() {
|
private func toggleTheme() {
|
||||||
isDarkMode.toggle()
|
themeManager.toggleTheme(from: colorScheme)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func openLanguageSettings() {
|
private func openLanguageSettings() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user