Browse Source

refactoring

master
Keanu D?lle 2 years ago
parent
commit
4700a02214
  1. 2
      src/database/login.rs
  2. 2
      src/database/profile_communication.rs
  3. 2
      src/lang/lang.rs
  4. 17
      src/lang/mod.rs
  5. 7
      src/lang/setup.rs

2
src/database/login.rs

@ -1,8 +1,6 @@
use crate::database::connection::connect;
use crate::lang::parse::{parse_fallback, parse_or_fallback};
use crate::modules::login::UserData;
use crate::sitebuilder::sidebar::parse;
use mysql::Value;
pub fn get_user_hash(email: String) -> Option<String> {
let pool = connect();

2
src/database/profile_communication.rs

@ -182,7 +182,7 @@ pub enum FormTypes {
Phone(UserCommunicationPhoneNumber),
}
fn parse_phone_number_from_string(number: String) -> Option<((i16, i64))> {
fn parse_phone_number_from_string(number: String) -> Option<(i16, i64)> {
let mut parts: Vec<&str> = number.split(' ').collect();
if parts.len() > 0 {
let country_code: i16 = parts[0].parse().unwrap();

2
src/lang/lang.rs

@ -1,5 +1,3 @@
use fluent::{FluentArgs, FluentBundle, FluentResource, FluentValue};
pub fn get(id: String, args: Vec<String>) -> String {
String::from(id)
}

17
src/lang/mod.rs

@ -106,7 +106,7 @@ impl LanguageManager {
mod language_tests {
use super::*;
use crate::lang::setup::create_bundle;
use fluent::{FluentBundle, FluentResource, FluentValue};
use fluent::{FluentBundle, FluentValue};
use unic_langid::LanguageIdentifier;
#[test]
@ -175,7 +175,11 @@ mod language_tests {
fn test_get_non_existing_string_but_in_fallback_language() {
//Retrieve current fallback language from config
let fallback_language = SETTINGS.read().unwrap().get::<String>("fallback_language");
SETTINGS.write().unwrap().set("fallback_language", "en-US");
SETTINGS
.write()
.unwrap()
.set("fallback_language", "en-US")
.unwrap();
let langid: LanguageIdentifier = "en-US".parse().expect("Parsing failed.");
let langid2: LanguageIdentifier = "de-DE".parse().expect("Parsing failed.");
@ -202,9 +206,14 @@ mod language_tests {
SETTINGS
.write()
.unwrap()
.set("fallback_language", fallback_language.unwrap());
.set("fallback_language", fallback_language.unwrap())
.unwrap();
} else {
SETTINGS.write().unwrap().set("fallback_language", "");
SETTINGS
.write()
.unwrap()
.set("fallback_language", "")
.unwrap();
}
}

7
src/lang/setup.rs

@ -1,8 +1,5 @@
use crate::lang::LanguageManager;
use fluent::FluentError;
use fluent::{FluentArgs, FluentBundle, FluentResource, FluentValue};
use std::collections::HashMap;
use std::fs::{self, DirEntry};
use fluent::{FluentBundle, FluentResource};
use std::fs;
use unic_langid::LanguageIdentifier;
/// Imports all language files from lang/

Loading…
Cancel
Save