forked from pop-os/distinst
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Use iso-codes package for languages
This fixes the issue where "ber" wasn't mapped to any name, and showed up as a blank link at the end of the language list in the installer. Now it is listed as Berber "languages".
- Loading branch information
Showing
5 changed files
with
44 additions
and
166 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use once_cell::sync::Lazy; | ||
use serde_json::from_reader; | ||
use std::collections::HashMap; | ||
use std::fs::File; | ||
|
||
const JSON_PATH_3: &str = "/usr/share/iso-codes/json/iso_639-3.json"; | ||
const JSON_PATH_5: &str = "/usr/share/iso-codes/json/iso_639-5.json"; | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct Language { | ||
alpha_2: Option<String>, | ||
alpha_3: String, | ||
pub name: String, | ||
} | ||
|
||
impl Language { | ||
pub fn all() -> &'static [Self] { | ||
static LANGUAGES: Lazy<Vec<Language>> = Lazy::new(|| { | ||
let f = File::open(JSON_PATH_3).unwrap(); | ||
let mut m: HashMap<String, Vec<Language>> = from_reader(f).unwrap(); | ||
let mut languages = m.remove("639-3").unwrap(); | ||
|
||
// Language families, like Berber, which is needed | ||
let f = File::open(JSON_PATH_5).unwrap(); | ||
let mut m: HashMap<String, Vec<Language>> = from_reader(f).unwrap(); | ||
languages.extend(m.remove("639-5").unwrap()); | ||
|
||
languages | ||
}); | ||
Lazy::force(&LANGUAGES).as_slice() | ||
} | ||
|
||
pub fn from_alpha_2(alpha_2: &str) -> Option<&'static Self> { | ||
Self::all().iter().find(|i| i.alpha_2.as_ref().map(String::as_str) == Some(alpha_2)) | ||
} | ||
|
||
pub fn from_alpha_3(alpha_3: &str) -> Option<&'static Self> { | ||
Self::all().iter().find(|i| i.alpha_3 == alpha_3) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters