mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-10 15:17:57 -05:00
app: locale loading using the miniquad asset manager rather than filesystem (which works for accessing APK assets on android)
This commit is contained in:
@@ -16,38 +16,40 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use std::{fs, path::Path};
|
||||
use std::sync::mpsc::sync_channel;
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
mod ui_consts {
|
||||
pub const LOCALE_PATH: &str = "lang/{locale}/";
|
||||
pub const LOCALE_PATH: &str = "lang/{locale}/{entry}";
|
||||
}
|
||||
#[cfg(all(
|
||||
any(target_os = "linux", target_os = "macos", target_os = "windows"),
|
||||
not(feature = "emulate-android")
|
||||
))]
|
||||
mod ui_consts {
|
||||
pub const LOCALE_PATH: &str = "assets/lang/{locale}/";
|
||||
pub const LOCALE_PATH: &str = "assets/lang/{locale}/{entry}";
|
||||
}
|
||||
|
||||
pub use ui_consts::*;
|
||||
|
||||
fn read_files_to_string<P: AsRef<Path>>(dir: P) -> std::io::Result<String> {
|
||||
let mut output = String::new();
|
||||
|
||||
for entry in fs::read_dir(dir)? {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
if path.is_file() {
|
||||
let contents = fs::read_to_string(&path)?;
|
||||
output.push_str(&contents);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(output)
|
||||
}
|
||||
static ENTRIES: &[&'static str] = &[
|
||||
"app.ftl"
|
||||
];
|
||||
|
||||
pub fn read_locale_ftl(locale: &str) -> String {
|
||||
let dir = LOCALE_PATH.replace("{locale}", locale);
|
||||
read_files_to_string(dir).unwrap()
|
||||
|
||||
let mut output = String::new();
|
||||
for entry in ENTRIES {
|
||||
let path = dir.replace("{entry}", entry);
|
||||
let (sender, recvr) = sync_channel(1);
|
||||
miniquad::fs::load_file(&path, move |res| match res {
|
||||
Ok(res) => sender.send(res).unwrap(),
|
||||
Err(e) => panic!("FTL not found! {e}")
|
||||
});
|
||||
let res = recvr.recv().unwrap();
|
||||
let contents = std::str::from_utf8(&res).unwrap();
|
||||
output.push_str(contents);
|
||||
}
|
||||
output
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
use chrono::{NaiveDate, NaiveDateTime};
|
||||
use darkfi_serial::Encodable;
|
||||
use indoc::indoc;
|
||||
use sled_overlay::sled;
|
||||
use smol::Task;
|
||||
use std::sync::{Arc, Mutex as SyncMutex};
|
||||
@@ -146,7 +145,7 @@ impl App {
|
||||
|
||||
fn setup_locale(&self, window: &mut SceneNode) -> I18nBabelFish {
|
||||
/*
|
||||
let i18n_src = indoc! {"
|
||||
let i18n_src = indoc::indoc! {"
|
||||
hello-world = Hello, world!
|
||||
channels-label = CHANNELS
|
||||
"}
|
||||
|
||||
Reference in New Issue
Block a user