use i18n_core::Catalog;
use ui_core::{AssetDecoder, AssetError};
pub struct CatalogDecoder {
locale: String,
}
impl CatalogDecoder {
pub fn new(locale: impl Into<String>) -> Self {
Self {
locale: locale.into(),
}
}
}
impl AssetDecoder for CatalogDecoder {
fn kind(&self) -> &'static str {
"catalog"
}
type Output = &'static Catalog;
fn decode(&self, bytes: &[u8]) -> Result<Self::Output, AssetError> {
let text = std::str::from_utf8(bytes)
.map_err(|e| AssetError(format!("catalog is not valid utf-8: {e}")))?;
Catalog::from_toml(&self.locale, text).map_err(AssetError)
}
}
#[cfg(test)]
#[path = "catalog_test.rs"]
mod tests;