Changeset 317:8c656d6b7300

Show
Ignore:
Timestamp:
10/18/08 19:26:56 (3 months ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

Add support for SWT language files

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwt/dwthelper/ResourceBundle.d

    r212 r317  
    1010import dwt.dwthelper.utils; 
    1111import tango.io.File; 
     12import tango.text.locale.Core; 
     13 
     14import tango.util.log.Trace; 
    1215 
    1316class ResourceBundle { 
     
    1518    String[ String ] map; 
    1619 
     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    } 
    1750    public this( String data ){ 
     51        initialize( data ); 
     52    } 
     53    private void initialize( String data ){ 
    1854        String line; 
    1955        int dataIndex; 
     
    123159    } 
    124160 
     161    public static ResourceBundle getBundle( ImportData[] data ){ 
     162        return new ResourceBundle( data ); 
     163    } 
    125164    public static ResourceBundle getBundle( ImportData data ){ 
    126         return new ResourceBundle( cast(String) data.data ); 
     165        return new ResourceBundle( data ); 
    127166    } 
    128167    public static ResourceBundle getBundle( String name ){ 
  • dwt/internal/Compatibility.d

    r246 r317  
    296296    proc.execute; 
    297297} 
    298 /++ PORTING_LEFT 
     298 
     299const 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 
    299327private static ResourceBundle msgs = null; 
    300328 
     
    311339    String answer = key; 
    312340 
    313     if (key == null) { 
     341    if (key is null) { 
    314342        DWT.error (DWT.ERROR_NULL_ARGUMENT); 
    315343    } 
    316     if (msgs == null) { 
     344    if (msgs is null) { 
    317345        try { 
    318             msgs = ResourceBundle.getBundle("dwt.internal.SWTMessages"); //$NON-NLS-1$ 
     346            msgs = ResourceBundle.getBundle(SWTMessagesBundleData); //$NON-NLS-1$ 
    319347        } catch (MissingResourceException ex) { 
    320             answer = key + " (no resource bundle)"; //$NON-NLS-1$ 
     348            answer = key ~ " (no resource bundle)"; //$NON-NLS-1$ 
    321349        } 
    322350    } 
    323     if (msgs != null) { 
     351    if (msgs !is null) { 
    324352        try { 
    325353            answer = msgs.getString(key); 
     
    332360    String answer = key; 
    333361 
    334     if (key == null || args == null) { 
     362    if (key is null || args is null) { 
    335363        DWT.error (DWT.ERROR_NULL_ARGUMENT); 
    336364    } 
    337     if (msgs == null) { 
     365    if (msgs is null) { 
    338366        try { 
    339             msgs = ResourceBundle.getBundle("dwt.internal.SWTMessages"); //$NON-NLS-1$ 
     367            msgs = ResourceBundle.getBundle(SWTMessagesBundleData); //$NON-NLS-1$ 
    340368        } catch (MissingResourceException ex) { 
    341             answer = key + " (no resource bundle)"; //$NON-NLS-1$ 
     369            answer = key ~ " (no resource bundle)"; //$NON-NLS-1$ 
    342370        } 
    343371    } 
    344     if (msgs != null) { 
     372    if (msgs !is null) { 
    345373        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            } 
    349385        } catch (MissingResourceException ex2) {} 
    350386    } 
    351387    return answer; 
    352388} 
    353 ++/ 
    354389 
    355390