1
// This file is part of hnefatafl-copenhagen.
2
//
3
// hnefatafl-copenhagen is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU Affero General Public License as published by
5
// the Free Software Foundation, either version 3 of the License, or
6
// (at your option) any later version.
7
//
8
// hnefatafl-copenhagen is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
// GNU Affero General Public License for more details.
12
//
13
// You should have received a copy of the GNU Affero General Public License
14
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
15

            
16
use std::fmt;
17

            
18
use serde::{Deserialize, Serialize};
19

            
20
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
21
pub enum Locale {
22
    #[default]
23
    English,
24
    Chinese,
25
    Spanish,
26
    Arabic,
27
    Indonesian,
28
    PortugueseBr,
29
    PortuguesePt,
30
    French,
31
    Japanese,
32
    Russian,
33
    German,
34
    Icelandic,
35
    IcelandicRunic,
36
    Swedish,
37
    Korean,
38
}
39

            
40
impl Locale {
41
    #[must_use]
42
    pub fn txt(self) -> String {
43
        match self {
44
            Self::English => "en-US".to_string(),
45
            Self::Chinese => "zh-CN".to_string(),
46
            Self::Spanish => "es".to_string(),
47
            Self::Arabic => "ar".to_string(),
48
            Self::Indonesian => "id".to_string(),
49
            Self::PortugueseBr => "pt-BR".to_string(),
50
            Self::PortuguesePt => "pt-PT".to_string(),
51
            Self::French => "fr".to_string(),
52
            Self::Japanese => "ja".to_string(),
53
            Self::Russian => "ru".to_string(),
54
            Self::German => "de".to_string(),
55
            Self::Icelandic => "is-IS".to_string(),
56
            Self::IcelandicRunic => "is-RU".to_string(),
57
            Self::Swedish => "sv-SE".to_string(),
58
            Self::Korean => "ko".to_string(),
59
        }
60
    }
61
}
62

            
63
impl fmt::Display for Locale {
64
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
65
        match self {
66
            Self::English => write!(f, "English (United States)"),
67
            Self::Chinese => write!(f, "中文 (中国)"),
68
            Self::Spanish => write!(f, "Español"),
69
            Self::Arabic => write!(f, "العربية"),
70
            Self::Indonesian => write!(f, "bahasa Indonesia"),
71
            Self::PortugueseBr => write!(f, "Português (Brasil)"),
72
            Self::PortuguesePt => write!(f, "Português (Portugal)"),
73
            Self::French => write!(f, "Français"),
74
            Self::Japanese => write!(f, "日本人"),
75
            Self::Russian => write!(f, "Русский"),
76
            Self::German => write!(f, "Deutsch"),
77
            Self::Icelandic => write!(f, "Íslenska"),
78
            Self::IcelandicRunic => write!(f, "ᛇᛋᛚᛂᚿᛋᚴᛁ ᚱᚤᛐᚢᚱᛁᚿᚿ (Íslenska Rúturinn)"),
79
            Self::Swedish => write!(f, "Svenska"),
80
            Self::Korean => write!(f, "한국인"),
81
        }
82
    }
83
}