This is the mail archive of the java-patches@sources.redhat.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PATCH: Make Locale work


This patch sets the "user.region" and "user.language" system
properties so that i18n stuff works. I'm checking it in.

regards

  [ bryce ]


2000-11-29  Bryce McKinlay  <bryce@albatross.co.nz>

	* java/lang/natSystem.cc (init_properties): Set user.language and
	user.region.
	* configure.in: Check for setlocale.
	* configure: Rebuilt.
	* include/config.h.in: Rebuilt.

Index: configure.in
===================================================================
RCS file: /cvs/java/libgcj/libjava/configure.in,v
retrieving revision 1.68
diff -u -r1.68 configure.in
--- configure.in	2000/11/26 01:48:03	1.68
+++ configure.in	2000/11/29 04:42:28
@@ -405,7 +405,7 @@
    AC_CHECK_FUNCS(strerror ioctl select fstat open fsync sleep)
    AC_CHECK_FUNCS(gmtime_r localtime_r readdir_r getpwuid_r getcwd)
    AC_CHECK_FUNCS(access stat mkdir rename rmdir unlink realpath)
-   AC_CHECK_FUNCS(iconv nl_langinfo)
+   AC_CHECK_FUNCS(iconv nl_langinfo setlocale)
    AC_CHECK_FUNCS(inet_aton inet_addr, break)
    AC_CHECK_FUNCS(inet_pton uname inet_ntoa)
    AC_CHECK_FUNCS(backtrace fork execvp pipe)
Index: java/lang/natSystem.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/natSystem.cc,v
retrieving revision 1.30
diff -u -r1.30 natSystem.cc
--- natSystem.cc	2000/11/26 01:48:04	1.30
+++ natSystem.cc	2000/11/29 04:42:28
@@ -339,6 +339,31 @@
 #endif /* HAVE_UNISTD_H */
 #endif /* HAVE_GETCWD */
 
+  // Set user locale properties based on setlocale()
+#ifdef HAVE_SETLOCALE
+  char *locale = setlocale (LC_ALL, "");
+  if (locale && strlen (locale) >= 2)
+    {
+      char buf[3];
+      buf[2] = '\0';
+      // copy the first two chars to user.language
+      strncpy (buf, locale, 2);
+      SET ("user.language", buf);
+      // if the next char is a '_', copy the two after that to user.region
+      locale += 2;
+      if (locale[0] == '_')
+        {
+	  locale++;
+	  strncpy (buf, locale, 2);
+	  SET ("user.region", buf);
+        }
+    }
+  else
+#endif /* HAVE_SETLOCALE */
+    {
+      SET ("user.language", "en");
+    }  
+
   // Set some properties according to whatever was compiled in with
   // `-D'.
   for (int i = 0; _Jv_Compiler_Properties[i]; ++i)
@@ -382,7 +407,7 @@
 	  sb->append ((jchar) ';');
 #else
 	  sb->append ((jchar) ':');
-#endif;
+#endif
 	}
       if (cp != NULL)
 	sb->append (cp);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]