use once_cell::sync::Lazy;
use fluent_templates::{Loader, loader::LanguageIdentifier};
use super::LOADER;
static ALL_LOCALES: Lazy<Vec<String>> = Lazy::new(|| {
let mut locales: Vec<String> = LOADER.locales().map(|id| id.to_string()).collect();
locales.sort_unstable();
locales
});
#[must_use]
pub fn available_locales() -> &'static [String] {
ALL_LOCALES.as_slice()
}
#[must_use]
pub fn supports_locale(locale: &str) -> bool {
match locale.parse::<LanguageIdentifier>() {
Ok(identifier) => {
let canonical = identifier.to_string();
ALL_LOCALES
.binary_search_by(|candidate| candidate.as_str().cmp(canonical.as_str()))
.is_ok()
}
Err(_) => false,
}
}