Eval locale from language, region and variant
@param language
@param region
@param variant
@return the new Locale constructed
425702
public static Locale locale(String language, String region, String variant) {
        return new Locale(language, region, variant);
    }
564392
private void handleLangs(final Map<String, Object> dataModel) {
        final Locale locale = Latkes.getLocale();
        final String language = locale.getLanguage();
        final String country = locale.getCountry();
        final String variant = locale.getVariant();

        final StringBuilder keyBuilder = new StringBuilder(language);

        if (StringUtils.isNotBlank(country)) {
            keyBuilder.append("_").append(country);
        }
        if (StringUtils.isNotBlank(variant)) {
            keyBuilder.append("_").append(variant);
        }

        final String localKey = keyBuilder.toString();
        final Properties props = langs.get(localKey);

        if (null == props) {
            return;
        }

        final Set<Object> keySet = props.keySet();

        for (final Object key : keySet) {
            dataModel.put((String) key, props.getProperty((String) key));
        }
    }
17369
public static Locale parseLocale(String localeString) {
    if (localeString == null) {
      return Locale.US;
    }
    String[] groups = localeString.split("[-_]");
    switch (groups.length) {
      case 1:
        return new Locale(groups[0]);
      case 2:
        return new Locale(groups[0], Ascii.toUpperCase(groups[1]));
      case 3:
        return new Locale(groups[0], Ascii.toUpperCase(groups[1]), groups[2]);
      default:
        throw new IllegalArgumentException("Malformed localeString: " + localeString);
    }
  }
1223612
protected void setLocale( Locale locale )
    {
        if ( locale == null ) locale = getDefaultLocale();
        getSession().setAttribute( Globals.LOCALE_KEY, locale );
    }
599421
public void setLocale(Object loc) throws JspTagException {
        if (loc == null
                || (loc instanceof String && ((String) loc).length() == 0)) {
            this.locale = null;
        } else if (loc instanceof Locale) {
            this.locale = (Locale) loc;
        } else {
            locale = Util.parseLocale((String) loc);
        }
    }
1202157
private static void localize( final Class<?> i18nClass,
                                  final Locale locale ) {
        assert i18nClass != null;
        assert locale != null;
        // Create a class-to-problem map for this locale if one doesn't exist, else get the existing one.
        Map<Class<?>, Set<String>> classToProblemsMap = new ConcurrentHashMap<Class<?>, Set<String>>();
        Map<Class<?>, Set<String>> existingClassToProblemsMap = LOCALE_TO_CLASS_TO_PROBLEMS_MAP.putIfAbsent(locale,
                                                                                                            classToProblemsMap);
        if (existingClassToProblemsMap != null) {
            classToProblemsMap = existingClassToProblemsMap;
        }
        // Check if already localized outside of synchronization block for 99% use-case
        if (classToProblemsMap.get(i18nClass) != null) {
            return;
        }
        synchronized (i18nClass) {
            // Return if the supplied i18n class has already been localized to the supplied locale, despite the check outside of
            // the synchronization block (1% use-case), else create a class-to-problems map for the class.
            Set<String> problems = classToProblemsMap.get(i18nClass);
            if (problems == null) {
                problems = new CopyOnWriteArraySet<String>();
                classToProblemsMap.put(i18nClass, problems);
            } else {
                return;
            }
            // Get the URL to the localization properties file ...
            final String localizationBaseName = i18nClass.getName();
            URL bundleUrl = ClasspathLocalizationRepository.getLocalizationBundle(i18nClass.getClassLoader(), localizationBaseName, locale);
            if (bundleUrl == null && i18nClass == CommonI18n.class) {
                throw new SystemFailureException("CommonI18n.properties file not found in classpath !");
            }
            if (bundleUrl == null) {
                LOGGER.warn(CommonI18n.i18nBundleNotFoundInClasspath,
                            ClasspathLocalizationRepository.getPathsToSearchForBundle(localizationBaseName, locale));
                // Nothing was found, so try the default locale
                Locale defaultLocale = Locale.getDefault();
                if (!defaultLocale.equals(locale)) {
                    bundleUrl = ClasspathLocalizationRepository.getLocalizationBundle(i18nClass.getClassLoader(), localizationBaseName, defaultLocale);
                }
                // Return if no applicable localization file could be found
                if (bundleUrl == null) {
                    LOGGER.error(CommonI18n.i18nBundleNotFoundInClasspath,
                                 ClasspathLocalizationRepository.getPathsToSearchForBundle(localizationBaseName, defaultLocale));
                    LOGGER.error(CommonI18n.i18nLocalizationFileNotFound, localizationBaseName);
                    problems.add(CommonI18n.i18nLocalizationFileNotFound.text(localizationBaseName));
                    return;
                }
            }
            // Initialize i18n map
            Properties props = prepareBundleLoading(i18nClass, locale, bundleUrl, problems);

            try {
                InputStream propStream = bundleUrl.openStream();
                try {
                    props.load(propStream);
                    // Check for uninitialized fields
                    for (Field fld : i18nClass.getDeclaredFields()) {
                        if (fld.getType() == I18n.class) {
                            try {
                                I18n i18n = (I18n)fld.get(null);
                                if (i18n.localeToTextMap.get(locale) == null) {
                                    i18n.localeToProblemMap.put(locale,
                                                                CommonI18n.i18nPropertyMissing.text(fld.getName(), bundleUrl));
                                }
                            } catch (IllegalAccessException notPossible) {
                                // Would have already occurred in initialize method, but allowing for the impossible...
                                problems.add(notPossible.getMessage());
                            }
                        }
                    }
                } finally {
                    propStream.close();
                }
            } catch (IOException err) {
                problems.add(err.getMessage());
            }
        }
    }
514247
public static void setLocale(@NonNull Locale locale) {
        if (!locale.equals(Locale.getDefault())) {
            LocalizationHelper.locale = locale;
            Locale.setDefault(locale);
        }
    }
1301116
private CellFormatResult getFormulaCellValue(final Cell cell, final Locale locale) {

        final CellType cellType = cell.getCellTypeEnum();
        assert cellType == CellType.FORMULA;

        final Workbook workbook = cell.getSheet().getWorkbook();
        final CreationHelper helper = workbook.getCreationHelper();
        final FormulaEvaluator evaluator = helper.createFormulaEvaluator();

        try {
            final CellValue value = evaluator.evaluate(cell);
            final POIEvaluatedCell evaluatedCell = new POIEvaluatedCell(cell, value);

            switch(value.getCellTypeEnum()) {

                case BOOLEAN:
                    return getCellValue(evaluatedCell, locale);

                case STRING:
                    return getCellValue(evaluatedCell, locale);

                case NUMERIC:
                    return getCellValue(evaluatedCell, locale);

                case ERROR:
                    return getErrorCellValue(value.getErrorValue(), locale);

                default:
                    final CellFormatResult result = new CellFormatResult();
                    result.setCellType(FormatCellType.Unknown);
                    result.setText("");
                    return result;
            }

        } catch(Exception e) {
            if(isThrowFailEvaluateFormula()) {
                throw new FormulaEvaluateException(cell, e);
            } else {
                return getErrorCellValue(cell.getErrorCellValue(), locale);
            }
        }

    }
409011
public static Locale selectLocale(Locale vrloc, Object loc, UIComponent comp) {
		java.util.Locale selLocale = vrloc;

		if (loc != null) {
			if (loc instanceof String) {
				selLocale = BsfUtils.toLocale((String) loc);
			} else if (loc instanceof java.util.Locale) {
				selLocale = (java.util.Locale) loc;
			} else {
				throw new IllegalArgumentException(
						"Type:" + loc.getClass() + " is not a valid locale type for " + comp.getFamily() + ":" + comp.getClientId());
			}
		}

		return selLocale;
	}
170532
private Instance getExistingLocale(final long _propertyid,
                                       final String _language)
    {
        Instance ret = null;
        try {
            final QueryBuilder queryBldr = new QueryBuilder(Type.get(DBPropertiesUpdate.TYPE_PROPERTIES_LOCAL));
            queryBldr.addWhereAttrEqValue("PropertyID", _propertyid);
            queryBldr.addWhereAttrEqValue("LanguageID", getLanguageId(_language));
            final InstanceQuery query = queryBldr.getQuery();
            query.executeWithoutAccessCheck();
            if (query.next()) {
                ret = query.getCurrentValue();
            }
        } catch (final EFapsException e) {
            DBPropertiesUpdate.LOG.error("getExistingLocale(String)", e);
        }
        return ret;
    }
990927
public void setCaseCanonicalizationLocale(final Locale caseCanonicalizationLocale) {
        if (caseCanonicalizationLocale == null) {
            this.caseCanonicalizationLocale = Locale.getDefault();
        } else {
            this.caseCanonicalizationLocale = caseCanonicalizationLocale;
        }
    }
1162212
private String localize(String key, String defaultValue) {
    String result = defaultValue;
    if (bundle != null) {
      try {
        result = bundle.getString(key);
      }
      catch (MissingResourceException mre) {
      }
    }
    return result;
  }
473604
private Locale getLocale(FacesContext context) {

        // PENDING(craigmcc) - JSTL localization context?
        Locale locale = this.locale;
        if (locale == null) {
            locale = context.getViewRoot().getLocale();
        }
        return (locale);

    }
723770
public Locale getLocaleWithCountryAndVariant() {
    if (getCountries().length > 0) {
      if (getVariant() != null) {
        return new Locale(getShortCode(), getCountries()[0], getVariant());
      } else {
        return new Locale(getShortCode(), getCountries()[0]);
      }
    } else {
      return getLocale();
    }
  }
46038
public void setLocale(final Locale locale) {
        if (!equals(this.locale, locale)) {
            this.locale = locale;
            super.setValue(toString(locale));
            i18nBundleProvider.reloadBundles(locale);
        }
    }
1311998
private List<Locale> extractLocales(List<List<String>> allLangs) {
        List<Locale> rc = new ArrayList<Locale>();
        for (List<String> langList : allLangs) {
            for (String language : langList) {
                String country = "";
                String variant = "";
                int countryIndex = language.indexOf('-');
                if (countryIndex > -1) {
                    int variantIndex = language.indexOf('-', (countryIndex + 1));
                    if (variantIndex > -1) {
                        variant = language.substring(variantIndex + 1).trim();
                        country = language.substring(countryIndex, variantIndex).trim();
                    } else {
                        country = language.substring(countryIndex + 1).trim();
                    }
                    language = language.substring(0, countryIndex).trim();
                }

                rc.add(new Locale(language, country, variant));
            }
        }

        return rc;
    }
492216
public static Locale resolveLocale(Object locale, String clientId) {
        Locale result = null;

        if (locale != null) {
            if (locale instanceof String) {
                result = toLocale((String) locale);
            }
            else if (locale instanceof java.util.Locale) {
                result = (java.util.Locale) locale;
            }
            else {
                throw new IllegalArgumentException("Type:" + locale.getClass() + " is not a valid locale type for: " + clientId);
            }
        }
        else {
            // default to the view local
            result = FacesContext.getCurrentInstance().getViewRoot().getLocale();
        }

        return result;
    }