mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-14 08:04:52 +01:00
get language despite admin or not
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
|
use crate::system_helpers::*;
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn get_lang(window: tauri::Window, lang: String) -> String {
|
pub async fn get_lang(window: tauri::Window, lang: String) -> String {
|
||||||
let lang = lang.to_lowercase();
|
let lang = lang.to_lowercase();
|
||||||
|
|
||||||
// Send contents of language file back
|
// Send contents of language file back
|
||||||
let contents = match std::fs::read_to_string(format!("./lang/{}.json", lang)) {
|
let contents = match std::fs::read_to_string(format!("{}/lang/{}.json", install_location(), lang)) {
|
||||||
Ok(x) => x,
|
Ok(x) => x,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
emit_lang_err(window, format!("Failed to read language file: {}", e));
|
emit_lang_err(window, format!("Failed to read language file: {}", e));
|
||||||
@@ -19,7 +21,7 @@ pub async fn get_languages() -> std::collections::HashMap<String, String> {
|
|||||||
// for each lang file, set the key as the filename and the value as the lang_name contained in the file
|
// for each lang file, set the key as the filename and the value as the lang_name contained in the file
|
||||||
let mut languages = std::collections::HashMap::new();
|
let mut languages = std::collections::HashMap::new();
|
||||||
|
|
||||||
let mut lang_files = std::fs::read_dir("./lang").unwrap();
|
let mut lang_files = std::fs::read_dir(format!("{}/lang", install_location())).unwrap();
|
||||||
|
|
||||||
while let Some(entry) = lang_files.next() {
|
while let Some(entry) = lang_files.next() {
|
||||||
let entry = entry.unwrap();
|
let entry = entry.unwrap();
|
||||||
|
|||||||
@@ -54,3 +54,14 @@ pub fn open_in_browser(url: String) {
|
|||||||
Err(e) => println!("Failed to open URL: {}", e),
|
Err(e) => println!("Failed to open URL: {}", e),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn install_location() -> String {
|
||||||
|
let mut exe_path = std::env::current_exe().unwrap();
|
||||||
|
|
||||||
|
// Get the path to the executable.
|
||||||
|
exe_path.pop();
|
||||||
|
|
||||||
|
println!("{}", exe_path.to_str().unwrap().to_string());
|
||||||
|
|
||||||
|
return exe_path.to_str().unwrap().to_string();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user