use std::sync::Arc;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct InputWords {
pub signature: Arc<str>,
pub angle: Arc<str>,
pub sign_above_the_line: Arc<str>,
pub signed: Arc<str>,
pub not_signed: Arc<str>,
pub undo: Arc<str>,
pub clear: Arc<str>,
pub available: Arc<str>,
pub selected: Arc<str>,
pub select_all: Arc<str>,
pub add: Arc<str>,
pub remove: Arc<str>,
pub no_items: Arc<str>,
pub no_options: Arc<str>,
pub loading: Arc<str>,
}
impl InputWords {
fn of(words: [&str; 15]) -> Self {
let [
signature,
angle,
sign_above_the_line,
signed,
not_signed,
undo,
clear,
available,
selected,
select_all,
add,
remove,
no_items,
no_options,
loading,
] = words.map(Arc::from);
Self {
signature,
angle,
sign_above_the_line,
signed,
not_signed,
undo,
clear,
available,
selected,
select_all,
add,
remove,
no_items,
no_options,
loading,
}
}
pub fn english() -> Self {
Self::of([
"Signature",
"Angle",
"Sign above the line",
"Signed",
"Not signed",
"Undo",
"Clear",
"Available",
"Selected",
"Select all",
"Add",
"Remove",
"No items",
"No options",
"Loading",
])
}
pub fn for_language(language: &str) -> Self {
match language {
"uk" => Self::of([
"Підпис",
"Кут",
"Підпишіть над лінією",
"Підписано",
"Не підписано",
"Скасувати",
"Очистити",
"Доступні",
"Вибрані",
"Вибрати все",
"Додати",
"Прибрати",
"Немає елементів",
"Немає варіантів",
"Завантаження",
]),
"de" => Self::of([
"Unterschrift",
"Winkel",
"Über der Linie unterschreiben",
"Unterschrieben",
"Nicht unterschrieben",
"Rückgängig",
"Löschen",
"Verfügbar",
"Ausgewählt",
"Alle auswählen",
"Hinzufügen",
"Entfernen",
"Keine Einträge",
"Keine Optionen",
"Wird geladen",
]),
"fr" => Self::of([
"Signature",
"Angle",
"Signez au-dessus de la ligne",
"Signé",
"Non signé",
"Annuler",
"Effacer",
"Disponibles",
"Sélectionnés",
"Tout sélectionner",
"Ajouter",
"Retirer",
"Aucun élément",
"Aucune option",
"Chargement",
]),
"es" => Self::of([
"Firma",
"Ángulo",
"Firme sobre la línea",
"Firmado",
"Sin firmar",
"Deshacer",
"Borrar",
"Disponibles",
"Seleccionados",
"Seleccionar todo",
"Añadir",
"Quitar",
"Sin elementos",
"Sin opciones",
"Cargando",
]),
"pl" => Self::of([
"Podpis",
"Kąt",
"Podpisz nad linią",
"Podpisano",
"Nie podpisano",
"Cofnij",
"Wyczyść",
"Dostępne",
"Wybrane",
"Zaznacz wszystko",
"Dodaj",
"Usuń",
"Brak elementów",
"Brak opcji",
"Ładowanie",
]),
_ => Self::english(),
}
}
}
impl Default for InputWords {
fn default() -> Self {
Self::english()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_language_has_every_word_and_another_is_english() {
for language in ["en", "uk", "de", "fr", "es", "pl"] {
let words = InputWords::for_language(language);
let all = [
&words.signature,
&words.angle,
&words.sign_above_the_line,
&words.signed,
&words.not_signed,
&words.undo,
&words.clear,
&words.available,
&words.selected,
&words.select_all,
&words.add,
&words.remove,
&words.no_items,
&words.no_options,
&words.loading,
];
assert!(all.iter().all(|word| !word.trim().is_empty()), "{language}");
assert_ne!(words.signed, words.not_signed, "{language}");
assert_ne!(words.add, words.remove, "{language}");
assert_ne!(words.available, words.selected, "{language}");
}
assert_eq!(InputWords::for_language("xx"), InputWords::english());
assert_eq!(&*InputWords::for_language("de").select_all, "Alle auswählen");
}
}