]> code.delx.au - gnu-emacs/commitdiff
Set locale when run from OS X GUI
authorAlan Third <alan@idiocy.org>
Thu, 11 Feb 2016 02:27:50 +0000 (18:27 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 11 Feb 2016 02:36:04 +0000 (18:36 -0800)
* src/emacs.c (main): Call ns_init_locale.
* src/nsterm.m (ns_init_locale): Get locale from OS and set LANG.
* src/nsterm.h: Include ns_init_locale.

src/emacs.c
src/nsterm.h
src/nsterm.m

index e3cfad0f7f8de00d7ded9b0112d9b16b3625708e..ab5d777aa2eb0d375a16472a7477e6b2e3e3b775 100644 (file)
@@ -1310,6 +1310,11 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
   init_ntproc (dumping); /* must precede init_editfns.  */
 #endif
 
+#ifdef HAVE_NS
+  /* Initialise the locale from user defaults. */
+  ns_init_locale();
+#endif
+
   /* Initialize and GC-protect Vinitial_environment and
      Vprocess_environment before set_initial_environment fills them
      in.  */
index 6ca584e6774904989590b9089e22511cc5bf158e..fa5399c7f90e469bbcf7d171fb6e6cfb0cf872af 100644 (file)
@@ -1141,6 +1141,8 @@ extern void  ns_retain_object (void *obj);
 extern void *ns_alloc_autorelease_pool (void);
 extern void ns_release_autorelease_pool (void *);
 extern const char *ns_get_defaults_value (const char *key);
+extern void ns_init_locale (void);
+
 
 /* in nsmenu */
 extern void update_frame_tool_bar (struct frame *f);
index f77aadba67c59712b69d3fc82f23031876fe8ccb..43d1377f8a717cf6b9be8661fb2acb5d4cbb693a 100644 (file)
@@ -585,6 +585,27 @@ ns_load_path (void)
 }
 
 
+void
+ns_init_locale (void)
+/* OS X doesn't set any environment variables for the locale when run
+   from the GUI. Get the locale from the OS and set LANG. */
+{
+  NSLocale *locale = [NSLocale currentLocale];
+
+  NSTRACE ("ns_init_locale");
+
+  @try
+    {
+      /* Set LANG to locale, but not if LANG is already set. */
+      setenv("LANG", [[locale localeIdentifier] UTF8String], 0);
+    }
+  @catch (NSException *e)
+    {
+      NSLog (@"Locale detection failed: %@: %@", [e name], [e reason]);
+    }
+}
+
+
 void
 ns_release_object (void *obj)
 /* --------------------------------------------------------------------------