/*
 * Loc.java
 *
 * Created on 7. duben 2001, 11:20
 */

package timetable.util;

import java.util.*;
import java.io.*;
/**
 *
 * @author  administrator
 * @version 
 */
public class Loc extends Object {

    /** Creates new Loc */
    public Loc() {

    }
    
    public static void addLocalization(String fileName) {
        try {
        Properties p = new Properties();
        p.load(new java.io.FileInputStream(fileName));
        for (java.util.Enumeration e=p.keys();e.hasMoreElements();) {
            Object key = e.nextElement();
            loc.put(key,p.getProperty((String)key));
        }
        } catch (Exception e) {
            System.err.println("Error: "+e);
        }
    }
    
    public static String get(String key) {
        String ret = (String)loc.get(key);
        return (ret==null?key:(String)loc.get(key));
    }
    
    public static String get(String key, String [] params) {
        StringBuffer ret = new StringBuffer(get(key));
        for (int i=0;i<params.length;i++) {
            String prm = "%"+(i+1)+"%";
            while (ret.toString().indexOf(prm)>0)
                ret.replace(ret.toString().indexOf(prm),ret.toString().indexOf(prm)+prm.length(),params[i]);
        }
        return ret.toString();
    }
        
    public static String get(String key, String param) {
        return get(key,new String[] {param});
    }
           
    
    private static Hashtable loc = new Hashtable();

}
