phonograph/interim-models/src/language.rs

40 lines
1.1 KiB
Rust
Raw Normal View History

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`].
// <https://docs.rs/sqlx/latest/sqlx/types/struct.Text.html>
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",
}
}
}