crunchy-cli/crunchy-cli-core/src/utils/locale.rs
2023-03-23 01:18:14 +01:00

29 lines
772 B
Rust

use crunchyroll_rs::Locale;
/// Return the locale of the system.
pub fn system_locale() -> Locale {
if let Some(system_locale) = sys_locale::get_locale() {
let locale = Locale::from(system_locale);
if let Locale::Custom(_) = locale {
Locale::en_US
} else {
locale
}
} else {
Locale::en_US
}
}
/// Check if [`Locale::Custom("all")`] is in the provided locale list and return [`Locale::all`] if
/// so. If not, just return the provided locale list.
pub fn all_locale_in_locales(locales: Vec<Locale>) -> Vec<Locale> {
if locales
.iter()
.find(|l| l.to_string().to_lowercase().trim() == "all")
.is_some()
{
Locale::all()
} else {
locales
}
}