Skip to content

Commit

Permalink
LazyStatic for file path
Browse files Browse the repository at this point in the history
  • Loading branch information
asodugf12 committed Dec 2, 2024
1 parent 48bbd3b commit c7aa51f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pumpkin/src/server/translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ use std::{
fs::File,
io::{BufRead, BufReader},
path::PathBuf,
sync::LazyLock,
};

use pumpkin_config::ADVANCED_CONFIG;
use pumpkin_core::text::{style::Style, TextComponent, TextContent};
use serde_json::Value;
use thiserror::Error;

static PATH: LazyLock<&str> = LazyLock::new(|| "assets/lang/en_us/en_us.json");

#[derive(Error, Debug)]
pub enum TranslationError {
#[error("File does not exist")]
Expand All @@ -26,8 +29,7 @@ pub enum TranslationError {
pub fn translate(message: &'_ str) -> Result<TextComponent<'_>, TranslationError> {
let config = &ADVANCED_CONFIG.translation;
if !config.enabled {
let path = "assets/lang/en_us/en_us.json";
let translations = get_translations(path, message)?;
let translations = get_translations(*PATH, message)?;

return Ok(translations);
}
Expand Down

0 comments on commit c7aa51f

Please sign in to comment.