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.cocoon.forms.datatype.convertor.LocaleMap.java

private final String getKey(Locale locale) {
    boolean hasLanguage = !locale.getLanguage().equals("");
    boolean hasCountry = !locale.getCountry().equals("");
    boolean hasVariant = !locale.getVariant().equals("");

    if (hasLanguage && hasCountry && hasVariant)
        return locale.getLanguage() + '-' + locale.getCountry() + '-' + locale.getVariant();
    else if (hasLanguage && hasCountry)
        return locale.getLanguage() + '-' + locale.getCountry();
    else if (hasLanguage)
        return locale.getLanguage();
    else/*from  www .ja  va 2s  .  co  m*/
        return "";
}

From source file:com.manydesigns.portofino.i18n.ResourceBundleManager.java

protected String getBundleName(String baseName, Locale locale) {
    String language = locale.getLanguage();
    String country = locale.getCountry();
    String variant = locale.getVariant();

    if (StringUtils.isBlank(language) && StringUtils.isBlank(country) && StringUtils.isBlank(variant)) {
        return baseName;
    }//w w w .  java 2 s .com

    String name = baseName + "_";
    if (!StringUtils.isBlank(variant)) {
        name += language + "_" + country + "_" + variant;
    } else if (!StringUtils.isBlank(country)) {
        name += language + "_" + country;
    } else {
        name += language;
    }
    return name;
}

From source file:org.pentaho.platform.engine.services.actionsequence.ActionSequenceResource.java

@SuppressWarnings({ "resource", "deprecation" })
public static InputStream getInputStream(String filePath, Locale locale) {
    InputStream inputStream = null;

    if (filePath.startsWith("system")) {
        File file = null;/* w  w w  .j  av a2s .c o m*/
        filePath = PentahoSystem.getApplicationContext().getSolutionPath(filePath);
        if (locale == null) {
            file = new File(filePath);
        } else {
            String extension = FilenameUtils.getExtension(filePath);
            String baseName = FilenameUtils.removeExtension(filePath);
            if (extension.length() > 0) {
                extension = "." + extension; //$NON-NLS-1$
            }
            String language = locale.getLanguage();
            String country = locale.getCountry();
            String variant = locale.getVariant();
            if (!variant.equals("")) { //$NON-NLS-1$
                file = new File(baseName + "_" + language + "_" + country + "_" + variant + extension); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            }
            if ((file == null) || !file.exists()) {
                file = new File(baseName + "_" + language + "_" + country + extension); //$NON-NLS-1$//$NON-NLS-2$
            }
            if ((file == null) || !file.exists()) {
                file = new File(baseName + "_" + language + extension); //$NON-NLS-1$
            }
            if ((file == null) || !file.exists()) {
                file = new File(filePath);
            }
        }
        if (file != null) {
            try {
                inputStream = new FileInputStream(file);
            } catch (FileNotFoundException ex) {
                // Do nothing we'll just return a null input stream;
            }
        }
    } else {
        // This is not a file from the system folder. User is trying to access a resource in the repository.
        // Get the RepositoryContentConverterHandler
        IRepositoryContentConverterHandler converterHandler = PentahoSystem
                .get(IRepositoryContentConverterHandler.class);
        RepositoryFile repositoryFile = null;
        if (locale == null) {
            repositoryFile = getRepository().getFile(filePath);
            String extension = FilenameUtils.getExtension(filePath);
            try {
                // Try to get the converter for the extension. If there is not converter available then we will
                //assume simple type and will get the data that way
                if (converterHandler != null) {
                    Converter converter = converterHandler.getConverter(extension);
                    if (converter != null) {
                        inputStream = converter.convert(repositoryFile.getId());
                    }
                }
                if (inputStream == null) {
                    inputStream = getRepository()
                            .getDataForRead(repositoryFile.getId(), SimpleRepositoryFileData.class).getStream();
                }
            } catch (UnifiedRepositoryException ure) {
                //ignored
            }
        } else {
            String extension = FilenameUtils.getExtension(filePath);
            String baseName = FilenameUtils.removeExtension(filePath);
            if (extension.length() > 0) {
                extension = "." + extension; //$NON-NLS-1$
            }
            String language = locale.getLanguage();
            String country = locale.getCountry();
            String variant = locale.getVariant();
            if (!variant.equals("")) { //$NON-NLS-1$
                repositoryFile = getRepository()
                        .getFile(baseName + "_" + language + "_" + country + "_" + variant + extension); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                try {
                    if (repositoryFile != null) {
                        // Try to get the converter for the extension. If there is not converter available then we will
                        //assume simple type and will get the data that way
                        if (converterHandler != null) {
                            Converter converter = converterHandler
                                    .getConverter(FilenameUtils.getExtension(filePath));
                            if (converter != null) {
                                inputStream = converter.convert(repositoryFile.getId());
                            }
                        }
                        if (inputStream == null) {
                            inputStream = getRepository()
                                    .getDataForRead(repositoryFile.getId(), SimpleRepositoryFileData.class)
                                    .getStream();
                        }
                    }
                } catch (UnifiedRepositoryException ure) {
                    //ignored
                }
            }
            if (inputStream == null) {
                repositoryFile = getRepository().getFile(baseName + "_" + language + "_" + country + extension); //$NON-NLS-1$//$NON-NLS-2$
                try {
                    if (repositoryFile != null) {
                        // Try to get the converter for the extension. If there is not converter available then we will
                        //assume simple type and will get the data that way
                        if (converterHandler != null) {
                            Converter converter = converterHandler
                                    .getConverter(FilenameUtils.getExtension(filePath));
                            if (converter != null) {
                                inputStream = converter.convert(repositoryFile.getId());
                            }
                        }
                        if (inputStream == null) {
                            inputStream = getRepository()
                                    .getDataForRead(repositoryFile.getId(), SimpleRepositoryFileData.class)
                                    .getStream();
                        }
                    }
                } catch (UnifiedRepositoryException ure) {
                    //ignored
                }
            }
            if (inputStream == null) {
                repositoryFile = getRepository().getFile(baseName + "_" + language + extension); //$NON-NLS-1$
                try {
                    if (repositoryFile != null) {
                        // Try to get the converter for the extension. If there is not converter available then we will
                        //assume simple type and will get the data that way
                        if (converterHandler != null) {
                            Converter converter = converterHandler
                                    .getConverter(FilenameUtils.getExtension(filePath));
                            if (converter != null) {
                                inputStream = converter.convert(repositoryFile.getId());
                            }
                        }
                        if (inputStream == null) {
                            inputStream = getRepository()
                                    .getDataForRead(repositoryFile.getId(), SimpleRepositoryFileData.class)
                                    .getStream();
                        }
                    }
                } catch (UnifiedRepositoryException ure) {
                    //ignored
                }
            }
            if (inputStream == null) {
                repositoryFile = getRepository().getFile(filePath);
                try {
                    if (repositoryFile != null) {
                        // Try to get the converter for the extension. If there is not converter available then we will
                        //assume simple type and will get the data that way
                        if (converterHandler != null) {
                            Converter converter = converterHandler
                                    .getConverter(FilenameUtils.getExtension(filePath));
                            if (converter != null) {
                                inputStream = converter.convert(repositoryFile.getId());
                            }
                        }
                        if (inputStream == null) {
                            inputStream = getRepository()
                                    .getDataForRead(repositoryFile.getId(), SimpleRepositoryFileData.class)
                                    .getStream();
                        }
                    }
                } catch (UnifiedRepositoryException ure) {
                    //ignored
                }
            }
        }
    }
    return inputStream;
}

From source file:org.xwiki.localization.internal.AbstractCachedTranslationBundle.java

/**
 * @param locale the locale//from  www .j ava  2 s.  co  m
 * @return the parent locale
 */
private Locale getParentLocale(Locale locale) {
    String language = locale.getLanguage();
    String country = locale.getCountry();
    String variant = locale.getVariant();

    if (StringUtils.isEmpty(language)) {
        return null;
    }

    if (StringUtils.isEmpty(country)) {
        return Locale.ROOT;
    }

    if (StringUtils.isEmpty(variant)) {
        return new Locale(language);
    }

    return new Locale(language, country);
}

From source file:LocaleMap.java

private String getFullKey(Locale locale) {
    return locale.getLanguage() + '-' + locale.getCountry() + '-' + locale.getVariant();
}

From source file:com.salesmanager.central.shipping.ShippingfedexgroundAction.java

@Override
public void prepareModule() throws Exception {
    Context ctx = (Context) super.getServletRequest().getSession().getAttribute(ProfileConstants.context);
    Integer merchantid = ctx.getMerchantid();

    ReferenceService rservice = (ReferenceService) ServiceFactory.getService(ServiceFactory.ReferenceService);

    Locale locale = getLocale();

    String country = locale.getCountry();
    if (locale.getVariant().equals("EUR")) {
        country = "X1";
    }//from   w w w  .j ava 2s  . c  o m

    Map packages = ShippingUtil.buildPackageMap(moduleid, locale);
    if (packages != null) {
        setPackageMap(packages);
    }

    // get merchant configs
    MerchantService mservice = (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);

    ConfigurationResponse config = mservice.getConfigurationByModule(moduleid, merchantid);
    this.setConfigurations(config);

}

From source file:org.orcid.frontend.web.util.LanguagesMap.java

/**
 * Returns the language translated in the given user locale
 * //from   w  w w.j  a  v  a 2s .c o  m
 * @param locale
 * @param userLocal
 * 
 * @return The language translated to the given locale.
 * */
@Cacheable(value = "languages-map", key = "#locale.toString() + '-' + #userLocale.toString()")
public String buildLanguageValue(Locale locale, Locale userLocale) {
    if (userLocale != null && userLocale.getLanguage().equals("xx")) {
        return X;
    }
    String variant = locale.getVariant();
    String displayVariant = locale.getDisplayVariant(userLocale);
    String language = WordUtils.capitalize(locale.getDisplayLanguage(userLocale));

    if (StringUtils.isEmpty(variant))
        if (StringUtils.isEmpty(locale.getDisplayCountry(userLocale)))
            return language;
        else
            return language + " (" + locale.getDisplayCountry(userLocale) + ')';
    else if (StringUtils.isEmpty(locale.getDisplayCountry(userLocale)))
        return language + ' ' + displayVariant;
    else
        return language + ' ' + displayVariant + " (" + locale.getDisplayCountry(userLocale) + ')';
}

From source file:org.marketcetera.util.ws.wrappers.MarshalledLocale.java

/**
 * Creates a new marshalled form for the locale given in its raw
 * form.//  w  w  w  . j a  v a2 s  .  c  om
 *
 * @param locale The locale, which may be null.
 */

public MarshalledLocale(Locale locale) {
    if (locale == null) {
        return;
    }
    setLanguage(locale.getLanguage());
    setCountry(locale.getCountry());
    setVariant(locale.getVariant());
}

From source file:nz.co.senanque.localemanagement.XMLMessageSource.java

@Override
protected MessageFormat resolveCode(String code, Locale locale) {
    String ret = null;/*from   w  w  w .j  a  v  a  2 s. com*/
    String country = locale.getCountry();
    String language = locale.getLanguage();
    String variant = locale.getVariant();
    logger.debug("Code {} Initial locale {}", code, locale.toString());
    Locale thisLocale = null;
    if (!StringUtils.isEmpty(variant)) {
        thisLocale = new Locale(language, country, variant);
        Map<String, String> m = m_map.get(thisLocale);
        if (m != null) {
            ret = m.get(code);
        }
        logger.debug("tried locale {} result: {}", thisLocale.toString(), ret);

    }
    if (ret == null) {
        if (!StringUtils.isEmpty(country)) {
            thisLocale = new Locale(language, country);
            Map<String, String> m = m_map.get(thisLocale);
            if (m != null) {
                ret = m.get(code);
            }
            logger.debug("tried locale {} result: {}", thisLocale.toString(), ret);
        }
    }
    if (ret == null) {
        if (!StringUtils.isEmpty(language)) {
            thisLocale = new Locale(language);
            Map<String, String> m = m_map.get(thisLocale);
            if (m != null) {
                ret = m.get(code);
            }
            logger.debug("tried locale {} result: {}", thisLocale.toString(), ret);
        }
    }
    if (ret == null) {
        thisLocale = Locale.getDefault();
        Map<String, String> m = m_map.get(thisLocale);
        if (m != null) {
            ret = m.get(code);
        }
        logger.debug("tried locale {} result: {}", thisLocale.toString(), ret);
    }
    if (ret == null) {
        return null;
    }
    return new MessageFormat(ret, locale);
}

From source file:org.zaproxy.zap.GuiBootstrap.java

/**
 * Determines the {@link Locale} of the current user's system.
 * <p>//w w  w  .j  a v  a 2s  .  com
 * It will match the {@link Constant#getSystemsLocale()} with the available locales from ZAPs translation files.
 * <p>
 * It may return {@code null}, if the users system locale is not in the list of available translations of ZAP.
 *
 * @return
 */
private static Locale determineUsersSystemLocale() {
    Locale userloc = null;
    final Locale systloc = Constant.getSystemsLocale();
    // first, try full match
    for (String ls : LocaleUtils.getAvailableLocales()) {
        String[] langArray = ls.split("_");
        if (langArray.length == 1) {
            if (systloc.getLanguage().equals(langArray[0])) {
                userloc = systloc;
                break;
            }
        }

        if (langArray.length == 2) {
            if (systloc.getLanguage().equals(langArray[0]) && systloc.getCountry().equals(langArray[1])) {
                userloc = systloc;
                break;
            }
        }

        if (langArray.length == 3) {
            if (systloc.getLanguage().equals(langArray[0]) && systloc.getCountry().equals(langArray[1])
                    && systloc.getVariant().equals(langArray[2])) {
                userloc = systloc;
                break;
            }
        }
    }

    if (userloc == null) {
        // second, try partial language match
        for (String ls : LocaleUtils.getAvailableLocales()) {
            String[] langArray = ls.split("_");
            if (systloc.getLanguage().equals(langArray[0])) {
                userloc = createLocale(langArray);
                break;
            }
        }
    }

    return userloc;
}