use serde::{Deserialize, Serialize}; use sqlx::Decode; use strum::{EnumIter, EnumString}; /// Languages represented as /// [ISO 639-3 codes](https://en.wikipedia.org/wiki/List_of_ISO_639-3_codes). #[derive( Clone, Debug, Decode, Deserialize, strum::Display, PartialEq, Serialize, EnumIter, EnumString, )] #[serde(rename_all = "lowercase")] #[strum(serialize_all = "lowercase")] // [`sqlx`] implements Decode and Encode to/from the Postgres `TEXT` type based // on the [`std::fmt::Display`] and [`std::str::FromStr`] traits, so it should // use the transformations applied by [`strum`]. // pub enum Language { Deu, Eng, Spa, } impl Default for Language { /// Language defaults to English when necessary, as the product is being /// developed with a primarily English speaking/reading/writing market in /// mind. fn default() -> Self { Self::Eng } } impl Language { pub fn as_locale_str(&self) -> &'static str { match self { Self::Deu => "Deutsch", Self::Eng => "English", Self::Spa => "EspaƱol", } } }