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

org.bidib.wizard.api.utils.XmlLocaleUtils Maven / Gradle / Ivy

There is a newer version: 2.0.25
Show newest version
package org.bidib.wizard.api.utils;

import java.util.Locale;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class XmlLocaleUtils {
    private static final Logger LOGGER = LoggerFactory.getLogger(XmlLocaleUtils.class);

    public static final String DEFAULT_LOCALE = "en-US";

    public static final String DEFAULT_LOCALE_VENDOR_CV = "en-EN";

    public static final String DEFAULT_FALLBACK_LOCALE = "en";

    public static String getXmlLocale() {
        Locale locale = Locale.getDefault();
        LOGGER.trace("Current locale: {}", locale);

        String xmlLocale = null;
        xmlLocale = locale.getLanguage();
        // if (xmlLocale.equals("de")) {
        // xmlLocale = "de-DE";
        // }
        // else {
        // xmlLocale = DEFAULT_LOCALE;
        // }
        if (StringUtils.isBlank(xmlLocale)) {
            xmlLocale = DEFAULT_LOCALE;
        }
        return xmlLocale;
    }

    public static String getXmlLocaleVendorCV() {
        Locale locale = Locale.getDefault();
        LOGGER.trace("Current locale: {}", locale);

        String xmlLocale = null;
        xmlLocale = locale.getLanguage();
        // if (xmlLocale.equals("de")) {
        // xmlLocale = "de-DE";
        // }
        // else {
        // xmlLocale = DEFAULT_LOCALE_VENDOR_CV;
        // }
        if (StringUtils.isBlank(xmlLocale)) {
            xmlLocale = DEFAULT_LOCALE_VENDOR_CV;
        }
        return xmlLocale;
    }

    public static String stripMainLanguage(String language) {
        int idx = language.indexOf('-');
        if (idx > -1) {
            return language.substring(0, idx);
        }
        return language;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy