mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-12 23:24:35 +01:00
translation system
This commit is contained in:
28
src-tauri/src/lang.rs
Normal file
28
src-tauri/src/lang.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_lang(window: tauri::Window, lang: String) -> String {
|
||||
let lang = lang.to_lowercase();
|
||||
|
||||
// Send contents of language file back
|
||||
let contents = match std::fs::read_to_string(format!("../lang/{}.json", lang)) {
|
||||
Ok(x) => x,
|
||||
Err(e) => {
|
||||
emit_lang_err(window, format!("Failed to read language file: {}", e));
|
||||
return "".to_string();
|
||||
}
|
||||
};
|
||||
|
||||
return contents;
|
||||
}
|
||||
|
||||
|
||||
pub fn emit_lang_err(window: tauri::Window, msg: std::string::String) {
|
||||
let mut res_hash = std::collections::HashMap::new();
|
||||
|
||||
res_hash.insert(
|
||||
"error".to_string(),
|
||||
msg.to_string()
|
||||
);
|
||||
|
||||
window.emit("lang_error", &res_hash).unwrap();
|
||||
}
|
||||
@@ -6,6 +6,7 @@ windows_subsystem = "windows"
|
||||
use opener;
|
||||
|
||||
mod downloader;
|
||||
mod lang;
|
||||
mod proxy;
|
||||
|
||||
fn main() {
|
||||
@@ -14,7 +15,8 @@ fn main() {
|
||||
connect,
|
||||
disconnect,
|
||||
run_program,
|
||||
downloader::download_file
|
||||
downloader::download_file,
|
||||
lang::get_lang
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
Reference in New Issue
Block a user