comparison 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
comparison
equal deleted inserted replaced
331:9df969c69a1e 332:9e715c0a8376
7 import tango.io.Stdout; 7 import tango.io.Stdout;
8 8
9 import dwt.DWT; 9 import dwt.DWT;
10 import dwt.dwthelper.utils; 10 import dwt.dwthelper.utils;
11 import tango.io.File; 11 import tango.io.File;
12 import tango.text.locale.Core;
13
14 import tango.util.log.Trace;
12 15
13 class ResourceBundle { 16 class ResourceBundle {
14 17
15 String[ String ] map; 18 String[ String ] map;
16 19
20 /++
21 + First entry is the default entry if no maching locale is found
22 +/
23 public this( ImportData[] data ){
24 char[] name = Culture.current().name.dup;
25 if( name.length is 5 && name[2] is '-' ){
26 name[2] = '_';
27 char[] end = "_" ~ name ~ ".properties";
28 foreach( entry; data ){
29 if( entry.name.length > end.length && entry.name[ $-end.length .. $ ] == end ){
30 Trace.formatln( "ResourceBundle {}", entry.name );
31 initialize( cast(char[])entry.data );
32 return;
33 }
34 }
35 }
36 char[] end = "_" ~ name[0..2] ~ ".properties";
37 foreach( entry; data ){
38 if( entry.name.length > end.length && entry.name[ $-end.length .. $ ] == end ){
39 Trace.formatln( "ResourceBundle {}", entry.name );
40 initialize( cast(char[])entry.data );
41 return;
42 }
43 }
44 Trace.formatln( "ResourceBundle default" );
45 initialize( cast(char[])data[0].data );
46 }
47 public this( ImportData data ){
48 initialize( cast(char[])data.data );
49 }
17 public this( String data ){ 50 public this( String data ){
51 initialize( data );
52 }
53 private void initialize( String data ){
18 String line; 54 String line;
19 int dataIndex; 55 int dataIndex;
20 56
21 //tango.io.Stdout.Stdout.formatln( "properties put ..." ); 57 //tango.io.Stdout.Stdout.formatln( "properties put ..." );
22 void readLine(){ 58 void readLine(){
120 156
121 public String[] getKeys(){ 157 public String[] getKeys(){
122 return map.keys; 158 return map.keys;
123 } 159 }
124 160
161 public static ResourceBundle getBundle( ImportData[] data ){
162 return new ResourceBundle( data );
163 }
125 public static ResourceBundle getBundle( ImportData data ){ 164 public static ResourceBundle getBundle( ImportData data ){
126 return new ResourceBundle( cast(String) data.data ); 165 return new ResourceBundle( data );
127 } 166 }
128 public static ResourceBundle getBundle( String name ){ 167 public static ResourceBundle getBundle( String name ){
129 try{ 168 try{
130 scope f = new File(name); 169 scope f = new File(name);
131 return new ResourceBundle( cast(String) f.read() ); 170 return new ResourceBundle( cast(String) f.read() );