package org.javarosa.core.services.locale;

import java.util.Hashtable;

import org.javarosa.core.reference.ReferenceDataSource;

public class Localization {
    private static Localizer globalLocalizer;
    
    public static String get(String key){
        return get(key, new String[]{});
    }
    
    public static String get(String key, String[] args) {
        checkRep();
        return globalLocalizer.getText(key, args);
    }
    
    public static String get(String key, Hashtable args) {
        checkRep();
        return globalLocalizer.getText(key, args);
    }
    
    public static void registerLanguageFile(String localeName, String resourceFileURI) {
        init(false);
        if(!globalLocalizer.hasLocale(localeName)){ 
            globalLocalizer.addAvailableLocale(localeName);
        }
        globalLocalizer.registerLocaleResource(localeName, new ResourceFileDataSource(resourceFileURI));
        if(globalLocalizer.getDefaultLocale() == null) {
            globalLocalizer.setDefaultLocale(localeName);
        }
    }
    
    public static void registerLanguageReference(String localeName, String referenceUri) {
        init(false);
        if(!globalLocalizer.hasLocale(localeName)){ 
            globalLocalizer.addAvailableLocale(localeName);
        }
        globalLocalizer.registerLocaleResource(localeName, new ReferenceDataSource(referenceUri));
        if(globalLocalizer.getDefaultLocale() == null) {
            globalLocalizer.setDefaultLocale(localeName);
        }
    }
    
    public static Localizer getGlobalLocalizerAdvanced() {
        init(false);
        return globalLocalizer;
    }
    
    public static void setLocale(String locale) {
        checkRep();
        globalLocalizer.setLocale(locale);
    }
    
    public static void setDefaultLocale(String defaultLocale) {
        checkRep();
        globalLocalizer.setDefaultLocale(defaultLocale);
    }
    
    /**
     * 
     */
    public static void init(boolean force) {
        if(globalLocalizer == null || force) {
            globalLocalizer = new Localizer(true,false);
        }
    }
    
    public static void setLocalizationData(Localizer localizer) {
        globalLocalizer = localizer;

    }
    
    /**
     *  
     */
    private static void checkRep() {
        init(false);
        if(globalLocalizer.getAvailableLocales().length == 0) {
            throw new LocaleTextException("There are no locales defined for the application. Please make sure to register locale text using the Locale.register() method");
        }
    }
}

@@ -288,32 +288,183 @@
 %7B%7D);%0A    %7D%0A    %0A
+    public static String get(String key, String arg) %7B%0A        checkRep();%0A        return globalLocalizer.getText(key, new String%5B%5D %7Barg%7D);%0A    %7D%0A    %0A
     public stati

add localization helper method