@@ -58,13 +58,55 @@ pub fn exe_path() -> RocResult<RocList<u8>, ()> {
5858 }
5959}
6060
61+ #[ cfg( target_os = "macos" ) ]
62+ fn locale_from_env ( ) -> Option < String > {
63+ for key in [ "LC_ALL" , "LC_CTYPE" , "LANG" ] {
64+ if let Ok ( value) = std:: env:: var ( key) {
65+ let trimmed = value. trim ( ) ;
66+ if trimmed. is_empty ( ) {
67+ continue ;
68+ }
69+ let locale = trimmed
70+ . split ( '.' )
71+ . next ( )
72+ . unwrap_or ( trimmed)
73+ . split ( '@' )
74+ . next ( )
75+ . unwrap_or ( trimmed)
76+ . trim ( ) ;
77+ if !locale. is_empty ( ) {
78+ return Some ( locale. to_string ( ) ) ;
79+ }
80+ }
81+ }
82+
83+ None
84+ }
85+
86+ #[ cfg( target_os = "macos" ) ]
87+ pub fn get_locale ( ) -> RocResult < RocStr , ( ) > {
88+ locale_from_env ( )
89+ . map ( |locale| RocResult :: ok ( locale. as_str ( ) . into ( ) ) )
90+ . unwrap_or_else ( || RocResult :: err ( ( ) ) )
91+ }
92+
93+ #[ cfg( target_os = "macos" ) ]
94+ pub fn get_locales ( ) -> RocList < RocStr > {
95+ match locale_from_env ( ) {
96+ Some ( locale) => RocList :: from_slice ( & [ RocStr :: from ( locale. as_str ( ) ) ] ) ,
97+ None => RocList :: empty ( ) ,
98+ }
99+ }
100+
101+ #[ cfg( not( target_os = "macos" ) ) ]
61102pub fn get_locale ( ) -> RocResult < RocStr , ( ) > {
62103 sys_locale:: get_locale ( ) . map_or_else (
63104 || RocResult :: err ( ( ) ) ,
64105 |locale| RocResult :: ok ( locale. to_string ( ) . as_str ( ) . into ( ) ) ,
65106 )
66107}
67108
109+ #[ cfg( not( target_os = "macos" ) ) ]
68110pub fn get_locales ( ) -> RocList < RocStr > {
69111 const DEFAULT_MAX_LOCALES : usize = 10 ;
70112 let locales = sys_locale:: get_locales ( ) ;
0 commit comments