Find translations in several places
This commit is contained in:
parent
3e048747cd
commit
8d854c1d1a
25
src/log.rs
25
src/log.rs
|
@ -13,9 +13,30 @@ lazy_static!{
|
||||||
|
|
||||||
pub type Context<'a> = &'a HashMap<&'a str, &'a str>;
|
pub type Context<'a> = &'a HashMap<&'a str, &'a str>;
|
||||||
|
|
||||||
|
/// Returns a PathBuf containing the translations. Does not mean
|
||||||
|
/// the translations are in there!
|
||||||
|
/// First attempts to find $FORGEBUILDI18N from env, otherwise tries
|
||||||
|
/// $HOME/.local/share/forgebuild/i18n or /usr/local/share/forgebuild/i18n
|
||||||
|
fn find_translations() -> PathBuf {
|
||||||
|
match env::var("FORGEBUILDI18N") {
|
||||||
|
Ok(dir) => PathBuf::from(dir),
|
||||||
|
Err(_) => {
|
||||||
|
let home = env::var("HOME").expect("$HOME environment variable is not defined!");
|
||||||
|
let mut path = PathBuf::from(home);
|
||||||
|
path.push(".local/share/forgebuild/i18n");
|
||||||
|
if path.is_dir() {
|
||||||
|
path
|
||||||
|
} else {
|
||||||
|
// Didn't find from env or in home directory,
|
||||||
|
// return default /usr/share/local/forgebuild/i18n
|
||||||
|
PathBuf::from("/usr/share/local/forgebuild/i18n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn load_translations() -> HashMap<String, String> {
|
fn load_translations() -> HashMap<String, String> {
|
||||||
let folder = env::var("I18N").unwrap_or("./i18n/".to_string());
|
let mut path = find_translations();
|
||||||
let mut path = PathBuf::from(folder);
|
|
||||||
if !path.is_dir() {
|
if !path.is_dir() {
|
||||||
panic!("Could not find translations in {:?}", path);
|
panic!("Could not find translations in {:?}", path);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue