@@ -37,15 +37,47 @@ pub fn locale_decimal_separator() -> &'static str {
3737 DECIMAL_SEP . get_or_init ( || get_decimal_separator ( get_numeric_locale ( ) . 0 . clone ( ) ) )
3838}
3939
40+ /// Return the grouping separator for the given locale
41+ fn get_grouping_separator ( loc : Locale ) -> String {
42+ let data_locale = DataLocale :: from ( loc) ;
43+
44+ let request = DataRequest {
45+ id : DataIdentifierBorrowed :: for_locale ( & data_locale) ,
46+ metadata : DataRequestMetadata :: default ( ) ,
47+ } ;
48+
49+ let response: DataResponse < DecimalSymbolsV1 > =
50+ icu_decimal:: provider:: Baked . load ( request) . unwrap ( ) ;
51+
52+ response. payload . get ( ) . grouping_separator ( ) . to_string ( )
53+ }
54+
55+ /// Return the grouping separator from the language we're working with.
56+ /// Example:
57+ /// Say we need to format 1,000
58+ /// en_US: 1,000 -> grouping separator is ','
59+ /// fr_FR: 1 000 -> grouping separator is '\u{202f}'
60+ pub fn locale_grouping_separator ( ) -> & ' static str {
61+ static GROUPING_SEP : OnceLock < String > = OnceLock :: new ( ) ;
62+
63+ GROUPING_SEP . get_or_init ( || get_grouping_separator ( get_numeric_locale ( ) . 0 . clone ( ) ) )
64+ }
65+
4066#[ cfg( test) ]
4167mod tests {
4268 use icu_locale:: locale;
4369
44- use super :: get_decimal_separator;
70+ use super :: { get_decimal_separator, get_grouping_separator } ;
4571
4672 #[ test]
47- fn test_simple_separator ( ) {
73+ fn test_simple_decimal_separator ( ) {
4874 assert_eq ! ( get_decimal_separator( locale!( "en" ) ) , "." ) ;
4975 assert_eq ! ( get_decimal_separator( locale!( "fr" ) ) , "," ) ;
5076 }
77+
78+ #[ test]
79+ fn test_simple_grouping_separator ( ) {
80+ assert_eq ! ( get_grouping_separator( locale!( "en" ) ) , "," ) ;
81+ assert_eq ! ( get_grouping_separator( locale!( "fr" ) ) , "\u{202f} " ) ;
82+ }
5183}
0 commit comments