i18n+filtering fork - fluent-templates v2
at main 37 lines 1.2 kB view raw
1use fluent::{FluentError}; 2use fluent_syntax::parser::ParserError; 3use std::error::Error; 4use std::fmt; 5use unic_langid::LanguageIdentifier; 6 7#[derive(Debug)] 8pub enum I18nError { 9 InvalidLanguage, 10 LanguageResourceFailed(Vec<ParserError>), 11 BundleLoadFailed(Vec<FluentError>), 12 TemplateError(String), 13 MissingTranslation { 14 locale: LanguageIdentifier, 15 message_id: String, 16 }, 17} 18 19impl fmt::Display for I18nError { 20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 21 match self { 22 I18nError::InvalidLanguage => write!(f, "Invalid language identifier"), 23 I18nError::LanguageResourceFailed(errors) => { 24 write!(f, "Failed to parse language resource: {:?}", errors) 25 } 26 I18nError::BundleLoadFailed(errors) => { 27 write!(f, "Failed to load bundle: {:?}", errors) 28 } 29 I18nError::TemplateError(msg) => write!(f, "Template error: {}", msg), 30 I18nError::MissingTranslation { locale, message_id } => { 31 write!(f, "Missing translation for '{}' in locale '{}'", message_id, locale) 32 } 33 } 34 } 35} 36 37impl Error for I18nError {}