From 8d854c1d1a6379cb2b6f9a284b06837db1f1036a Mon Sep 17 00:00:00 2001 From: southerntofu Date: Mon, 23 Nov 2020 19:45:35 +0100 Subject: [PATCH] Find translations in several places --- src/log.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/log.rs b/src/log.rs index dfb197c..06e88b0 100644 --- a/src/log.rs +++ b/src/log.rs @@ -13,9 +13,30 @@ lazy_static!{ 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 { - let folder = env::var("I18N").unwrap_or("./i18n/".to_string()); - let mut path = PathBuf::from(folder); + let mut path = find_translations(); if !path.is_dir() { panic!("Could not find translations in {:?}", path); }