comparison 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
comparison
equal deleted inserted replaced
331:9df969c69a1e 332:9e715c0a8376
25 import dwt.DWT; 25 import dwt.DWT;
26 public import dwt.dwthelper.FileInputStream; 26 public import dwt.dwthelper.FileInputStream;
27 public import dwt.dwthelper.FileOutputStream; 27 public import dwt.dwthelper.FileOutputStream;
28 public import dwt.dwthelper.InflaterInputStream; 28 public import dwt.dwthelper.InflaterInputStream;
29 import dwt.dwthelper.BufferedInputStream; 29 import dwt.dwthelper.BufferedInputStream;
30 import dwt.dwthelper.ResourceBundle;
30 31
31 import Math = tango.math.Math; 32 import Math = tango.math.Math;
32 import Unicode = tango.text.Unicode; 33 import Unicode = tango.text.Unicode;
33 import tango.sys.Process; 34 import tango.sys.Process;
35 import tango.text.convert.Format;
34 36
35 /** 37 /**
36 * This class is a placeholder for utility methods commonly 38 * This class is a placeholder for utility methods commonly
37 * used on J2SE platforms but not supported on some J2ME 39 * used on J2SE platforms but not supported on some J2ME
38 * profiles. 40 * profiles.
291 */ 293 */
292 public static void exec(String[] progArray) { 294 public static void exec(String[] progArray) {
293 auto proc = new Process( progArray ); 295 auto proc = new Process( progArray );
294 proc.execute; 296 proc.execute;
295 } 297 }
296 /++ 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
297 private static ResourceBundle msgs = null; 327 private static ResourceBundle msgs = null;
298 328
299 /** 329 /**
300 * Returns the NLS'ed message for the given argument. This is only being 330 * Returns the NLS'ed message for the given argument. This is only being
301 * called from DWT. 331 * called from DWT.
306 * @see DWT#getMessage(String) 336 * @see DWT#getMessage(String)
307 */ 337 */
308 public static String getMessage(String key) { 338 public static String getMessage(String key) {
309 String answer = key; 339 String answer = key;
310 340
311 if (key == null) { 341 if (key is null) {
312 DWT.error (DWT.ERROR_NULL_ARGUMENT); 342 DWT.error (DWT.ERROR_NULL_ARGUMENT);
313 } 343 }
314 if (msgs == null) { 344 if (msgs is null) {
315 try { 345 try {
316 msgs = ResourceBundle.getBundle("dwt.internal.SWTMessages"); //$NON-NLS-1$ 346 msgs = ResourceBundle.getBundle(SWTMessagesBundleData); //$NON-NLS-1$
317 } catch (MissingResourceException ex) { 347 } catch (MissingResourceException ex) {
318 answer = key + " (no resource bundle)"; //$NON-NLS-1$ 348 answer = key ~ " (no resource bundle)"; //$NON-NLS-1$
319 } 349 }
320 } 350 }
321 if (msgs != null) { 351 if (msgs !is null) {
322 try { 352 try {
323 answer = msgs.getString(key); 353 answer = msgs.getString(key);
324 } catch (MissingResourceException ex2) {} 354 } catch (MissingResourceException ex2) {}
325 } 355 }
326 return answer; 356 return answer;
327 } 357 }
328 358
329 public static String getMessage(String key, Object[] args) { 359 public static String getMessage(String key, Object[] args) {
330 String answer = key; 360 String answer = key;
331 361
332 if (key == null || args == null) { 362 if (key is null || args is null) {
333 DWT.error (DWT.ERROR_NULL_ARGUMENT); 363 DWT.error (DWT.ERROR_NULL_ARGUMENT);
334 } 364 }
335 if (msgs == null) { 365 if (msgs is null) {
336 try { 366 try {
337 msgs = ResourceBundle.getBundle("dwt.internal.SWTMessages"); //$NON-NLS-1$ 367 msgs = ResourceBundle.getBundle(SWTMessagesBundleData); //$NON-NLS-1$
338 } catch (MissingResourceException ex) { 368 } catch (MissingResourceException ex) {
339 answer = key + " (no resource bundle)"; //$NON-NLS-1$ 369 answer = key ~ " (no resource bundle)"; //$NON-NLS-1$
340 } 370 }
341 } 371 }
342 if (msgs != null) { 372 if (msgs !is null) {
343 try { 373 try {
344 MessageFormat formatter = new MessageFormat(""); 374 char[] frmt = msgs.getString(key);
345 formatter.applyPattern(msgs.getString(key)); 375 switch( args.length ){
346 answer = formatter.format(args); 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 }
347 } catch (MissingResourceException ex2) {} 385 } catch (MissingResourceException ex2) {}
348 } 386 }
349 return answer; 387 return answer;
350 } 388 }
351 ++/
352 389
353 390
354 /** 391 /**
355 * Interrupt the current thread. 392 * Interrupt the current thread.
356 * <p> 393 * <p>