Files
Oxicloud/src/application/dtos/i18n_dto.rs
T

66 lines
1.6 KiB
Rust
Raw Normal View History

2025-03-17 21:28:08 +01:00
use crate::domain::services::i18n_service::Locale;
2026-02-14 01:29:34 +01:00
use serde::{Deserialize, Serialize};
2025-03-17 21:28:08 +01:00
/// DTO for locale information
#[derive(Debug, Serialize, Deserialize)]
pub struct LocaleDto {
/// Locale code (e.g., "en", "es")
pub code: String,
2026-02-14 01:29:34 +01:00
2025-03-17 21:28:08 +01:00
/// Locale name in its own language (e.g., "English", "Español")
pub name: String,
}
impl From<Locale> for LocaleDto {
fn from(locale: Locale) -> Self {
let (code, name) = match locale {
Locale::English => ("en", "English"),
Locale::Spanish => ("es", "Español"),
Locale::French => ("fr", "Français"),
Locale::German => ("de", "Deutsch"),
Locale::Portuguese => ("pt", "Português"),
2025-03-17 21:28:08 +01:00
};
2026-02-14 01:29:34 +01:00
2025-03-17 21:28:08 +01:00
Self {
code: code.to_string(),
name: name.to_string(),
}
}
}
/// DTO for translation request
#[derive(Debug, Deserialize)]
pub struct TranslationRequestDto {
/// The translation key
pub key: String,
2026-02-14 01:29:34 +01:00
2025-03-17 21:28:08 +01:00
/// The locale code (optional, defaults to "en")
pub locale: Option<String>,
}
/// DTO for translation response
#[derive(Debug, Serialize)]
pub struct TranslationResponseDto {
/// The translation key
pub key: String,
2026-02-14 01:29:34 +01:00
2025-03-17 21:28:08 +01:00
/// The locale code used for translation
pub locale: String,
2026-02-14 01:29:34 +01:00
2025-03-17 21:28:08 +01:00
/// The translated text
pub text: String,
}
/// DTO for translation error
#[derive(Debug, Serialize)]
pub struct TranslationErrorDto {
/// The translation key that was not found
pub key: String,
2026-02-14 01:29:34 +01:00
2025-03-17 21:28:08 +01:00
/// The locale code used for translation
pub locale: String,
2026-02-14 01:29:34 +01:00
2025-03-17 21:28:08 +01:00
/// The error message
pub error: String,
2026-02-14 01:29:34 +01:00
}