Fixes Patches Creation & More
Working with files / Paths fixed Websocket PingPongs (There is no data behind this just PingPong) Storing User Profiles correctly Added necessary dependencies and initial code support for: - X.509 certificate handling via x509/pkcs8 crates - Key generation and crypto operations via x448/sha2 - Structured hex encoding and base64 encoding
This commit is contained in:
parent
bba3f548ab
commit
0d07ddf851
23 changed files with 887 additions and 266 deletions
58
src/langu/language_creator.rs
Normal file
58
src/langu/language_creator.rs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
use crate::util::file_util::{self, save_file};
|
||||
use json::{self, JsonValue};
|
||||
|
||||
pub fn create_languages() {
|
||||
let mut frontend_messages = JsonValue::new_object();
|
||||
let mut omikron_messages = JsonValue::new_object();
|
||||
let mut button_texts = JsonValue::new_object();
|
||||
let mut general_texts = JsonValue::new_object();
|
||||
let mut debug_messages = JsonValue::new_object();
|
||||
|
||||
// FRONTEND
|
||||
frontend_messages.insert(
|
||||
"USER_CONTEXT_GET_CONVERSATIONS",
|
||||
"User {} is loading conversations",
|
||||
);
|
||||
frontend_messages.insert(
|
||||
"USER_CONTEXT_GET_COMMUNITIES",
|
||||
"User {} is loading communities",
|
||||
);
|
||||
frontend_messages.insert("ADD_CONVERSATION", "User {} added {}");
|
||||
|
||||
// OMIKRON
|
||||
omikron_messages.insert(
|
||||
"IdentificationResponse",
|
||||
"IOTA identified on Omikron, {} users!",
|
||||
);
|
||||
|
||||
// BUTTONS
|
||||
button_texts.insert("EXIT", "Exit");
|
||||
|
||||
// GENERAL
|
||||
general_texts.insert("IOTA_ID", "IOTA ID: {}-####-####-####-############");
|
||||
general_texts.insert("USER_ID", "USER ID: {}");
|
||||
general_texts.insert("USER_IDS", "USER IDS: {}");
|
||||
|
||||
// DEBUG
|
||||
debug_messages.insert("", "");
|
||||
save_file(
|
||||
"languages/en_INT",
|
||||
"frontend.json",
|
||||
&frontend_messages.to_string(),
|
||||
);
|
||||
save_file(
|
||||
"languages/en_INT",
|
||||
"omikron.json",
|
||||
&omikron_messages.to_string(),
|
||||
);
|
||||
save_file(
|
||||
"languages/en_INT",
|
||||
"buttons.json",
|
||||
&button_texts.to_string(),
|
||||
);
|
||||
save_file(
|
||||
"languages/en_INT",
|
||||
"debug.json",
|
||||
&debug_messages.to_string(),
|
||||
);
|
||||
}
|
||||
66
src/langu/language_manager.rs
Normal file
66
src/langu/language_manager.rs
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
use crate::util::file_util::{self, load_file};
|
||||
use json::{JsonValue, parse};
|
||||
use once_cell::sync::Lazy;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Mutex;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct LanguagePack {
|
||||
languages: HashMap<String, String>,
|
||||
}
|
||||
|
||||
// Language packs need to have formatting
|
||||
// Variables need to be provided
|
||||
|
||||
pub static LANGUAGE_PACK: Lazy<Mutex<LanguagePack>> =
|
||||
Lazy::new(|| Mutex::new(LanguagePack::new("en_INT")));
|
||||
|
||||
pub fn get_language() -> LanguagePack {
|
||||
LANGUAGE_PACK.lock().unwrap().clone()
|
||||
}
|
||||
|
||||
impl LanguagePack {
|
||||
pub fn new(language: &str) -> Self {
|
||||
let mut pack = LanguagePack {
|
||||
languages: HashMap::new(),
|
||||
};
|
||||
pack.load_language(language);
|
||||
pack
|
||||
}
|
||||
|
||||
pub fn load_language(&mut self, language: &str) {
|
||||
let path = format!("languages/{}/", language);
|
||||
|
||||
let frontend_messages = file_util::load_file(&path, "frontend.json");
|
||||
let frontend_messages = parse(&frontend_messages).unwrap();
|
||||
for (key, value) in frontend_messages.entries() {
|
||||
self.languages
|
||||
.insert(key.to_string(), value.as_str().unwrap().to_string());
|
||||
}
|
||||
|
||||
let omikron_messages = file_util::load_file(&path, "omikron.json");
|
||||
let omikron_messages = parse(&omikron_messages).unwrap();
|
||||
for (key, value) in omikron_messages.entries() {
|
||||
self.languages
|
||||
.insert(key.to_string(), value.as_str().unwrap().to_string());
|
||||
}
|
||||
|
||||
let button_texts = file_util::load_file(&path, "buttons.json");
|
||||
let button_texts = parse(&button_texts).unwrap();
|
||||
for (key, value) in button_texts.entries() {
|
||||
self.languages
|
||||
.insert(key.to_string(), value.as_str().unwrap().to_string());
|
||||
}
|
||||
|
||||
let debug_messages = file_util::load_file(&path, "debug.json");
|
||||
let debug_messages = parse(&debug_messages).unwrap();
|
||||
for (key, value) in debug_messages.entries() {
|
||||
self.languages
|
||||
.insert(key.to_string(), value.as_str().unwrap().to_string());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_translation(&self, key: &str) -> &String {
|
||||
self.languages.get(key).unwrap()
|
||||
}
|
||||
}
|
||||
2
src/langu/mod.rs
Normal file
2
src/langu/mod.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
pub mod language_creator;
|
||||
pub mod language_manager;
|
||||
Loading…
Reference in a new issue