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.tiles.xmlDefinition.I18nFactorySet.java

/**
 * Calculate the postixes along the search path from the base bundle to the
 * bundle specified by baseName and locale.
 * Method copied from java.util.ResourceBundle
 * @param baseName the base bundle name//ww w . j ava  2s  . c o  m
 * @param locale the locale
 */
private static List calculatePostixes(String baseName, Locale locale) {
    final List result = new ArrayList(MAX_BUNDLES_SEARCHED);
    final String language = locale.getLanguage();
    final int languageLength = language.length();
    final String country = locale.getCountry();
    final int countryLength = country.length();
    final String variant = locale.getVariant();
    final int variantLength = variant.length();

    if (languageLength + countryLength + variantLength == 0) {
        //The locale is "", "", "".
        return result;
    }

    final StringBuffer temp = new StringBuffer(baseName);
    temp.append('_');
    temp.append(language);

    if (languageLength > 0)
        result.add(temp.toString());

    if (countryLength + variantLength == 0)
        return result;

    temp.append('_');
    temp.append(country);

    if (countryLength > 0)
        result.add(temp.toString());

    if (variantLength == 0) {
        return result;
    } else {
        temp.append('_');
        temp.append(variant);
        result.add(temp.toString());
        return result;
    }
}

From source file:org.jahia.utils.LanguageCodeConverters.java

/**
 * Returns a language tags encoded (RFC 3066) compliant string from
 * a Java Locale object. Note that Locales without any languages will
 * not be accepted by this method and will return a null String since
 * language tags MUST contain a language
 *
 * @param locale the locale we want to be converted.
 *
 * @return a String containing the RFC 3066 encoded language information
 * extracted from the tag. If their is no language found in the locale a
 * NULL string is returned instead !//from ww  w  . j  a v a 2 s  . c o m
 */
public static String localeToLanguageTag(Locale locale) {
    StringBuilder result = new StringBuilder();
    if (!("".equals(locale.getLanguage()))) {
        result.append(locale.getLanguage());
    } else {
        // if there is no language we can't return a valid
        // language tag.
        return null;
    }
    if (!("".equals(locale.getCountry()))) {
        result.append("-");
        result.append(locale.getCountry());
    }
    if (!("".equals(locale.getVariant()))) {
        result.append("-");
        result.append(locale.getVariant());
    }

    return result.toString();
}

From source file:org.vfny.geoserver.config.web.tiles.definition.MultipleDefinitionsFactory.java

/**
 * Calculate the postixes along the search path from the base bundle to the
 * bundle specified by baseName and locale.
 * Method copied from java.util.ResourceBundle
 * @param baseName the base bundle name//from  ww  w . j  ava  2 s .  co m
 * @param locale the locale
 */
private static List calculatePostixes(String baseName, Locale locale) {
    final List result = new ArrayList(MAX_BUNDLES_SEARCHED);
    final String language = locale.getLanguage();
    final int languageLength = language.length();
    final String country = locale.getCountry();
    final int countryLength = country.length();
    final String variant = locale.getVariant();
    final int variantLength = variant.length();

    if ((languageLength + countryLength + variantLength) == 0) {
        //The locale is "", "", "".
        return result;
    }

    final StringBuffer temp = new StringBuffer(baseName);
    temp.append('_');
    temp.append(language);

    if (languageLength > 0) {
        result.add(temp.toString());
    }

    if ((countryLength + variantLength) == 0) {
        return result;
    }

    temp.append('_');
    temp.append(country);

    if (countryLength > 0) {
        result.add(temp.toString());
    }

    if (variantLength == 0) {
        return result;
    } else {
        temp.append('_');
        temp.append(variant);
        result.add(temp.toString());

        return result;
    }
}

From source file:wicket.SharedResources.java

/**
 * THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT. Inserts
 * _[locale] and _[style] into path just before any extension that might
 * exist.//from w  w  w  . jav a2s .c  om
 * 
 * @param path
 *            The resource path
 * @param locale
 *            The locale
 * @param style
 *            The style (see {@link wicket.Session})
 * @return The localized path
 */
public static String resourceKey(final String path, final Locale locale, final String style) {
    final String extension = Files.extension(path);
    final String basePath = Files.basePath(path, extension);
    final AppendingStringBuffer buffer = new AppendingStringBuffer(basePath.length() + 16);
    buffer.append(basePath);

    // First style because locale can append later on.
    if (style != null) {
        buffer.append('_');
        buffer.append(style);
    }
    if (locale != null) {
        buffer.append('_');
        boolean l = locale.getLanguage().length() != 0;
        boolean c = locale.getCountry().length() != 0;
        boolean v = locale.getVariant().length() != 0;
        buffer.append(locale.getLanguage());
        if (c || (l && v)) {
            buffer.append('_').append(locale.getCountry()); // This may just
            // append '_'
        }
        if (v && (l || c)) {
            buffer.append('_').append(locale.getVariant());
        }
    }
    if (extension != null) {
        buffer.append('.');
        buffer.append(extension);
    }
    return buffer.toString();
}

From source file:org.dspace.core.I18nUtil.java

/**
 * Get the appropriate localized version of a file according to language settings
 * e. g. help files in jsp/help///from w  w  w . ja  v  a 2 s  . c om
 *
 * @param locale
 *        Locale to get the file for
 * @param fileName
 *        String fileName, to get the localized file for
 * @param fileType
 *        String file extension
 * @return localizedFileName
 *          String - localized filename
 */
private static String getFilename(Locale locale, String fileName, String fileType) {
    String localizedFileName = null;
    boolean fileFound = false;
    // with Language, Country, Variant
    String fileNameLCV = null;
    // with Language, Country
    String fileNameLC = null;
    // with Language
    String fileNameL = null;
    fileNameL = fileName + "_" + locale.getLanguage();

    if (fileType == null) {
        fileType = "";
    }

    if (!("".equals(locale.getCountry()))) {
        fileNameLC = fileName + "_" + locale.getLanguage() + "_" + locale.getCountry();

        if (!("".equals(locale.getVariant()))) {
            fileNameLCV = fileName + "_" + locale.getLanguage() + "_" + locale.getCountry() + "_"
                    + locale.getVariant();
        }
    }

    if (fileNameLCV != null && !fileFound) {
        File fileTmp = new File(fileNameLCV + fileType);
        if (fileTmp.exists()) {
            fileFound = true;
            localizedFileName = fileNameLCV + fileType;
        }
    }

    if (fileNameLC != null && !fileFound) {
        File fileTmp = new File(fileNameLC + fileType);
        if (fileTmp.exists()) {
            fileFound = true;
            localizedFileName = fileNameLC + fileType;
        }
    }

    if (fileNameL != null && !fileFound) {
        File fileTmp = new File(fileNameL + fileType);
        if (fileTmp.exists()) {
            fileFound = true;
            localizedFileName = fileNameL + fileType;
        }
    }
    if (!fileFound) {
        localizedFileName = fileName + fileType;
    }
    return localizedFileName;
}

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

public static long getLastModifiedDate(String filePath, Locale locale) {
    if (filePath.startsWith("system")) {
        File file = null;/* w  ww .j av  a  2 s  .c  om*/
        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) {
            return file.lastModified();
        }
    } else {
        RepositoryFile repositoryFile = null;
        if (locale == null) {
            repositoryFile = getRepository().getFile(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$
                repositoryFile = getRepository()
                        .getFile(baseName + "_" + language + "_" + country + "_" + variant + extension); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            }
            if (repositoryFile == null) {
                repositoryFile = getRepository().getFile(baseName + "_" + language + "_" + country + extension); //$NON-NLS-1$//$NON-NLS-2$
            }
            if (repositoryFile == null) {
                repositoryFile = getRepository().getFile(baseName + "_" + language + extension); //$NON-NLS-1$
            }
            if (repositoryFile == null) {
                repositoryFile = getRepository().getFile(filePath);
            }
        }
        if (repositoryFile != null) {
            return repositoryFile.getLastModifiedDate().getTime();
        }
    }
    return -1L;
}

From source file:org.apache.cocoon.forms.datatype.convertor.LocaleMap.java

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

From source file:nl.strohalm.cyclos.utils.conversion.LocaleConverter.java

public String toString(final Locale locale) {
    if (locale == null) {
        return null;
    }//w w  w .  j  a va  2s  .c o m
    final String variant = locale.getVariant();
    if (StringUtils.isEmpty(variant)) {
        return locale.getLanguage() + "_" + locale.getCountry();
    } else {
        return locale.getLanguage() + "_" + locale.getCountry() + "_" + locale.getVariant();
    }
}

From source file:ca.sqlpower.dao.session.LocaleConverter.java

@Override
public String convertToSimpleType(Locale convertFrom, Object... additionalInfo) {
    return convertFrom.getLanguage() + SEPARATOR + convertFrom.getCountry() + SEPARATOR
            + convertFrom.getVariant();
}

From source file:com.haulmont.cuba.core.sys.FormatStringsRegistryImpl.java

@Override
public void setFormatStrings(Locale locale, FormatStrings formatStrings) {
    formatStringsMap.put(locale, formatStrings);
    if (!StringUtils.isEmpty(locale.getCountry()) || !StringUtils.isEmpty(locale.getVariant()))
        useLocaleLanguageOnly = false;/*  w  w w .j  a v  a 2 s  .c  o  m*/
}