use crate::Lang;
#[derive(Debug, Clone, Copy)]
pub struct Source {
lang: Lang,
ftl: &'static str,
}
impl Source {
pub const fn new(lang: Lang, ftl: &'static str) -> Source {
Source { lang, ftl }
}
pub const fn lang(&self) -> Lang {
self.lang
}
pub const fn ftl(&self) -> &'static str {
self.ftl
}
}
#[derive(Debug, Clone, Copy)]
pub struct Catalog {
name: &'static str,
prefix: Option<&'static str>,
sources: &'static [Source],
}
impl Catalog {
pub const fn new(name: &'static str, sources: &'static [Source]) -> Catalog {
Catalog {
name,
prefix: None,
sources,
}
}
pub const fn with_prefix(self, prefix: &'static str) -> Catalog {
Catalog {
prefix: Some(prefix),
..self
}
}
pub const fn name(&self) -> &'static str {
self.name
}
pub const fn prefix(&self) -> Option<&'static str> {
self.prefix
}
pub const fn sources(&self) -> &'static [Source] {
self.sources
}
pub fn default_lang(&self) -> Option<Lang> {
self.sources.first().map(Source::lang)
}
pub fn languages(&self) -> impl Iterator<Item = Lang> {
self.sources.iter().map(Source::lang)
}
pub fn source(&self, lang: Lang) -> Option<&'static Source> {
self.sources.iter().find(|s| s.lang == lang)
}
}