@@ -669,8 +669,47 @@ unsafe fn write_try_bool_result(
669669 std:: ptr:: write ( ret_ptr as * mut TryBoolPathErr , try_result) ;
670670}
671671
672+ #[ cfg( target_os = "macos" ) ]
673+ fn locale_from_env ( ) -> Option < String > {
674+ for key in [ "LC_ALL" , "LC_CTYPE" , "LANG" ] {
675+ if let Ok ( value) = std:: env:: var ( key) {
676+ let trimmed = value. trim ( ) ;
677+ if trimmed. is_empty ( ) {
678+ continue ;
679+ }
680+ let locale = trimmed
681+ . split ( '.' )
682+ . next ( )
683+ . unwrap_or ( trimmed)
684+ . split ( '@' )
685+ . next ( )
686+ . unwrap_or ( trimmed)
687+ . trim ( ) ;
688+ if !locale. is_empty ( ) {
689+ return Some ( locale. to_string ( ) ) ;
690+ }
691+ }
692+ }
693+
694+ None
695+ }
696+
697+ /// Hosted function: Locale.all!
698+ /// Takes {}, returns List(Str)
699+ #[ cfg( target_os = "macos" ) ]
700+ extern "C" fn hosted_locale_all ( ops : * const RocOps , ret_ptr : * mut c_void , _args_ptr : * mut c_void ) {
701+ let roc_ops = unsafe { & * ops } ;
702+ let locales = locale_from_env ( ) . unwrap_or_else ( || "en-US" . to_string ( ) ) ;
703+ let mut list = RocList :: with_capacity ( 1 , roc_ops) ;
704+ list. push ( RocStr :: from_str ( & locales, roc_ops) , roc_ops) ;
705+ unsafe {
706+ * ( ret_ptr as * mut RocList < RocStr > ) = list;
707+ }
708+ }
709+
672710/// Hosted function: Locale.all!
673711/// Takes {}, returns List(Str)
712+ #[ cfg( not( target_os = "macos" ) ) ]
674713extern "C" fn hosted_locale_all ( ops : * const RocOps , ret_ptr : * mut c_void , _args_ptr : * mut c_void ) {
675714 let roc_ops = unsafe { & * ops } ;
676715 let locales = sys_locale:: get_locales ( ) . collect :: < Vec < _ > > ( ) ;
@@ -686,6 +725,19 @@ extern "C" fn hosted_locale_all(ops: *const RocOps, ret_ptr: *mut c_void, _args_
686725
687726/// Hosted function: Locale.get!
688727/// Takes {}, returns Str
728+ #[ cfg( target_os = "macos" ) ]
729+ extern "C" fn hosted_locale_get ( ops : * const RocOps , ret_ptr : * mut c_void , _args_ptr : * mut c_void ) {
730+ let roc_ops = unsafe { & * ops } ;
731+ let locale = locale_from_env ( ) . unwrap_or_else ( || "en-US" . to_string ( ) ) ;
732+ let roc_str = RocStr :: from_str ( & locale, roc_ops) ;
733+ unsafe {
734+ * ( ret_ptr as * mut RocStr ) = roc_str;
735+ }
736+ }
737+
738+ /// Hosted function: Locale.get!
739+ /// Takes {}, returns Str
740+ #[ cfg( not( target_os = "macos" ) ) ]
689741extern "C" fn hosted_locale_get ( ops : * const RocOps , ret_ptr : * mut c_void , _args_ptr : * mut c_void ) {
690742 let roc_ops = unsafe { & * ops } ;
691743 let locale = sys_locale:: get_locale ( ) . unwrap_or_else ( || "en-US" . to_string ( ) ) ;
0 commit comments