@@ -182,6 +182,9 @@ pub fn fluent_bundle(
182182 trace ! ( ?locale) ;
183183 let mut bundle = new_bundle ( vec ! [ locale] ) ;
184184
185+ // Add convenience functions available to ftl authors.
186+ register_functions ( & mut bundle) ;
187+
185188 // Fluent diagnostics can insert directionality isolation markers around interpolated variables
186189 // indicating that there may be a shift from right-to-left to left-to-right text (or
187190 // vice-versa). These are disabled because they are sometimes visible in the error output, but
@@ -244,6 +247,15 @@ pub fn fluent_bundle(
244247 Ok ( Some ( bundle) )
245248}
246249
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+
247259/// Type alias for the result of `fallback_fluent_bundle` - a reference-counted pointer to a lazily
248260/// evaluated fluent bundle.
249261pub type LazyFallbackBundle = Lrc < Lazy < FluentBundle , impl FnOnce ( ) -> FluentBundle > > ;
@@ -256,6 +268,9 @@ pub fn fallback_fluent_bundle(
256268) -> LazyFallbackBundle {
257269 Lrc :: new ( Lazy :: new ( move || {
258270 let mut fallback_bundle = new_bundle ( vec ! [ langid!( "en-US" ) ] ) ;
271+
272+ register_functions ( & mut fallback_bundle) ;
273+
259274 // See comment in `fluent_bundle`.
260275 fallback_bundle. set_use_isolating ( with_directionality_markers) ;
261276
0 commit comments