Files
IronCalc/base/src/language/mod.rs
Nicolás Hatcher Andrés f9cf86a17c Bugfix/nicolas more fixes (#36)
* FIX: Remove the serde_json depndendency

* UPDATE: Use binary representation also for languages and locales
2024-04-15 19:25:38 +02:00

44 lines
983 B
Rust

use std::collections::HashMap;
use bitcode::{Decode, Encode};
use once_cell::sync::Lazy;
#[derive(Encode, Decode, Clone)]
pub struct Booleans {
pub r#true: String,
pub r#false: String,
}
#[derive(Encode, Decode, Clone)]
pub struct Errors {
pub r#ref: String,
pub name: String,
pub value: String,
pub div: String,
pub na: String,
pub num: String,
pub nimpl: String,
pub spill: String,
pub calc: String,
pub circ: String,
pub error: String,
pub null: String,
}
#[derive(Encode, Decode, Clone)]
pub struct Language {
pub booleans: Booleans,
pub errors: Errors,
}
static LANGUAGES: Lazy<HashMap<String, Language>> = Lazy::new(|| {
bitcode::decode(include_bytes!("language.bin")).expect("Failed parsing language file")
});
pub fn get_language(id: &str) -> Result<&Language, String> {
let language = LANGUAGES
.get(id)
.ok_or(format!("Language is not supported: '{}'", id))?;
Ok(language)
}