File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11//! Internationalization support using Fluent.
22
33use bevy:: prelude:: * ;
4+ pub use fluent_bundle:: FluentArgs ;
45use fluent_bundle:: FluentResource ;
56use fluent_bundle:: concurrent:: FluentBundle ;
67use std:: sync:: Arc ;
@@ -110,6 +111,21 @@ impl I18n {
110111 }
111112 }
112113
114+ /// Get a localized string with named arguments.
115+ pub fn t_args ( & self , id : & str , args : & fluent_bundle:: FluentArgs ) -> String {
116+ let msg = self . bundle . get_message ( id) ;
117+ match msg {
118+ Some ( msg) => {
119+ let pattern = msg. value ( ) . expect ( "message has no value" ) ;
120+ let mut errors = vec ! [ ] ;
121+ self . bundle
122+ . format_pattern ( pattern, Some ( args) , & mut errors)
123+ . to_string ( )
124+ }
125+ None => id. to_string ( ) ,
126+ }
127+ }
128+
113129 fn build_bundle ( locale : Locale , custom : & [ ( Locale , String ) ] ) -> FluentBundle < FluentResource > {
114130 let lang_id = locale. lang_id ( ) ;
115131 let source = locale. ftl_source ( ) ;
You can’t perform that action at this time.
0 commit comments