Skip to main content

tablo_core/declaration/
locale.rs

1//! Why a panel's locales or translations cannot be served.
2
3use std::fmt;
4
5/// Why a panel's [`locales`](crate::Panel::locales) or
6/// [`translations`](crate::Panel::translations) cannot be served.
7#[derive(Debug, Clone, PartialEq, Eq)]
8#[non_exhaustive]
9pub enum LocaleFault {
10    /// `Panel::locales` lists no locale.
11    ///
12    /// List one at least: the first is the panel's default.
13    NoLocale,
14    /// `Panel::locales` lists a locale twice, or two names of one locale, as `iw` and `he`.
15    Duplicate {
16        /// The repeated locale.
17        tag: String,
18    },
19    /// `Panel::locales` lists a locale neither Tablo nor the app translates, so the panel would
20    /// render it in English.
21    ///
22    /// Add its catalog with `Panel::translations`, or drop it.
23    Untranslated {
24        /// The locale.
25        locale: String,
26    },
27    /// `Panel::translations` names a locale the panel does not offer, so no request reads it.
28    ///
29    /// Add it to `Panel::locales`, or drop the translations.
30    Unoffered {
31        /// The locale.
32        locale: String,
33    },
34    /// A catalog `Panel::translations` adds is not valid Fluent.
35    Syntax {
36        /// The catalog's locale.
37        locale: String,
38        /// Each parse error, with the line it starts on.
39        errors: Vec<String>,
40    },
41}
42
43impl fmt::Display for LocaleFault {
44    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45        match self {
46            Self::NoLocale => f.write_str(
47                "`Panel::locales` lists no locale: list one at least, the first being the default",
48            ),
49            Self::Duplicate { tag } => write!(
50                f,
51                "`Panel::locales` lists '{tag}' twice, maybe under another of its names, as `iw` for `he`"
52            ),
53            Self::Untranslated { locale } => write!(
54                f,
55                "locale '{locale}' has no catalog, so the panel would render it in English: add \
56                 one with `Panel::translations(locale!(\"{locale}\"), ..)`, or drop it from \
57                 `Panel::locales`"
58            ),
59            Self::Unoffered { locale } => write!(
60                f,
61                "`Panel::translations` adds a catalog for '{locale}', which `Panel::locales` does \
62                 not offer: add the locale, or drop the catalog"
63            ),
64            Self::Syntax { locale, errors } => write!(
65                f,
66                "the '{locale}' catalog is not valid Fluent: {}",
67                errors.join("; ")
68            ),
69        }
70    }
71}