All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sofia.maven.0.1.source-code.sofia.fm Maven / Gradle / Ivy

package ${packageName};

import java.text.*;
import java.util.*;

public class Localizer {
    private static Map messages = new HashMap();

    private static ResourceBundle getBundle(Locale... localeList) {
        Locale locale = localeList.length == 0 ? Locale.getDefault() : localeList[0];
        ResourceBundle labels = loadBundle(locale);
        if(labels == null) {
            labels = loadBundle(Locale.ROOT);
        }
        return labels;
    }

    private static ResourceBundle loadBundle(Locale locale) {
        ResourceBundle bundle = messages.get(locale);
        if(bundle == null) {
            bundle = ResourceBundle.getBundle("${bundleName}", locale);
            messages.put(locale, bundle);
        }
        return bundle;
    }

    private static String getMessageValue(String key, Locale... locale) {
        return (String) getBundle(locale).getObject(key);
    }

    <#list methods as method>
    public static String ${method.name}(<#list method.parameters as argument>${argument}<#if argument_has_next>, <#if method.parameters?size != 0>, Locale... locale) {
    <#if method.arguments?size != 0>
        return MessageFormat.format(getMessageValue("${method.key}", locale), <#list method.arguments as argument>${argument}<#if argument_has_next>, );
    <#else>
        return getMessageValue("${method.key}", locale);
    
    }

    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy