diff dwt/dwthelper/ResourceBundle.d @ 332:9e715c0a8376

Support for SWT language files
author Frank Benoit <benoit@tionex.de>
date Sun, 19 Oct 2008 01:20:57 +0200
parents 380bad9f6852
children 6757eb934b0b
line wrap: on
line diff
--- a/dwt/dwthelper/ResourceBundle.d	Sat Oct 18 22:04:23 2008 +0200
+++ b/dwt/dwthelper/ResourceBundle.d	Sun Oct 19 01:20:57 2008 +0200
@@ -9,12 +9,48 @@
 import dwt.DWT;
 import dwt.dwthelper.utils;
 import tango.io.File;
+import tango.text.locale.Core;
+
+import tango.util.log.Trace;
 
 class ResourceBundle {
 
     String[ String ] map;
 
+    /++
+     + First entry is the default entry if no maching locale is found
+     +/
+    public this( ImportData[] data ){
+        char[] name = Culture.current().name.dup;
+        if( name.length is 5 && name[2] is '-' ){
+            name[2] = '_';
+            char[] end = "_" ~ name ~ ".properties";
+            foreach( entry; data ){
+                if( entry.name.length > end.length && entry.name[ $-end.length .. $ ] == end ){
+                    Trace.formatln( "ResourceBundle {}", entry.name );
+                    initialize( cast(char[])entry.data );
+                    return;
+                }
+            }
+        }
+        char[] end = "_" ~ name[0..2] ~ ".properties";
+        foreach( entry; data ){
+            if( entry.name.length > end.length && entry.name[ $-end.length .. $ ] == end ){
+                Trace.formatln( "ResourceBundle {}", entry.name );
+                initialize( cast(char[])entry.data );
+                return;
+            }
+        }
+        Trace.formatln( "ResourceBundle default" );
+        initialize( cast(char[])data[0].data );
+    }
+    public this( ImportData data ){
+        initialize( cast(char[])data.data );
+    }
     public this( String data ){
+        initialize( data );
+    }
+    private void initialize( String data ){
         String line;
         int dataIndex;
 
@@ -122,8 +158,11 @@
         return map.keys;
     }
 
+    public static ResourceBundle getBundle( ImportData[] data ){
+        return new ResourceBundle( data );
+    }
     public static ResourceBundle getBundle( ImportData data ){
-        return new ResourceBundle( cast(String) data.data );
+        return new ResourceBundle( data );
     }
     public static ResourceBundle getBundle( String name ){
         try{