Remove FluentErgo from the l10n stack
This commit is contained in:
parent
15b1d4bfd6
commit
034bda502a
|
@ -1,7 +1,6 @@
|
|||
// This file was autogenerated from l10n-codegen-rust. Edits will be lost
|
||||
// on next generation.
|
||||
use l10n::Message;
|
||||
use fluent_ergonomics::FluentErgo;
|
||||
use fluent::FluentArgs;
|
||||
|
||||
pub struct Hello {
|
||||
|
@ -9,24 +8,25 @@ pub struct Hello {
|
|||
}
|
||||
|
||||
impl Message for Hello {
|
||||
fn localize(&self, bundle: &FluentErgo) -> String {
|
||||
let mut args = FluentArgs::new();
|
||||
args.set("name", self.name.clone());
|
||||
bundle.tr("hello", Some(&args)).unwrap()
|
||||
}
|
||||
fn msgid(&self) -> &str {
|
||||
"hello"
|
||||
}
|
||||
|
||||
pub struct NothingHere;
|
||||
impl Message for NothingHere {
|
||||
fn localize(&self, bundle: &FluentErgo) -> String {
|
||||
bundle.tr("nothing-here", None).unwrap()
|
||||
fn args(&self) -> Option<FluentArgs> {
|
||||
let mut args = FluentArgs::new();
|
||||
args.set("name", self.name.clone());
|
||||
Some(args)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Welcome;
|
||||
impl Message for Welcome {
|
||||
fn localize(&self, bundle: &FluentErgo) -> String {
|
||||
bundle.tr("welcome", None).unwrap()
|
||||
fn msgid(&self) -> &str {
|
||||
"welcome"
|
||||
}
|
||||
|
||||
fn args(&self) -> Option<FluentArgs> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,9 +35,24 @@ pub struct GamesInDatabase {
|
|||
}
|
||||
|
||||
impl Message for GamesInDatabase {
|
||||
fn localize(&self, bundle: &FluentErgo) -> String {
|
||||
fn msgid(&self) -> &str {
|
||||
"games-in-database"
|
||||
}
|
||||
|
||||
fn args(&self) -> Option<FluentArgs> {
|
||||
let mut args = FluentArgs::new();
|
||||
args.set("count", self.count.clone());
|
||||
bundle.tr("games-in-database", Some(&args)).unwrap()
|
||||
Some(args)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct NothingHere;
|
||||
impl Message for NothingHere {
|
||||
fn msgid(&self) -> &str {
|
||||
"nothing-here"
|
||||
}
|
||||
|
||||
fn args(&self) -> Option<FluentArgs> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,8 +81,12 @@ impl Message {
|
|||
|
||||
struct_strs.push(format!("pub struct {}; ", self.name.to_case(Case::Pascal)));
|
||||
struct_strs.push(format!("impl Message for {} {{
|
||||
fn localize(&self, bundle: &FluentErgo) -> String {{
|
||||
bundle.tr(\"{}\", None).unwrap()
|
||||
fn msgid(&self) -> &str {{
|
||||
\"{}\"
|
||||
}}
|
||||
|
||||
fn args(&self) -> Option<FluentArgs> {{
|
||||
None
|
||||
}}
|
||||
}}",
|
||||
self.name.to_case(Case::Pascal),
|
||||
|
@ -114,15 +118,19 @@ impl Message {
|
|||
|
||||
struct_strs.push(format!(
|
||||
"impl Message for {} {{
|
||||
fn localize(&self, bundle: &FluentErgo) -> String {{
|
||||
fn msgid(&self) -> &str {{
|
||||
\"{}\"
|
||||
}}
|
||||
|
||||
fn args(&self) -> Option<FluentArgs> {{
|
||||
let mut args = FluentArgs::new();
|
||||
{}
|
||||
bundle.tr(\"{}\", Some(&args)).unwrap()
|
||||
Some(args)
|
||||
}}
|
||||
}}",
|
||||
self.name.to_case(Case::Pascal),
|
||||
parameters,
|
||||
self.name,
|
||||
parameters,
|
||||
));
|
||||
|
||||
struct_strs.join("\n")
|
||||
|
@ -144,7 +152,6 @@ fn main() {
|
|||
println!("// This file was autogenerated from l10n-codegen-rust. Edits will be lost
|
||||
// on next generation.");
|
||||
println!("use l10n::Message;");
|
||||
println!("use fluent_ergonomics::FluentErgo;");
|
||||
println!("use fluent::FluentArgs;");
|
||||
|
||||
let messages = messages
|
||||
|
|
|
@ -68,12 +68,13 @@ impl From<icu::locid::Error> for L10NError {
|
|||
// However, I have not found a mechanism in Fluent to identify all of the placeholders within a
|
||||
// message, so I'm not even sure that I can automate this code generation.
|
||||
pub trait Message {
|
||||
fn localize(&self, bundle: &FluentErgo) -> String;
|
||||
fn msgid(&self) -> &str;
|
||||
fn args(&self) -> Option<FluentArgs>;
|
||||
}
|
||||
|
||||
pub struct L10N {
|
||||
messages_root: std::path::PathBuf,
|
||||
message_bundle: FluentErgo,
|
||||
message_bundles: Vec<FluentBundle<FluentResource>>,
|
||||
|
||||
locales: NonEmptyList<Locale>,
|
||||
zone: chrono_tz::Tz,
|
||||
|
@ -94,7 +95,8 @@ impl L10N {
|
|||
let english_phrases = FluentResource::try_new
|
||||
*/
|
||||
|
||||
let message_bundle = {
|
||||
let message_bundles = {
|
||||
/*
|
||||
let mut english_messages = messages_root.clone();
|
||||
english_messages.push("en-US.ftl");
|
||||
|
||||
|
@ -102,12 +104,14 @@ impl L10N {
|
|||
let mut messages = FluentErgo::new(&[langid.clone()]);
|
||||
let _ = messages.add_from_file(langid, &english_messages);
|
||||
|
||||
messages
|
||||
vec![messages]
|
||||
*/
|
||||
vec![]
|
||||
};
|
||||
|
||||
Self {
|
||||
messages_root,
|
||||
message_bundle,
|
||||
message_bundles,
|
||||
locales,
|
||||
zone,
|
||||
}
|
||||
|
@ -156,12 +160,14 @@ impl L10N {
|
|||
// parameters. In an ideal world, neither of these can be incorrect. Messages are all checked
|
||||
// at compile time, as are their parameters. That implies an enumeration, with one element per
|
||||
// message, and with each element knowing its parameters.
|
||||
pub fn messages(&self) -> FluentErgo {
|
||||
self.message_bundle.clone()
|
||||
}
|
||||
// pub fn messages(&self) -> Vec<FluentBundle<FluentResource>> {
|
||||
// self.message_bundles.clone()
|
||||
// }
|
||||
|
||||
pub fn tr(&self, message: impl Message) -> String {
|
||||
message.localize(&self.message_bundle)
|
||||
let msg = self.message_bundles[0].get_message(message.msgid()).and_then(|msg| msg.value()).unwrap();
|
||||
let mut errors = vec![];
|
||||
self.message_bundles[0].format_pattern(msg, message.args().as_ref(), &mut errors).to_string()
|
||||
}
|
||||
|
||||
pub fn format_date_time_utc(
|
||||
|
|
Loading…
Reference in New Issue