Skip to content

Commit

Permalink
refactor: l10n
Browse files Browse the repository at this point in the history
  • Loading branch information
sjfhsjfh committed Feb 6, 2025
1 parent 023fa20 commit 917c25c
Show file tree
Hide file tree
Showing 36 changed files with 69 additions and 38 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"prpr",
"prpr-avc",
"prpr-pbc",
"prpr-l10n",
"phira",
"phira-main",
"phira-monitor",
Expand Down
1 change: 1 addition & 0 deletions phira/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ once_cell = "*"
openssl = { version = "*", features = ["vendored"] }
pollster = "0.3.0"
prpr = { path = "../prpr", features = ["log"], default-features = false }
prpr-l10n ={ path = "../prpr-l10n" }
rand = "0.8.5"
regex = "1.7.0"
reqwest = { version = "0.12.5", features = ["json", "stream", "gzip"] }
Expand Down
3 changes: 2 additions & 1 deletion phira/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::{anti_addiction_action, get_data, get_data_mut, save_data};
use anyhow::{anyhow, bail, Context, Result};
use arc_swap::ArcSwap;
use once_cell::sync::Lazy;
use prpr::{l10n::LANG_IDENTS, scene::SimpleRecord};
use prpr::scene::SimpleRecord;
use prpr_l10n::LANG_IDENTS;
use reqwest::{header, ClientBuilder, Method, RequestBuilder, Response, StatusCode};
use serde::{Deserialize, Serialize};
use serde_json::json;
Expand Down
4 changes: 2 additions & 2 deletions phira/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prpr::tl_file!("common" ttl crate::);
prpr_l10n::tl_file!("common" ttl crate::);

#[cfg(feature = "closed")]
mod inner;
Expand Down Expand Up @@ -28,13 +28,13 @@ use prpr::{
build_conf,
core::{init_assets, PGR_FONT},
ext::SafeTexture,
l10n::{set_prefered_locale, GLOBAL, LANGS},
log,
scene::{show_error, show_message},
time::TimeManager,
ui::{FontArc, TextPainter},
Main,
};
use prpr_l10n::{set_prefered_locale, GLOBAL, LANGS};
use scene::MainScene;
use std::sync::{mpsc, Mutex};
use tracing::{error, info};
Expand Down
2 changes: 1 addition & 1 deletion phira/src/login.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prpr::tl_file!("login");
prpr_l10n::tl_file!("login");

use crate::{
client::{Client, LoginParams, User, UserManager},
Expand Down
2 changes: 1 addition & 1 deletion phira/src/mp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prpr::tl_file!("multiplayer" mtl);
prpr_l10n::tl_file!("multiplayer" mtl);

mod panel;
pub use panel::MPPanel;
2 changes: 1 addition & 1 deletion phira/src/page/coll.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prpr::tl_file!("collection");
prpr_l10n::tl_file!("collection");

use super::{Illustration, NextPage, Page, SharedState};
use crate::{icons::Icons, load_res_tex, resource::rtl, scene::ChapterScene};
Expand Down
4 changes: 2 additions & 2 deletions phira/src/page/home.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prpr::tl_file!("home");
prpr_l10n::tl_file!("home");

use super::{
load_font_with_cksum, set_bold_font, EventPage, LibraryPage, MessagePage, NextPage, Page, ResPackPage, SFader, SettingsPage, SharedState,
Expand All @@ -15,6 +15,7 @@ use crate::{
sync_data,
threed::ThreeD,
};
use prpr_l10n::LANG_IDENTS;
use ::rand::{random, thread_rng, Rng};
use anyhow::{bail, Context, Result};
use chrono::NaiveDate;
Expand All @@ -24,7 +25,6 @@ use prpr::{
core::BOLD_FONT,
ext::{open_url, screen_aspect, semi_black, semi_white, RectExt, SafeTexture, ScaleType},
info::ChartInfo,
l10n::LANG_IDENTS,
scene::{show_error, NextScene},
task::Task,
ui::{button_hit_large, clip_rounded_rect, ClipType, DRectButton, Dialog, FontArc, RectButton, Scroll, Ui},
Expand Down
2 changes: 1 addition & 1 deletion phira/src/page/library.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prpr::tl_file!("library");
prpr_l10n::tl_file!("library");

use super::{CollectionPage, NextPage, Page, SharedState};
use crate::{
Expand Down
2 changes: 1 addition & 1 deletion phira/src/page/message.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prpr::tl_file!("message");
prpr_l10n::tl_file!("message");

use std::borrow::Cow;

Expand Down
2 changes: 1 addition & 1 deletion phira/src/page/offset.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prpr::tl_file!("cali");
prpr_l10n::tl_file!("cali");

use std::borrow::Cow;

Expand Down
2 changes: 1 addition & 1 deletion phira/src/page/respack.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prpr::tl_file!("respack");
prpr_l10n::tl_file!("respack");

use super::{Page, SharedState};
use crate::{
Expand Down
4 changes: 2 additions & 2 deletions phira/src/page/settings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prpr::tl_file!("settings");
prpr_l10n::tl_file!("settings");

use super::{NextPage, OffsetPage, Page, SharedState};
use crate::{
Expand All @@ -15,11 +15,11 @@ use macroquad::prelude::*;
use prpr::{
core::BOLD_FONT,
ext::{open_url, poll_future, semi_white, LocalTask, RectExt, SafeTexture},
l10n::{LanguageIdentifier, LANG_IDENTS, LANG_NAMES},
scene::{request_input, return_input, show_error, show_message, take_input},
task::Task,
ui::{DRectButton, Scroll, Slider, Ui},
};
use prpr_l10n::{LanguageIdentifier, LANG_IDENTS, LANG_NAMES};
use reqwest::Url;
use std::{borrow::Cow, fs, io, net::ToSocketAddrs, path::PathBuf, sync::atomic::Ordering};

Expand Down
2 changes: 1 addition & 1 deletion phira/src/rate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prpr::tl_file!("rate");
prpr_l10n::tl_file!("rate");

use crate::page::Fader;
use macroquad::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion phira/src/resource.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
prpr::tl_file!("resource" rtl);
prpr_l10n::tl_file!("resource" rtl);
2 changes: 1 addition & 1 deletion phira/src/scene.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prpr::tl_file!("import" itl);
prpr_l10n::tl_file!("import" itl);

mod chart_order;
pub use chart_order::{ChartOrder, ORDERS};
Expand Down
2 changes: 1 addition & 1 deletion phira/src/scene/chapter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prpr::tl_file!("chapter");
prpr_l10n::tl_file!("chapter");

use crate::{
anim::Anim,
Expand Down
2 changes: 1 addition & 1 deletion phira/src/scene/chart_order.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prpr::tl_file!("chart_order");
prpr_l10n::tl_file!("chart_order");

use crate::page::ChartItem;

Expand Down
2 changes: 1 addition & 1 deletion phira/src/scene/event.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prpr::tl_file!("event");
prpr_l10n::tl_file!("event");

use super::{render_ldb, LdbDisplayItem, ProfileScene};
use crate::{
Expand Down
2 changes: 1 addition & 1 deletion phira/src/scene/profile.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prpr::tl_file!("profile");
prpr_l10n::tl_file!("profile");

use super::{confirm_delete, TEX_BACKGROUND, TEX_ICON_BACK};
use crate::{
Expand Down
2 changes: 1 addition & 1 deletion phira/src/scene/song.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prpr::tl_file!("song");
prpr_l10n::tl_file!("song");

#[cfg(feature = "video")]
use super::UnlockScene;
Expand Down
2 changes: 1 addition & 1 deletion phira/src/tags.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prpr::tl_file!("tags");
prpr_l10n::tl_file!("tags");

use crate::{client::Permissions, page::Fader};
use macroquad::prelude::*;
Expand Down
13 changes: 13 additions & 0 deletions prpr-l10n/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "prpr-l10n"
version = "0.1.0"
edition = "2021"

[dependencies]
fluent = "0.16.0"
fluent-syntax = "0.11.0"
lru = "0.9.0"
once_cell = "1.16.0"
sys-locale = "0.3.1"
tracing = "0.1.37"
unic-langid = { version = "0.9.1", features = ["macros"] }
10 changes: 5 additions & 5 deletions prpr/src/l10n.rs → prpr-l10n/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ pub static LANG_IDENTS: Lazy<[LanguageIdentifier; 12]> = Lazy::new(|| LANGS.map(
#[macro_export]
macro_rules! create_bundle {
($locale:literal, $file:literal) => {{
let mut bundle = $crate::l10n::FluentBundle::new($crate::l10n::LANG_IDENTS.iter().cloned().collect());
let mut bundle = $crate::FluentBundle::new($crate::LANG_IDENTS.iter().cloned().collect());
bundle
.add_resource(
$crate::l10n::FluentResource::try_new(
$crate::FluentResource::try_new(
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/locales/", $locale, "/", $file, ".ftl")).to_owned(),
)
.unwrap(),
Expand Down Expand Up @@ -207,10 +207,10 @@ macro_rules! tl_file {
$crate::tl_file!($file tl);
};
($file:literal $macro_name:ident $($p:tt)*) => {
static L10N_BUNDLES: $crate::l10n::Lazy<$crate::l10n::L10nBundles> = $crate::l10n::Lazy::new(|| $crate::create_bundles!($file).into());
static L10N_BUNDLES: $crate::Lazy<$crate::L10nBundles> = $crate::Lazy::new(|| $crate::create_bundles!($file).into());

thread_local! {
pub static L10N_LOCAL: std::cell::RefCell<$crate::l10n::L10nLocal> = $crate::l10n::L10nLocal::new(&*L10N_BUNDLES).into();
pub static L10N_LOCAL: std::cell::RefCell<$crate::L10nLocal> = $crate::L10nLocal::new(&*L10N_BUNDLES).into();
}

macro_rules! __tl_builder {
Expand All @@ -223,7 +223,7 @@ macro_rules! tl_file {
$($p)* L10N_LOCAL.with(|it| it.borrow_mut().format($key, Some($args)))
};
($d key:expr, $d ($d name:expr => $d value:expr),+) => {
$($p)* L10N_LOCAL.with(|it| it.borrow_mut().format($key, Some(&$crate::l10n::fluent_args![$d($d name => $d value), *])).to_string())
$($p)* L10N_LOCAL.with(|it| it.borrow_mut().format($key, Some(&$crate::fluent_args![$d($d name => $d value), *])).to_string())
};
(err $d ($d body:tt)*) => {
anyhow::Error::msg($macro_name!($d($d body)*))
Expand Down
1 change: 1 addition & 0 deletions prpr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ tracing-subscriber = { version = "0.3.17", optional = true }
colored = { version = "=2.0.0", optional = true }

prpr-avc = { path = "../prpr-avc", optional = true }
prpr-l10n ={ path = "../prpr-l10n" }

ahash = "=0.8.6"
cfg-expr = "=0.15.4"
Expand Down
1 change: 0 additions & 1 deletion prpr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub mod ext;
pub mod fs;
pub mod info;
pub mod judge;
pub mod l10n;
pub mod parse;
pub mod particle;
pub mod scene;
Expand Down
2 changes: 1 addition & 1 deletion prpr/src/parse/extra.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
crate::tl_file!("parser" ptl);
prpr_l10n::tl_file!("parser" ptl);

use super::RPE_TWEEN_MAP;
use crate::{
Expand Down
2 changes: 1 addition & 1 deletion prpr/src/parse/pec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
crate::tl_file!("parser" ptl);
prpr_l10n::tl_file!("parser" ptl);

use super::{process_lines, RPE_TWEEN_MAP};
use crate::{
Expand Down
2 changes: 1 addition & 1 deletion prpr/src/parse/pgr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
crate::tl_file!("parser" ptl);
prpr_l10n::tl_file!("parser" ptl);

use super::process_lines;
use crate::{
Expand Down
2 changes: 1 addition & 1 deletion prpr/src/parse/rpe.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
crate::tl_file!("parser" ptl);
prpr_l10n::tl_file!("parser" ptl);

use super::{process_lines, RPE_TWEEN_MAP};
use crate::{
Expand Down
2 changes: 1 addition & 1 deletion prpr/src/scene.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Scene management module.
crate::tl_file!("scene" ttl);
prpr_l10n::tl_file!("scene" ttl);

mod ending;
pub use ending::{EndingScene, RecordUpdateState};
Expand Down
2 changes: 1 addition & 1 deletion prpr/src/scene/ending.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
crate::tl_file!("ending");
prpr_l10n::tl_file!("ending");

use super::{draw_background, game::SimpleRecord, loading::UploadFn, NextScene, Scene};
use crate::{
Expand Down
2 changes: 1 addition & 1 deletion prpr/src/scene/game.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(unused)]

crate::tl_file!("game");
prpr_l10n::tl_file!("game");

use super::{
draw_background,
Expand Down
2 changes: 1 addition & 1 deletion prpr/src/ui/chart_info.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
crate::tl_file!("chart_info");
prpr_l10n::tl_file!("chart_info");

use super::Ui;
use crate::{core::BOLD_FONT, ext::parse_time, info::ChartInfo, scene::show_message};
Expand Down
2 changes: 1 addition & 1 deletion prpr/src/ui/dialog.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
crate::tl_file!("dialog");
prpr_l10n::tl_file!("dialog");

use super::{DRectButton, RectButton, Scroll, Ui};
use crate::{core::BOLD_FONT, ext::RectExt, scene::show_message};
Expand Down

0 comments on commit 917c25c

Please sign in to comment.