diff dwt/internal/Compatibility.d @ 332:9e715c0a8376

Support for SWT language files
author Frank Benoit <benoit@tionex.de>
date Sun, 19 Oct 2008 01:20:57 +0200
parents c0d810de7093
children
line wrap: on
line diff
--- a/dwt/internal/Compatibility.d	Sat Oct 18 22:04:23 2008 +0200
+++ b/dwt/internal/Compatibility.d	Sun Oct 19 01:20:57 2008 +0200
@@ -27,10 +27,12 @@
 public import dwt.dwthelper.FileOutputStream;
 public import dwt.dwthelper.InflaterInputStream;
 import dwt.dwthelper.BufferedInputStream;
+import dwt.dwthelper.ResourceBundle;
 
 import Math = tango.math.Math;
 import Unicode = tango.text.Unicode;
 import tango.sys.Process;
+import tango.text.convert.Format;
 
 /**
  * This class is a placeholder for utility methods commonly
@@ -293,7 +295,35 @@
     auto proc = new Process( progArray );
     proc.execute;
 }
-/++ PORTING_LEFT
+
+const ImportData[] SWTMessagesBundleData = [
+    getImportData!( "swt.internal.SWTMessages.properties" ),
+    getImportData!( "swt.internal.SWTMessages_ar.properties" ),
+    getImportData!( "swt.internal.SWTMessages_cs.properties" ),
+    getImportData!( "swt.internal.SWTMessages_da.properties" ),
+    getImportData!( "swt.internal.SWTMessages_de.properties" ),
+    getImportData!( "swt.internal.SWTMessages_el.properties" ),
+    getImportData!( "swt.internal.SWTMessages_es.properties" ),
+    getImportData!( "swt.internal.SWTMessages_fi.properties" ),
+    getImportData!( "swt.internal.SWTMessages_fr.properties" ),
+    getImportData!( "swt.internal.SWTMessages_hu.properties" ),
+    getImportData!( "swt.internal.SWTMessages_it.properties" ),
+    getImportData!( "swt.internal.SWTMessages_iw.properties" ),
+    getImportData!( "swt.internal.SWTMessages_ja.properties" ),
+    getImportData!( "swt.internal.SWTMessages_ko.properties" ),
+    getImportData!( "swt.internal.SWTMessages_nl.properties" ),
+    getImportData!( "swt.internal.SWTMessages_no.properties" ),
+    getImportData!( "swt.internal.SWTMessages_pl.properties" ),
+    getImportData!( "swt.internal.SWTMessages_pt_BR.properties" ),
+    getImportData!( "swt.internal.SWTMessages_pt.properties" ),
+    getImportData!( "swt.internal.SWTMessages_ru.properties" ),
+    getImportData!( "swt.internal.SWTMessages_sv.properties" ),
+    getImportData!( "swt.internal.SWTMessages_tr.properties" ),
+    getImportData!( "swt.internal.SWTMessages_zh_HK.properties" ),
+    getImportData!( "swt.internal.SWTMessages_zh.properties" ),
+    getImportData!( "swt.internal.SWTMessages_zh_TW.properties" )
+];
+
 private static ResourceBundle msgs = null;
 
 /**
@@ -308,17 +338,17 @@
 public static String getMessage(String key) {
     String answer = key;
 
-    if (key == null) {
+    if (key is null) {
         DWT.error (DWT.ERROR_NULL_ARGUMENT);
     }
-    if (msgs == null) {
+    if (msgs is null) {
         try {
-            msgs = ResourceBundle.getBundle("dwt.internal.SWTMessages"); //$NON-NLS-1$
+            msgs = ResourceBundle.getBundle(SWTMessagesBundleData); //$NON-NLS-1$
         } catch (MissingResourceException ex) {
-            answer = key + " (no resource bundle)"; //$NON-NLS-1$
+            answer = key ~ " (no resource bundle)"; //$NON-NLS-1$
         }
     }
-    if (msgs != null) {
+    if (msgs !is null) {
         try {
             answer = msgs.getString(key);
         } catch (MissingResourceException ex2) {}
@@ -329,26 +359,33 @@
 public static String getMessage(String key, Object[] args) {
     String answer = key;
 
-    if (key == null || args == null) {
+    if (key is null || args is null) {
         DWT.error (DWT.ERROR_NULL_ARGUMENT);
     }
-    if (msgs == null) {
+    if (msgs is null) {
         try {
-            msgs = ResourceBundle.getBundle("dwt.internal.SWTMessages"); //$NON-NLS-1$
+            msgs = ResourceBundle.getBundle(SWTMessagesBundleData); //$NON-NLS-1$
         } catch (MissingResourceException ex) {
-            answer = key + " (no resource bundle)"; //$NON-NLS-1$
+            answer = key ~ " (no resource bundle)"; //$NON-NLS-1$
         }
     }
-    if (msgs != null) {
+    if (msgs !is null) {
         try {
-            MessageFormat formatter = new MessageFormat("");
-            formatter.applyPattern(msgs.getString(key));
-            answer = formatter.format(args);
+            char[] frmt = msgs.getString(key);
+            switch( args.length ){
+            case 0: answer = Format(frmt); break;
+            case 1: answer = Format(frmt, args[0]); break;
+            case 2: answer = Format(frmt, args[0], args[1]); break;
+            case 3: answer = Format(frmt, args[0], args[1], args[2]); break;
+            case 4: answer = Format(frmt, args[0], args[1], args[2], args[3]); break;
+            case 5: answer = Format(frmt, args[0], args[1], args[2], args[3], args[4]); break;
+            default:
+                implMissing(__FILE__, __LINE__ );
+            }
         } catch (MissingResourceException ex2) {}
     }
     return answer;
 }
-++/
 
 
 /**