Files
Oxicloud/src/application/services/i18n_application_service.rs
T

58 lines
1.8 KiB
Rust
Raw Normal View History

2025-03-17 21:28:08 +01:00
use std::sync::Arc;
2026-02-14 01:29:34 +01:00
use crate::domain::services::i18n_service::{I18nResult, I18nService, Locale};
use crate::infrastructure::services::file_system_i18n_service::FileSystemI18nService;
2025-03-17 21:28:08 +01:00
/// Service for i18n operations
pub struct I18nApplicationService {
i18n_service: Arc<FileSystemI18nService>,
2025-03-17 21:28:08 +01:00
}
impl I18nApplicationService {
2025-03-26 18:33:22 +01:00
/// Creates a dummy service for testing
pub fn dummy() -> Self {
2026-02-14 01:29:34 +01:00
Self {
i18n_service: Arc::new(FileSystemI18nService::dummy()),
2026-02-14 01:29:34 +01:00
}
2025-03-26 18:33:22 +01:00
}
2026-02-14 01:29:34 +01:00
2025-03-17 21:28:08 +01:00
/// Creates a new i18n application service
pub fn new(i18n_service: Arc<FileSystemI18nService>) -> Self {
2025-03-17 21:28:08 +01:00
Self { i18n_service }
}
2026-02-14 01:29:34 +01:00
2025-03-17 21:28:08 +01:00
/// Get a translation for a key and locale
pub async fn translate(&self, key: &str, locale: Option<Locale>) -> I18nResult<String> {
let locale = locale.unwrap_or_default();
2025-03-17 21:28:08 +01:00
self.i18n_service.translate(key, locale).await
}
2026-02-14 01:29:34 +01:00
2025-03-17 21:28:08 +01:00
/// Load translations for a locale
pub async fn load_translations(&self, locale: Locale) -> I18nResult<()> {
self.i18n_service.load_translations(locale).await
}
2026-02-14 01:29:34 +01:00
2025-03-17 21:28:08 +01:00
/// Load translations for all available locales
pub async fn load_all_translations(&self) -> Vec<(Locale, I18nResult<()>)> {
let locales = self.i18n_service.available_locales().await;
let mut results = Vec::new();
2026-02-14 01:29:34 +01:00
2025-03-17 21:28:08 +01:00
for locale in locales {
let result = self.i18n_service.load_translations(locale).await;
results.push((locale, result));
}
2026-02-14 01:29:34 +01:00
2025-03-17 21:28:08 +01:00
results
}
2026-02-14 01:29:34 +01:00
2025-03-17 21:28:08 +01:00
/// Get available locales
pub async fn available_locales(&self) -> Vec<Locale> {
self.i18n_service.available_locales().await
}
2026-02-14 01:29:34 +01:00
2025-03-17 21:28:08 +01:00
/// Check if a locale is supported
pub async fn is_supported(&self, locale: Locale) -> bool {
self.i18n_service.is_supported(locale).await
}
2026-02-14 01:29:34 +01:00
}