mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-12 23:24:35 +01:00
language select
This commit is contained in:
@@ -14,6 +14,32 @@ pub async fn get_lang(window: tauri::Window, lang: String) -> String {
|
||||
return contents;
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
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
|
||||
let mut languages = std::collections::HashMap::new();
|
||||
|
||||
let mut lang_files = std::fs::read_dir("../lang").unwrap();
|
||||
|
||||
while let Some(entry) = lang_files.next() {
|
||||
let entry = entry.unwrap();
|
||||
let path = entry.path();
|
||||
let filename = path.file_name().unwrap().to_str().unwrap();
|
||||
|
||||
let content = match std::fs::read_to_string(path.to_str().unwrap()) {
|
||||
Ok(x) => x,
|
||||
Err(e) => {
|
||||
println!("Failed to read language file: {}", e);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
languages.insert(filename.to_string(), content);
|
||||
}
|
||||
|
||||
return languages;
|
||||
}
|
||||
|
||||
pub fn emit_lang_err(window: tauri::Window, msg: std::string::String) {
|
||||
let mut res_hash = std::collections::HashMap::new();
|
||||
|
||||
|
||||
@@ -29,7 +29,8 @@ fn main() {
|
||||
get_bg_file,
|
||||
downloader::download_file,
|
||||
downloader::stop_download,
|
||||
lang::get_lang
|
||||
lang::get_lang,
|
||||
lang::get_languages
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
Reference in New Issue
Block a user