-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Add integrated test for L10n (#510)
- Loading branch information
1 parent
023fa20
commit cbffc51
Showing
46 changed files
with
454 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ members = [ | |
"prpr", | ||
"prpr-avc", | ||
"prpr-pbc", | ||
"prpr-l10n", | ||
"phira", | ||
"phira-main", | ||
"phira-monitor", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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::{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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::*; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
prpr::tl_file!("resource" rtl); | ||
prpr_l10n::tl_file!("resource" rtl); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use prpr_l10n::tools::check_langfile; | ||
|
||
#[test] | ||
fn check_all() { | ||
match check_langfile(concat!(env!("CARGO_MANIFEST_DIR"), "/locales/")) { | ||
Ok(_) => {} | ||
Err(e) => panic!("Error: {}", e), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[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"] } | ||
walkdir = "2.3.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::{collections::HashMap, sync::Mutex}; | ||
|
||
use tracing::warn; | ||
use unic_langid::LanguageIdentifier; | ||
|
||
use crate::{fallback_langid, FALLBACK_LANG, LANG_IDENTS}; | ||
|
||
pub struct L10nGlobal { | ||
pub lang_map: HashMap<LanguageIdentifier, usize>, | ||
pub order: Mutex<Vec<usize>>, | ||
} | ||
|
||
impl Default for L10nGlobal { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl L10nGlobal { | ||
pub fn new() -> Self { | ||
let mut lang_map = HashMap::new(); | ||
let mut order = Vec::new(); | ||
let locale_lang = sys_locale::get_locale().unwrap_or_else(|| String::from(FALLBACK_LANG)); | ||
let locale_lang: LanguageIdentifier = locale_lang.parse().unwrap_or_else(|_| { | ||
warn!("Invalid locale detected, defaulting to `{}`", FALLBACK_LANG); | ||
// Debug log: send lang tag to log | ||
warn!("Locale detected: {:?}", locale_lang); | ||
fallback_langid!() | ||
}); | ||
for (id, lang) in LANG_IDENTS.iter().enumerate() { | ||
lang_map.insert(lang.clone(), id); | ||
if *lang == locale_lang { | ||
order.push(id); | ||
} | ||
} | ||
order.push(*lang_map.get(&fallback_langid!()).unwrap()); | ||
Self { | ||
lang_map, | ||
order: order.into(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//! Localization utilities. | ||
pub use fluent::{fluent_args, FluentBundle, FluentResource}; | ||
pub use once_cell::sync::Lazy; | ||
pub use unic_langid::LanguageIdentifier; | ||
|
||
use std::sync::atomic::{AtomicU8, Ordering}; | ||
|
||
mod global; | ||
pub use global::*; | ||
|
||
mod local; | ||
pub use local::*; | ||
|
||
mod macros; | ||
|
||
pub mod tools; | ||
|
||
langs! { | ||
"en-US": "English", | ||
"fr-FR": "Français", | ||
"id-ID": "Bahasa Indonesia", | ||
"ja-JP": "日本語", | ||
"ko-KR": "한국어", | ||
"pl-PL": "Polski", | ||
"pt-BR": "Português", | ||
"ru-RU": "Русский", | ||
"th-TH": "แบบไทย", | ||
"vi-VN": "Tiếng Việt", | ||
"zh-CN": "简体中文", | ||
"zh-TW": "繁體中文" | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! fallback_langid { | ||
() => { | ||
unic_langid::langid!("en-US") | ||
}; | ||
} | ||
|
||
pub const FALLBACK_LANG: &str = "en-US"; | ||
|
||
pub static GLOBAL: Lazy<L10nGlobal> = Lazy::new(L10nGlobal::new); | ||
|
||
pub fn set_prefered_locale(locale: Option<LanguageIdentifier>) { | ||
let mut ids = Vec::new(); | ||
let map = &GLOBAL.lang_map; | ||
if let Some(lang) = locale.and_then(|it| map.get(&it)) { | ||
ids.push(*lang); | ||
} | ||
if let Some(lang) = sys_locale::get_locale() | ||
.and_then(|it| it.parse::<LanguageIdentifier>().ok()) | ||
.and_then(|it| map.get(&it)) | ||
{ | ||
ids.push(*lang); | ||
} | ||
ids.push(*map.get(&fallback_langid!()).unwrap()); | ||
*GLOBAL.order.lock().unwrap() = ids; | ||
GENERATION.fetch_add(1, Ordering::Relaxed); | ||
} | ||
|
||
pub fn locale_order() -> Vec<usize> { | ||
GLOBAL.order.lock().unwrap().clone() | ||
} | ||
|
||
pub struct L10nBundles { | ||
inner: Vec<FluentBundle<FluentResource>>, | ||
} | ||
|
||
impl From<Vec<FluentBundle<FluentResource>>> for L10nBundles { | ||
fn from(inner: Vec<FluentBundle<FluentResource>>) -> Self { | ||
Self { inner } | ||
} | ||
} | ||
|
||
unsafe impl Send for L10nBundles {} | ||
unsafe impl Sync for L10nBundles {} | ||
|
||
pub static GENERATION: AtomicU8 = AtomicU8::new(0); |
Oops, something went wrong.