Example usage for java.util Locale getCountry

List of usage examples for java.util Locale getCountry

Introduction

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

Prototype

public String getCountry() 

Source Link

Document

Returns the country/region code for this locale, which should either be the empty string, an uppercase ISO 3166 2-letter code, or a UN M.49 3-digit code.

Usage

From source file:org.jspringbot.keyword.i18n.I18nHelper.java

public String getCountry() {
    Locale locale = getLocale();

    LOG.keywordAppender().appendProperty("Locale Country", locale.getCountry());

    return locale.getCountry();
}

From source file:org.opendatakit.utilities.LocalizationUtilsTest.java

@Test
public void testHackedName() {
    Locale defaultLocale = Locale.getDefault();
    String full_locale = defaultLocale.getLanguage() + "_" + defaultLocale.getCountry();
    assertEquals("aname", LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale,
            NameUtil.normalizeDisplayName(NameUtil.constructSimpleDisplayName("aname"))));
    assertEquals("a name", LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale,
            NameUtil.normalizeDisplayName(NameUtil.constructSimpleDisplayName("a_name"))));
    assertEquals("_ an am e", LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale,
            NameUtil.normalizeDisplayName(NameUtil.constructSimpleDisplayName("_an_am_e"))));
    assertEquals("an ame _", LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale,
            NameUtil.normalizeDisplayName(NameUtil.constructSimpleDisplayName("an_ame_"))));
}

From source file:org.obm.opush.AutodiscoverHandlerTest.java

private String formatCultureParameter(Locale locale) {
    return locale.getLanguage().toLowerCase() + ":" + locale.getCountry().toLowerCase();
}

From source file:com.erudika.para.i18n.CurrencyUtils.java

private CurrencyUtils() {
    Locale[] locales = Locale.getAvailableLocales();
    try {//from w  w  w.j  ava2 s.  c o m
        for (Locale l : locales) {
            if (!StringUtils.isBlank(l.getCountry())) {
                COUNTRY_TO_LOCALE_MAP.put(l.getCountry(), l);
                Currency c = Currency.getInstance(l);
                if (c != null) {
                    CURRENCY_TO_LOCALE_MAP.put(c.getCurrencyCode(), l);
                    CURRENCIES_MAP.put(c.getCurrencyCode(),
                            getCurrencyName(c.getCurrencyCode(), Locale.US).concat(" ").concat(c.getSymbol(l)));
                }
            }
        }
        // overwrite main locales
        CURRENCY_TO_LOCALE_MAP.put("USD", Locale.US);
        CURRENCY_TO_LOCALE_MAP.put("EUR", Locale.FRANCE);
    } catch (Exception e) {
        logger.error(null, e);
    }
}

From source file:org.sisto.jeeplate.jsf.Oracle.java

private void populateCountries() {
    String[] allCountries = Locale.getISOCountries();
    for (String countryCode : allCountries) {
        Locale l = new Locale("", countryCode);
        this.countries.put(l.getCountry(), countryCode);
    }//from ww  w .  ja  v a  2s.  c  o  m
}

From source file:info.magnolia.module.admininterface.dialogs.LanguageSelect.java

/**
 * @see info.magnolia.cms.gui.dialog.DialogSelect#init(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, info.magnolia.cms.core.Content, info.magnolia.cms.core.Content)
 *///from  w  w  w. ja  va2s  . c om
public void init(HttpServletRequest request, HttpServletResponse response, Content websiteNode,
        Content configNode) throws RepositoryException {
    super.init(request, response, websiteNode, configNode);

    List options = new ArrayList();

    Collection col = MessagesManager.getAvailableLocales();

    for (Iterator iter = col.iterator(); iter.hasNext();) {
        Locale locale = (Locale) iter.next();
        String code = locale.getLanguage();
        if (StringUtils.isNotEmpty(locale.getCountry())) {
            code += "_" + locale.getCountry(); //$NON-NLS-1$
        }
        String name = locale.getDisplayName(MgnlContext.getLocale());
        SelectOption option = new SelectOption(name, code);
        options.add(option);
    }

    // sort them
    Collections.sort(options, new Comparator() {

        public int compare(Object arg0, Object arg1) {
            try {
                String name0 = ((SelectOption) arg0).getLabel();
                String name1 = ((SelectOption) arg1).getLabel();
                return name0.compareTo(name1);
            } catch (Exception e) {
                return 0;
            }
        }
    });

    this.setOptions(options);
}

From source file:org.overlord.sramp.ui.server.rsvcs.LocalizationRemoteService.java

/**
 * Gets the proper collection of messages for the given locale.
 * @param locale the current/desired locale
 * @return the localized messages//  w  w  w . j a  v  a  2 s .c o  m
 * @throws IOException 
 */
private Properties getMessages(Locale locale) throws IOException {
    String lang = locale.getLanguage();
    String country = locale.getCountry();
    if ("".equals(lang))
        lang = null;
    if ("".equals(country))
        country = null;

    Properties props = null;
    if (lang != null && country != null) {
        props = load("messages_" + lang + "_" + country + ".properties");
    }
    if (props == null && lang != null) {
        props = load("messages_" + lang + ".properties");
    }
    if (props == null) {
        props = load("messages.properties");
    }

    return props;
}

From source file:com.googlecode.osde.internal.editors.locale.LocaleModel.java

public LocaleModel(Locale rawModel, IProject project) {
    this();/*from w ww .j  av  a  2 s .  com*/
    country = rawModel.getCountry();
    lang = rawModel.getLang();
    internal = StringUtils.isEmpty(rawModel.getMessages());
    if (internal) {
        List<Msg> msgs = rawModel.getInlineMessages();
        for (Msg msg : msgs) {
            messages.put(msg.getName(), msg.getContent());
        }
    } else {
        loadMessageBundleFile(project);
    }
}

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;/*from   ww w.java2 s.  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: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  ww. j  a  va  2 s .c o  m

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