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

com.github.robtimus.maven.plugins.i18n.templates.I18N.vtl Maven / Gradle / Ivy

#if ($licenseText)
/*
#foreach ($line in $helper.splitLines($licenseText))
#set ($licenseTextLine = $helper.trimRight($line))
#if ($licenseTextLine.isEmpty())
 *
#else
 * $helper.trimRight($line)
#end
#end
 */

#end
##
// This file has been generated by i18n-maven-plugin
// (https://robtimus.github.io/i18n-maven-plugin/)

##
#if ($packageName)
package $packageName;

#end
#if ($useMessageFormat)
import java.text.MessageFormat;
#end
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;

#if ($suppressWarnings.size() == 1)
@SuppressWarnings("$suppressWarnings.iterator().next()")
#elseif (!$suppressWarnings.isEmpty())
@SuppressWarnings({
#foreach ($w in $suppressWarnings)
#if ($velocityCount == $suppressWarnings.size())
    "$w.trim()"
#else
    "$w.trim()",
#end
#end
})
#end
${visibility}final class $simpleClassName {

    private static final Map BUNDLES = new HashMap<>();

    private $simpleClassName() {
        throw new IllegalStateException("cannot create instances of " + getClass().getName());
    }

    private static synchronized ResourceBundle getResourceBundle(Locale locale) {
        Locale l = nonNull(locale);
        ResourceBundle bundle = BUNDLES.get(l);
        if (bundle == null) {
            bundle = ResourceBundle.getBundle("$bundleName", l);
            BUNDLES.put(l, bundle);
        }
        return bundle;
    }

    private static String getString(Locale locale, String key) {
        ResourceBundle bundle = getResourceBundle(locale);
        return bundle.getString(key);
    }

    private static Locale nonNull(Locale locale) {
        return locale != null ? locale : Locale.getDefault(Locale.Category.FORMAT);
    }
##
## Use a stack of nodes to support recursion properly
#set ($nodeStack = $helper.stack())
#set ($indent = "")
#set ($classNameStack = $helper.stack())
##
#macro ( i18nClass )
${indent}${visibility}static final class $classNameStack.peek() {

${indent}    private ${classNameStack.peek()}() {
${indent}        super();
${indent}    }
#if ($nodeStack.peek().isLeaf())
#set ($argumentTypes = $argumentTypesFinder.findArgumentTypes($nodeStack.peek().getValue()))

#if ($argumentTypes.isEmpty())
${indent}    ${visibility}String get() {
${indent}        return get(null);
${indent}    }

${indent}    ${visibility}String get(Locale locale) {
${indent}        Locale l = nonNull(locale);
${indent}        return getString(l, "$nodeStack.peek().path()");
${indent}    }
#elseif ($argumentTypes.size() == 1)
${indent}    ${visibility}String get(Object arg) {
${indent}        return get(null, arg);
${indent}    }

${indent}    ${visibility}String get(Locale locale, Object arg) {
${indent}        Locale l = nonNull(locale);
${indent}        String s = getString(l, "$nodeStack.peek().path()");
#if ($useMessageFormat)
${indent}        Object[] args = {arg};
${indent}        return new MessageFormat(s, l).format(args);
#else
${indent}        return String.format(l, s, arg);
#end
${indent}    }
#else
${indent}    ${visibility}String get(
#foreach ($argTypes in $argumentTypes)
#if ($useMessageFormat)
#set ($argIndex = $velocityCount - 1)
#else
#set ($argIndex = $velocityCount)
#end
#if ($velocityCount == $argumentTypes.size())
${indent}            Object arg${argIndex}) {
#else
${indent}            Object arg${argIndex},
#end
#end

${indent}        return get(null,
#foreach ($argTypes in $argumentTypes)
#if ($useMessageFormat)
#set ($argIndex = $velocityCount - 1)
#else
#set ($argIndex = $velocityCount)
#end
#if ($velocityCount == $argumentTypes.size())
${indent}                arg${argIndex}
#else
${indent}                arg${argIndex},
#end
#end
${indent}        );
${indent}    }

${indent}    ${visibility}String get(Locale locale,
#foreach ($argTypes in $argumentTypes)
#if ($useMessageFormat)
#set ($argIndex = $velocityCount - 1)
#else
#set ($argIndex = $velocityCount)
#end
#if ($velocityCount == $argumentTypes.size())
${indent}            Object arg${argIndex}) {
#else
${indent}            Object arg${argIndex},
#end
#end

${indent}        Locale l = nonNull(locale);
${indent}        String s = getString(l, "$nodeStack.peek().path()");
#if ($useMessageFormat)
${indent}        Object[] args = {
#foreach ($argTypes in $argumentTypes)
#set ($argIndex = $velocityCount - 1)
${indent}                arg${argIndex},
#end
${indent}        };
${indent}        return new MessageFormat(s, l).format(args);
#else
${indent}        return String.format(l, s,
#foreach ($argTypes in $argumentTypes)
#set ($argIndex = $velocityCount)
#if ($velocityCount == $argumentTypes.size())
${indent}                arg${argIndex}
#else
${indent}                arg${argIndex},
#end
#end
${indent}        );
#end
${indent}    }
#end
#end
#foreach ($n in $nodeStack.peek().children())
#set ($tmp = $nodeStack.push($n))
#set ($tmp = $classNameStack.push($helper.className($n, $classNameStack)))
#set ($indent = "$indent    ")

${indent}${visibility}final $classNameStack.peek() $helper.varName($nodeStack.peek()) = new ${classNameStack.peek()}();

#i18nClass
#set ($tmp = $nodeStack.pop())
#set ($tmp = $classNameStack.pop())
#set ($indent = $helper.stripLast($indent, 4))
#end
${indent}}#end
##
#foreach ($n in $i18n.children())
#set ($tmp = $nodeStack.push($n))
#set ($tmp = $classNameStack.push($helper.className($n, $classNameStack)))
#set ($indent = "$indent    ")

    ${visibility}static final $classNameStack.peek() $helper.varName($nodeStack.peek()) = new ${classNameStack.peek()}();

#i18nClass
#set ($tmp = $nodeStack.pop())
#set ($tmp = $classNameStack.pop())
#set ($indent = $helper.stripLast($indent, 4))
#end
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy