Register functions in translation

This commit is contained in:
Jonathan Brouwer 2026-02-04 17:17:45 +01:00
parent 66daca1a85
commit 6782a190f2
No known key found for this signature in database
GPG key ID: F13E55D38C971DEF
2 changed files with 3 additions and 2 deletions

View file

@ -192,7 +192,7 @@ pub fn fluent_bundle(
Ok(Some(bundle))
}
fn register_functions(bundle: &mut FluentBundle) {
pub fn register_functions<R, M>(bundle: &mut fluent_bundle::bundle::FluentBundle<R, M>) {
bundle
.add_function("STREQ", |positional, _named| match positional {
[FluentValue::String(a), FluentValue::String(b)] => format!("{}", (a == b)).into(),

View file

@ -3,8 +3,8 @@ use std::env;
use std::error::Report;
use std::sync::Arc;
use rustc_error_messages::langid;
pub use rustc_error_messages::{FluentArgs, LazyFallbackBundle};
use rustc_error_messages::{langid, register_functions};
use tracing::{debug, trace};
use crate::error::{TranslateError, TranslateErrorKind};
@ -91,6 +91,7 @@ impl Translator {
let mut bundle = fluent_bundle::FluentBundle::new(vec![langid!("en-US")]);
bundle.set_use_isolating(false);
bundle.add_resource(resource).unwrap();
register_functions(&mut bundle);
let message = bundle.get_message(GENERATED_MSG_ID).unwrap();
let value = message.value().unwrap();