diff dwt/internal/Compatibility.d @ 317:8c656d6b7300

Add support for SWT language files
author Frank Benoit <benoit@tionex.de>
date Sun, 19 Oct 2008 01:26:56 +0200
parents fd9c62a2998e
children f7a1b148cb35
line wrap: on
line diff
--- a/dwt/internal/Compatibility.d	Sat Oct 18 22:15:57 2008 +0200
+++ b/dwt/internal/Compatibility.d	Sun Oct 19 01:26:56 2008 +0200
@@ -295,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;
 
 /**
@@ -310,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) {}
@@ -331,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;
 }
-++/
 
 
 /**