db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1831216 - in /db/derby/code/trunk/java: build/org/apache/derbyBuild/splitmessages.java shared/org/apache/derby/shared/common/i18n/MessageService.java tools/build.xml
Date Wed, 09 May 2018 00:10:48 GMT
Author: rhillegas
Date: Wed May  9 00:10:48 2018
New Revision: 1831216

URL: http://svn.apache.org/viewvc?rev=1831216&view=rev
Log:
DERBY-6945: Move localizations into packages which are specific to the jar files containing
them; commit derby-6945-33-ab-moveLocalizations.diff.

Modified:
    db/derby/code/trunk/java/build/org/apache/derbyBuild/splitmessages.java
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/i18n/MessageService.java
    db/derby/code/trunk/java/tools/build.xml

Modified: db/derby/code/trunk/java/build/org/apache/derbyBuild/splitmessages.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/build/org/apache/derbyBuild/splitmessages.java?rev=1831216&r1=1831215&r2=1831216&view=diff
==============================================================================
--- db/derby/code/trunk/java/build/org/apache/derbyBuild/splitmessages.java (original)
+++ db/derby/code/trunk/java/build/org/apache/derbyBuild/splitmessages.java Wed May  9 00:10:48
2018
@@ -27,11 +27,14 @@ import java.util.*;
 import org.apache.derby.shared.common.i18n.MessageService;
 import org.apache.derby.shared.common.reference.SQLState;
 
-public class splitmessages {
+public class splitmessages
+{
 	/**
 		arg[0] is the destination directory
 		arg[1] is the source file.
 	*/
+
+    private static final String LOCALE_STUB = "locale";
     
     /** 
      *  This is the list of message ids that are shared between
@@ -140,6 +143,8 @@ public class splitmessages {
 
 		boolean addBase = "_en".equals(locale);
 
+        File localizedEngineMessagesDir = new File(localesDir, LOCALE_STUB + locale);
+        localizedEngineMessagesDir.mkdir();
 
 		InputStream is = new BufferedInputStream(new FileInputStream(source), 64 * 1024);
 
@@ -171,9 +176,12 @@ public class splitmessages {
 		for (int i = 0; i < 50; i++) {
 			if (c[i].size() == 0)
 				continue;
-			OutputStream fos = new BufferedOutputStream(
-				new FileOutputStream(new File(localesDir, "m"+i+locale+".properties")), 16 * 1024);
-
+			OutputStream fos = new BufferedOutputStream
+              (
+				new FileOutputStream
+                (new File(localizedEngineMessagesDir, "m"+i+locale+".properties")),
+                16 * 1024
+               );
             
 			c[i].store(fos, (String) null);
 			fos.flush();

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/i18n/MessageService.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/i18n/MessageService.java?rev=1831216&r1=1831215&r2=1831216&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/i18n/MessageService.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/i18n/MessageService.java
Wed May  9 00:10:48 2018
@@ -42,6 +42,8 @@ import java.text.MessageFormat;
 public final class MessageService {
 
 	private static final Locale EN = new Locale("en", "US");
+    private static final String LOCALE_STUB = "locale_";
+    private static final String CLIENT_MESSAGES = "clientmessages";
 
 	private static BundleFinder finder;
 
@@ -177,20 +179,93 @@ public final class MessageService {
 		the resource is not available in the requested locale,
 		default locale or base class the one for en_US is returned.
 	*/
+	public static ResourceBundle getBundleWithEnDefault(String resource, Locale locale)
+    {
+        ResourceBundle retval = null;
+
+        retval = getBundle(resource, locale);
+
+        if (retval == null)
+        {
+            //
+            // This can happen if the database territory overrides
+            // the default Locale, but the territory isn't supported.
+            // Try the default Locale.
+            //
+            Locale defaultLocale = Locale.getDefault();
+
+            if (!defaultLocale.equals(locale))
+            {
+                retval = getBundle(resource, defaultLocale);
+            }
+        }
+
+        //
+        // Ok, fallback on English, the localization bundled into the base Derby jars.
+        // This throws MissingResourceException if the situation is completely
+        // confused.
+        //
+        if (retval == null)
+        {
+            retval = lookupBundle(resource, EN);
+        }
 
-	public static ResourceBundle getBundleWithEnDefault(String resource, Locale locale) {
+        return retval;
+	}
+
+	/**
+		Look up a bundle in the correct package. Returns
+        null if the bundle can't be found.
+	*/
+	private static ResourceBundle getBundle(String resource, Locale locale)
+    {
+        ResourceBundle retval = null;
 
 		try {
-			return ResourceBundle.getBundle(resource, locale);
-		} catch (MissingResourceException mre) {
+            retval = lookupBundle(localizeResourceName(resource, locale.toString()), locale);
+		} catch (MissingResourceException mre) {}
 
-			// This covers the case where neither the
-			// requested locale or the default locale
-			// have a resource.
+        // just try the language. it's better than nothing.
+        if (retval == null)
+        {
+            try {
+                retval = lookupBundle(localizeResourceName(resource, locale.getLanguage()),
locale);
+            } catch (MissingResourceException mre) {}
+        }
 
-			return ResourceBundle.getBundle(resource, EN);
-		}
+        return retval;
 	}
+  
+	/**
+		Use the JVM to lookup a ResourceBundle
+	*/
+	private static ResourceBundle lookupBundle(String resource, Locale locale)
+    {
+        return ResourceBundle.getBundle(resource, locale);
+	}
+  
+    /**
+        Add a directory level named locale_xx_YY to the resource name
+        if it is not the clientmessages resource bundle. So, for instance,
+        "org.apache.derby.loc.tools.toolsmessages" becomes
+        "org.apache.derby.loc.tools.locale_de_DE.toolsmessages".
+    */
+    private static String localizeResourceName(String original, String localeName)
+    {
+        if ((original == null) || (original.contains(CLIENT_MESSAGES))) { return original;
}
+
+        // American English messages are not re-located to a subdirectory
+        if (EN.toString().equals(localeName))
+        { return original; }
+
+        int lastDotIdx = original.lastIndexOf('.');
+        String retval =
+          original.substring(0, lastDotIdx + 1) +
+          LOCALE_STUB + localeName +
+          original.substring(lastDotIdx, original.length());
+
+        return retval;
+    }
 
 	/**
 		Hash function to split messages into 50 files based

Modified: db/derby/code/trunk/java/tools/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/build.xml?rev=1831216&r1=1831215&r2=1831216&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/build.xml (original)
+++ db/derby/code/trunk/java/tools/build.xml Wed May  9 00:10:48 2018
@@ -86,13 +86,62 @@
       </fileset>
     </copy>
 
-    <copy todir="${loc.locales.dir}/tools" flatten="true">
+    <antcall target="copyLocalization">
+      <param name="localization" value="en"/>
+    </antcall>
+    <antcall target="copyLocalization">
+      <param name="localization" value="cs"/>
+    </antcall>
+    <antcall target="copyLocalization">
+      <param name="localization" value="de_DE"/>
+    </antcall>
+    <antcall target="copyLocalization">
+      <param name="localization" value="es"/>
+    </antcall>
+    <antcall target="copyLocalization">
+      <param name="localization" value="hu"/>
+    </antcall>
+    <antcall target="copyLocalization">
+      <param name="localization" value="ja_JP"/>
+    </antcall>
+    <antcall target="copyLocalization">
+      <param name="localization" value="ko_KR"/>
+    </antcall>
+    <antcall target="copyLocalization">
+      <param name="localization" value="qq_PP_testOnly"/>
+    </antcall>
+    <antcall target="copyLocalization">
+      <param name="localization" value="pl"/>
+    </antcall>
+    <antcall target="copyLocalization">
+      <param name="localization" value="pt_BR"/>
+    </antcall>
+    <antcall target="copyLocalization">
+      <param name="localization" value="ru"/>
+    </antcall>
+    <antcall target="copyLocalization">
+      <param name="localization" value="zh_CN"/>
+    </antcall>
+    <antcall target="copyLocalization">
+      <param name="localization" value="zh_TW"/>
+    </antcall>
+    <antcall target="copyLocalization">
+      <param name="localization" value="it"/>
+    </antcall>
+    <antcall target="copyLocalization">
+      <param name="localization" value="fr"/>
+    </antcall>
+
+  </target>
+
+  <target name="copyLocalization">
+    <mkdir dir="${loc.locales.dir}/tools/locale_${localization}"/>
+    <copy todir="${loc.locales.dir}/tools/locale_${localization}">
       <fileset dir="${derby.tools.locales.dir}">
-        <include name="sysinfoMessages_*.properties"/>
-        <include name="toolsmessages_*.properties"/>
+        <include name="sysinfoMessages_${localization}.properties"/>
+        <include name="toolsmessages_${localization}.properties"/>
       </fileset>
     </copy>
-
   </target>
 
   <target name="parser">



Mime
View raw message