@@ -182,6 +182,9 @@ pub fn fluent_bundle(
182
182
trace ! ( ?locale) ;
183
183
let mut bundle = new_bundle ( vec ! [ locale] ) ;
184
184
185
+ // Add convenience functions available to ftl authors.
186
+ register_functions ( & mut bundle) ;
187
+
185
188
// Fluent diagnostics can insert directionality isolation markers around interpolated variables
186
189
// indicating that there may be a shift from right-to-left to left-to-right text (or
187
190
// vice-versa). These are disabled because they are sometimes visible in the error output, but
@@ -244,6 +247,15 @@ pub fn fluent_bundle(
244
247
Ok ( Some ( bundle) )
245
248
}
246
249
250
+ fn register_functions ( bundle : & mut FluentBundle ) {
251
+ bundle
252
+ . add_function ( "STREQ" , |positional, _named| match positional {
253
+ [ FluentValue :: String ( a) , FluentValue :: String ( b) ] => format ! ( "{}" , ( a == b) ) . into ( ) ,
254
+ _ => FluentValue :: Error ,
255
+ } )
256
+ . expect ( "Failed to add a function to the bundle." ) ;
257
+ }
258
+
247
259
/// Type alias for the result of `fallback_fluent_bundle` - a reference-counted pointer to a lazily
248
260
/// evaluated fluent bundle.
249
261
pub type LazyFallbackBundle = Lrc < Lazy < FluentBundle , impl FnOnce ( ) -> FluentBundle > > ;
@@ -256,6 +268,9 @@ pub fn fallback_fluent_bundle(
256
268
) -> LazyFallbackBundle {
257
269
Lrc :: new ( Lazy :: new ( move || {
258
270
let mut fallback_bundle = new_bundle ( vec ! [ langid!( "en-US" ) ] ) ;
271
+
272
+ register_functions ( & mut fallback_bundle) ;
273
+
259
274
// See comment in `fluent_bundle`.
260
275
fallback_bundle. set_use_isolating ( with_directionality_markers) ;
261
276
0 commit comments