Example usage for java.util Locale getVariant

List of usage examples for java.util Locale getVariant

Introduction

In this page you can find the example usage for java.util Locale getVariant.

Prototype

public String getVariant() 

Source Link

Document

Returns the variant code for this locale.

Usage

From source file:org.apache.beehive.netui.compiler.model.validation.ValidationModel.java

private void writeLocaleSets(XmlModelWriter xw, Element element) {
    ////  ww w  . j  a v  a 2  s .  co m
    // Commons Validator behavior is to build a key from the locale of a FormSet
    // or uses the default Locale (Locale.getDefault() - the system locale) to
    // track different  elements. This implies that the 
    // without language or country attributes could be mapped to "en_US"
    // if that's the default locale.
    // See org.apache.commons.validator.ValidatorResources.buildKey()
    //
    // Therefor, to ensure the validator uses  rules for of a specific
    // locale before the FormSet with no language or country attributes (even
    // if it is the locale of the system), write the most specific locales first.
    //
    List allLocales = new ArrayList(_localeSets.keySet());
    List langCountryVariant = new ArrayList();
    List langCountry = new ArrayList();
    List lang = new ArrayList();

    for (java.util.Iterator ii = allLocales.iterator(); ii.hasNext();) {
        Locale locale = (Locale) ii.next();
        if (locale.getCountry().length() > 0) {
            if (locale.getVariant().length() > 0) {
                langCountryVariant.add(locale);
            } else {
                langCountry.add(locale);
            }
        } else {
            lang.add(locale);
        }
    }

    writeLocaleSets(xw, element, langCountryVariant);
    writeLocaleSets(xw, element, langCountry);
    writeLocaleSets(xw, element, lang);
}

From source file:org.apache.cocoon.matching.LocaleMatcher.java

private boolean isValidResource(String pattern, Locale locale, Map map) {
    Locale testLocale;//from  ww w.  j a  v a2s. c  o  m

    // Test "language, country, variant" locale
    if (locale.getVariant().length() > 0) {
        if (isValidResource(pattern, locale, locale, map)) {
            return true;
        }
    }

    // Test "language, country" locale
    if (locale.getCountry().length() > 0) {
        testLocale = new Locale(locale.getLanguage(), locale.getCountry());
        if (isValidResource(pattern, locale, testLocale, map)) {
            return true;
        }
    }

    // Test "language" locale (or empty - if language is "")
    testLocale = new Locale(locale.getLanguage(), ""); // Use JDK1.3 constructor
    if (isValidResource(pattern, locale, testLocale, map)) {
        return true;
    }

    return false;
}

From source file:com.limegroup.gnutella.gui.init.LanguagePanel.java

private Locale guessLocale(Locale[] locales) {
    String[] language = guessLanguage();

    Locale result = null;/*from  w  w  w . j  av  a 2  s.com*/
    try {
        for (Locale l : locales) {
            if (l.getLanguage().equalsIgnoreCase(language[0]) && l.getCountry().equalsIgnoreCase(language[1])
                    && l.getVariant().equalsIgnoreCase(language[2])) {
                result = l;
            }

            if (l.getLanguage().equalsIgnoreCase(language[0]) && l.getCountry().equalsIgnoreCase(language[1])
                    && result == null) {
                result = l;
            }

            if (l.getLanguage().equalsIgnoreCase(language[0]) && result == null) {
                result = l;
            }
        }
    } catch (Throwable e) {
        //shhh!
    }

    return (result == null) ? new Locale(language[0], language[1], language[2]) : result;
}

From source file:com.openbravo.pos.forms.AppConfig.java

private void loadDefault() {

    m_propsconfig = new Properties();

    String dirname = System.getProperty("dirname.path");
    dirname = dirname == null ? "./" : dirname;

    m_propsconfig.setProperty("db.driverlib", new File(new File(dirname), "lib/derby.jar").getAbsolutePath());
    m_propsconfig.setProperty("db.driver", "org.apache.derby.jdbc.EmbeddedDriver");
    m_propsconfig.setProperty("db.URL",
            "jdbc:derby:" + new File(new File(System.getProperty("user.home")), AppLocal.APP_ID + "-database")
                    .getAbsolutePath() + ";create=true");
    m_propsconfig.setProperty("db.user", "");
    m_propsconfig.setProperty("db.password", "");

    //        m_propsconfig.setProperty("db.driverlib", new File(new File(dirname), "lib/hsqldb.jar").getAbsolutePath());
    //        m_propsconfig.setProperty("db.driver", "org.hsqldb.jdbcDriver");
    //        m_propsconfig.setProperty("db.URL", "jdbc:hsqldb:file:" + new File(new File(System.getProperty("user.home")), AppLocal.APP_ID + "-db").getAbsolutePath() + ";shutdown=true");
    //        m_propsconfig.setProperty("db.user", "sa");
    //        m_propsconfig.setProperty("db.password", "");

    //        m_propsconfig.setProperty("db.driver", "com.mysql.jdbc.Driver");
    //        m_propsconfig.setProperty("db.URL", "jdbc:mysql://localhost:3306/database");
    //        m_propsconfig.setProperty("db.user", "user");         
    //        m_propsconfig.setProperty("db.password", "password");

    //        m_propsconfig.setProperty("db.driver", "org.postgresql.Driver");
    //        m_propsconfig.setProperty("db.URL", "jdbc:postgresql://localhost:5432/database");
    //        m_propsconfig.setProperty("db.user", "user");         
    //        m_propsconfig.setProperty("db.password", "password");        

    m_propsconfig.setProperty("machine.hostname", getLocalHostName());

    Locale l = Locale.getDefault();
    m_propsconfig.setProperty("user.language", l.getLanguage());
    m_propsconfig.setProperty("user.country", l.getCountry());
    m_propsconfig.setProperty("user.variant", l.getVariant());

    m_propsconfig.setProperty("swing.defaultlaf",
            System.getProperty("swing.defaultlaf", "javax.swing.plaf.metal.MetalLookAndFeel"));

    m_propsconfig.setProperty("machine.printer", "screen");
    m_propsconfig.setProperty("machine.printer.2", "Not defined");
    m_propsconfig.setProperty("machine.printer.3", "Not defined");
    m_propsconfig.setProperty("machine.display", "screen");
    m_propsconfig.setProperty("machine.scale", "Not defined");
    m_propsconfig.setProperty("machine.screenmode", "window"); // fullscreen / window
    m_propsconfig.setProperty("machine.ticketsbag", "standard");
    m_propsconfig.setProperty("machine.scanner", "Not defined");

    m_propsconfig.setProperty("payment.gateway", "external");
    m_propsconfig.setProperty("payment.magcardreader", "Not defined");
    m_propsconfig.setProperty("payment.testmode", "false");
    m_propsconfig.setProperty("payment.commerceid", "");
    m_propsconfig.setProperty("payment.commercepassword", "password");

    m_propsconfig.setProperty("machine.printername", "(Default)");

    // Receipt printer paper set to 72mmx200mm
    m_propsconfig.setProperty("paper.receipt.x", "10");
    m_propsconfig.setProperty("paper.receipt.y", "287");
    m_propsconfig.setProperty("paper.receipt.width", "190");
    m_propsconfig.setProperty("paper.receipt.height", "546");
    m_propsconfig.setProperty("paper.receipt.mediasizename", "A4");

    // Normal printer paper for A4
    m_propsconfig.setProperty("paper.standard.x", "72");
    m_propsconfig.setProperty("paper.standard.y", "72");
    m_propsconfig.setProperty("paper.standard.width", "451");
    m_propsconfig.setProperty("paper.standard.height", "698");
    m_propsconfig.setProperty("paper.standard.mediasizename", "A4");

    m_propsconfig.setProperty("machine.uniqueinstance", "false");
}

From source file:org.echocat.jomon.runtime.i18n.ResourceBundles.java

@Nonnull
public ResourceBundle getBundle(@Nullable Locale locale) throws NoSuchElementException {
    ResourceBundle resourceBundle = _localeToBundleCache.get(locale);
    if (resourceBundle == null) {
        final List<ResourceBundle> candidates = new ArrayList<>(10);
        if (locale != null && !isEmpty(locale.getLanguage()) && !isEmpty(locale.getCountry())
                && !isEmpty(locale.getVariant())) {
            final ResourceBundle bundle = _localeToBundle
                    .get(new Locale(locale.getLanguage(), locale.getCountry(), locale.getVariant()));
            if (bundle != null) {
                candidates.add(bundle);/*www  .j av  a2 s . c  om*/
            }
        }
        if (locale != null && !isEmpty(locale.getLanguage()) && !isEmpty(locale.getCountry())) {
            final ResourceBundle bundle = _localeToBundle
                    .get(new Locale(locale.getLanguage(), locale.getCountry()));
            if (bundle != null) {
                candidates.add(bundle);
            }
        }
        if (locale != null && !isEmpty(locale.getLanguage())) {
            final ResourceBundle bundle = _localeToBundle.get(new Locale(locale.getLanguage()));
            if (bundle != null) {
                candidates.add(bundle);
            }
        }
        final ResourceBundle bundle = _localeToBundle.get(new Locale(""));
        if (bundle != null) {
            candidates.add(bundle);
        }
        if (candidates.isEmpty()) {
            throw new NoSuchElementException("There is no bundle for locale " + locale + ".");
        }
        resourceBundle = new CombinedResourceBundle(candidates);
        _localeToBundleCache.put(locale, resourceBundle);
    }
    return resourceBundle;
}

From source file:org.openmrs.module.custommessage.CustomMessageSource.java

/**
 * @see AbstractMessageSource#resolveCode(String, Locale)
 *//* w  w  w  .j  av  a  2  s . co  m*/
@Override
protected MessageFormat resolveCode(String code, Locale locale) {
    if (showMessageCode) {
        return new MessageFormat(code);
    }
    PresentationMessage pm = getPresentation(code, locale); // Check exact match
    if (pm == null) {
        if (locale.getVariant() != null) {
            pm = getPresentation(code, new Locale(locale.getLanguage(), locale.getCountry())); // Try to match language and country
            if (pm == null) {
                pm = getPresentation(code, new Locale(locale.getLanguage())); // Try to match language only
            }
        }
    }
    if (pm != null) {
        return new MessageFormat(pm.getMessage());
    }
    return null;
}

From source file:net.technicpack.ui.lang.ResourceLoader.java

public String getCodeFromLocale(Locale locale) {
    if (locale.getLanguage().isEmpty()) {
        return "default";
    } else if (locale.getCountry().isEmpty()) {
        return locale.getLanguage();
    } else if (locale.getVariant().isEmpty()) {
        return String.format("%s,%s", locale.getLanguage(), locale.getCountry());
    } else {//from   ww  w.  ja  va2  s.c om
        return String.format("%s,%s,%s", locale.getLanguage(), locale.getCountry(), locale.getVariant());
    }
}

From source file:net.technicpack.launcher.lang.ResourceLoader.java

private Locale matchClosestSupportedLocale(Locale definiteLocale) {
    Locale bestSupportedLocale = null;
    int bestLocaleScore = 0;
    for (int i = 0; i < SUPPORTED_LOCALES.length; i++) {
        Locale testLocale = SUPPORTED_LOCALES[i];
        int testScore = 0;

        if (testLocale.getLanguage().equals(definiteLocale.getLanguage())) {
            testScore++;//from  w w w.  ja va2s .  c  om

            if (testLocale.getCountry().equals(definiteLocale.getCountry())) {
                testScore++;

                if (testLocale.getVariant().equals(definiteLocale.getVariant())) {
                    testScore++;
                }
            }
        }

        if (testScore != 0 && testScore > bestLocaleScore) {
            bestLocaleScore = testScore;
            bestSupportedLocale = testLocale;
        }
    }

    if (bestSupportedLocale != null) {
        return bestSupportedLocale;
    } else {
        return Locale.getDefault();
    }
}

From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerXMLHelper.java

/**
 * @param locale/*from w w  w . j  a va  2  s  .com*/
 * @return
 */
protected static String makeLocaleKey(final Locale locale) {
    return makeLocaleKey(locale.getLanguage(), locale.getCountry(), locale.getVariant());
}

From source file:org.openmrs.module.initializer.InitializerMessageSource.java

/**
 * @see AbstractMessageSource#resolveCode(String, Locale)
 *//*from  w  w w.  j  ava  2s. co m*/
@Override
protected MessageFormat resolveCode(String code, Locale locale) {
    if (showMessageCode) {
        return new MessageFormat(code);
    }
    PresentationMessage pm = getPresentation(code, locale); // Check exact match
    if (pm == null) {
        if (locale.getVariant() != null) {
            pm = getPresentation(code, new Locale(locale.getLanguage(), locale.getCountry())); // Try to match
                                                                                               // language and
                                                                                               // country
            if (pm == null) {
                pm = getPresentation(code, new Locale(locale.getLanguage())); // Try to match language only
            }
        }
    }
    if (pm != null) {
        return new MessageFormat(pm.getMessage());
    }
    return null;
}