Changeset 317:8c656d6b7300
- Timestamp:
- 10/18/08 19:26:56 (3 months ago)
- Files:
-
- dwt/dwthelper/ResourceBundle.d (modified) (3 diffs)
- dwt/internal/Compatibility.d (modified) (3 diffs)
- res/swt.internal.SWTMessages.properties (added)
- res/swt.internal.SWTMessages_ar.properties (added)
- res/swt.internal.SWTMessages_cs.properties (added)
- res/swt.internal.SWTMessages_da.properties (added)
- res/swt.internal.SWTMessages_de.properties (added)
- res/swt.internal.SWTMessages_el.properties (added)
- res/swt.internal.SWTMessages_es.properties (added)
- res/swt.internal.SWTMessages_fi.properties (added)
- res/swt.internal.SWTMessages_fr.properties (added)
- res/swt.internal.SWTMessages_hu.properties (added)
- res/swt.internal.SWTMessages_it.properties (added)
- res/swt.internal.SWTMessages_iw.properties (added)
- res/swt.internal.SWTMessages_ja.properties (added)
- res/swt.internal.SWTMessages_ko.properties (added)
- res/swt.internal.SWTMessages_nl.properties (added)
- res/swt.internal.SWTMessages_no.properties (added)
- res/swt.internal.SWTMessages_pl.properties (added)
- res/swt.internal.SWTMessages_pt.properties (added)
- res/swt.internal.SWTMessages_pt_BR.properties (added)
- res/swt.internal.SWTMessages_ru.properties (added)
- res/swt.internal.SWTMessages_sv.properties (added)
- res/swt.internal.SWTMessages_tr.properties (added)
- res/swt.internal.SWTMessages_zh.properties (added)
- res/swt.internal.SWTMessages_zh_HK.properties (added)
- res/swt.internal.SWTMessages_zh_TW.properties (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
dwt/dwthelper/ResourceBundle.d
r212 r317 10 10 import dwt.dwthelper.utils; 11 11 import tango.io.File; 12 import tango.text.locale.Core; 13 14 import tango.util.log.Trace; 12 15 13 16 class ResourceBundle { … … 15 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 50 public this( String data ){ 51 initialize( data ); 52 } 53 private void initialize( String data ){ 18 54 String line; 19 55 int dataIndex; … … 123 159 } 124 160 161 public static ResourceBundle getBundle( ImportData[] data ){ 162 return new ResourceBundle( data ); 163 } 125 164 public static ResourceBundle getBundle( ImportData data ){ 126 return new ResourceBundle( cast(String) data.data );165 return new ResourceBundle( data ); 127 166 } 128 167 public static ResourceBundle getBundle( String name ){ dwt/internal/Compatibility.d
r246 r317 296 296 proc.execute; 297 297 } 298 /++ PORTING_LEFT 298 299 const ImportData[] SWTMessagesBundleData = [ 300 getImportData!( "swt.internal.SWTMessages.properties" ), 301 getImportData!( "swt.internal.SWTMessages_ar.properties" ), 302 getImportData!( "swt.internal.SWTMessages_cs.properties" ), 303 getImportData!( "swt.internal.SWTMessages_da.properties" ), 304 getImportData!( "swt.internal.SWTMessages_de.properties" ), 305 getImportData!( "swt.internal.SWTMessages_el.properties" ), 306 getImportData!( "swt.internal.SWTMessages_es.properties" ), 307 getImportData!( "swt.internal.SWTMessages_fi.properties" ), 308 getImportData!( "swt.internal.SWTMessages_fr.properties" ), 309 getImportData!( "swt.internal.SWTMessages_hu.properties" ), 310 getImportData!( "swt.internal.SWTMessages_it.properties" ), 311 getImportData!( "swt.internal.SWTMessages_iw.properties" ), 312 getImportData!( "swt.internal.SWTMessages_ja.properties" ), 313 getImportData!( "swt.internal.SWTMessages_ko.properties" ), 314 getImportData!( "swt.internal.SWTMessages_nl.properties" ), 315 getImportData!( "swt.internal.SWTMessages_no.properties" ), 316 getImportData!( "swt.internal.SWTMessages_pl.properties" ), 317 getImportData!( "swt.internal.SWTMessages_pt_BR.properties" ), 318 getImportData!( "swt.internal.SWTMessages_pt.properties" ), 319 getImportData!( "swt.internal.SWTMessages_ru.properties" ), 320 getImportData!( "swt.internal.SWTMessages_sv.properties" ), 321 getImportData!( "swt.internal.SWTMessages_tr.properties" ), 322 getImportData!( "swt.internal.SWTMessages_zh_HK.properties" ), 323 getImportData!( "swt.internal.SWTMessages_zh.properties" ), 324 getImportData!( "swt.internal.SWTMessages_zh_TW.properties" ) 325 ]; 326 299 327 private static ResourceBundle msgs = null; 300 328 … … 311 339 String answer = key; 312 340 313 if (key ==null) {341 if (key is null) { 314 342 DWT.error (DWT.ERROR_NULL_ARGUMENT); 315 343 } 316 if (msgs ==null) {344 if (msgs is null) { 317 345 try { 318 msgs = ResourceBundle.getBundle( "dwt.internal.SWTMessages"); //$NON-NLS-1$346 msgs = ResourceBundle.getBundle(SWTMessagesBundleData); //$NON-NLS-1$ 319 347 } catch (MissingResourceException ex) { 320 answer = key +" (no resource bundle)"; //$NON-NLS-1$348 answer = key ~ " (no resource bundle)"; //$NON-NLS-1$ 321 349 } 322 350 } 323 if (msgs ! =null) {351 if (msgs !is null) { 324 352 try { 325 353 answer = msgs.getString(key); … … 332 360 String answer = key; 333 361 334 if (key == null || args ==null) {362 if (key is null || args is null) { 335 363 DWT.error (DWT.ERROR_NULL_ARGUMENT); 336 364 } 337 if (msgs ==null) {365 if (msgs is null) { 338 366 try { 339 msgs = ResourceBundle.getBundle( "dwt.internal.SWTMessages"); //$NON-NLS-1$367 msgs = ResourceBundle.getBundle(SWTMessagesBundleData); //$NON-NLS-1$ 340 368 } catch (MissingResourceException ex) { 341 answer = key +" (no resource bundle)"; //$NON-NLS-1$369 answer = key ~ " (no resource bundle)"; //$NON-NLS-1$ 342 370 } 343 371 } 344 if (msgs ! =null) {372 if (msgs !is null) { 345 373 try { 346 MessageFormat formatter = new MessageFormat(""); 347 formatter.applyPattern(msgs.getString(key)); 348 answer = formatter.format(args); 374 char[] frmt = msgs.getString(key); 375 switch( args.length ){ 376 case 0: answer = Format(frmt); break; 377 case 1: answer = Format(frmt, args[0]); break; 378 case 2: answer = Format(frmt, args[0], args[1]); break; 379 case 3: answer = Format(frmt, args[0], args[1], args[2]); break; 380 case 4: answer = Format(frmt, args[0], args[1], args[2], args[3]); break; 381 case 5: answer = Format(frmt, args[0], args[1], args[2], args[3], args[4]); break; 382 default: 383 implMissing(__FILE__, __LINE__ ); 384 } 349 385 } catch (MissingResourceException ex2) {} 350 386 } 351 387 return answer; 352 388 } 353 ++/354 389 355 390
