From 33033f670ec89124cdbb9458ed2a1720d3ec0f3f Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Mon, 13 Feb 2023 21:43:13 -0500 Subject: [PATCH] Use plugin dir for locating translations without janky path passthru from front --- usdpl-back/README.md | 4 ++++ usdpl-back/src/instance.rs | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/usdpl-back/README.md b/usdpl-back/README.md index 73cdd4c..500e456 100644 --- a/usdpl-back/README.md +++ b/usdpl-back/README.md @@ -7,3 +7,7 @@ Targets x86_64 (native Steam Deck ISA). This is a minimalist web server for handling events from the front-end. +## Translations + +Translations are expected to be in `/translations/`, in compiled gettext format (`.mo`). + diff --git a/usdpl-back/src/instance.rs b/usdpl-back/src/instance.rs index 76f64f3..7dd842e 100644 --- a/usdpl-back/src/instance.rs +++ b/usdpl-back/src/instance.rs @@ -250,7 +250,8 @@ fn get_all_translations(language: String) -> Vec<(String, Vec)> { #[cfg(feature = "translate")] fn load_locale(lang: &str) -> Result { - let file = std::fs::File::open(lang).map_err(|e| gettext_ng::Error::Io(e))?; + let path = crate::api::dirs::plugin().unwrap_or_else(|| "".into()).join("translations").join(format!("{}.mo", lang)); + let file = std::fs::File::open(path).map_err(|e| gettext_ng::Error::Io(e))?; gettext_ng::Catalog::parse(file) }