use gettextrs::{LocaleCategory, bind_textdomain_codeset, bindtextdomain, setlocale, textdomain};
use log::warn;
use std::path::PathBuf;
pub fn setup_internationalization() -> Option<PathBuf> {
let mut translations_path = std::env::current_exe().unwrap();
translations_path.pop();
translations_path.push("translations");
translations_path.push("locale");
if !translations_path.is_dir() {
translations_path = std::env::current_exe().unwrap();
translations_path.pop();
translations_path.pop();
translations_path.pop();
translations_path.push("translations");
translations_path.push("locale");
if !translations_path.is_dir() {
translations_path = std::env::current_exe().unwrap();
translations_path.pop();
translations_path.pop();
translations_path.push("share");
translations_path.push("locale");
}
}
if translations_path.is_dir() {
if let Err(error) = bindtextdomain("songrec", translations_path.to_str().unwrap()) {
warn!("Failed to run bindtextdomain: {:?}", error);
}
}
if let Err(error) = textdomain("songrec") {
warn!("Failed to run textdomain: {:?}", error);
}
if let Err(error) = bind_textdomain_codeset("songrec", "UTF-8") {
warn!("Failed to run bind_textdomain_codeset: {:?}", error);
}
setlocale(LocaleCategory::LcAll, "");
if translations_path.is_dir() {
Some(translations_path)
} else {
None
}
}