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

org.wicketstuff.select2.Select2LanguageResourceReference Maven / Gradle / Ivy

There is a newer version: 10.2.0
Show newest version
package org.wicketstuff.select2;

import org.apache.wicket.request.resource.JavaScriptResourceReference;

/**
 * {@link JavaScriptResourceReference} for a select2 i18n file,
 * please see i18n resources folder for supported languages.
 *
 * @author Tom Götz ([email protected])
 */
class Select2LanguageResourceReference extends JavaScriptResourceReference {
	private static final long serialVersionUID = 1L;
	private static final String resourceName = "res/js/i18n/%s.js";
    private static final String defaultLanguage = "en";

    /**
     * @param language i18n file to load (e.g. "en", "de", "fr" ...)
     */
    Select2LanguageResourceReference(String language) {
        super(Select2LanguageResourceReference.class, getResourceName(language));
    }

    /**
     * Returns the resource name of the i18n file, uses a fallback to defaultLanguage
     * if requested resource file does not exist
     *
     * @param language i18n file to load
     * @return resource name
     */
    private static String getResourceName(String language) {
        try {
            String name = String.format(resourceName, language);
            if (Select2LanguageResourceReference.class.getResource(name) != null) {
                return name;
            }
        } catch (Exception ignore) {
            // noop
        }
        return String.format(resourceName, defaultLanguage);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy