Determine the RFC 3066 compliant language tag,
as used for the HTTP "Accept-Language" header.
@param locale the Locale to transform to a language tag
@return the RFC 3066 compliant language tag as {@code String}
180350
public static String toLanguageTag(Locale locale) {
        return locale.getLanguage() + (hasText(locale.getCountry()) ? "-" + locale.getCountry() : EMPTY);
    }
1009411
public String getLocaleName(final Locale locale) {
        return messageResolver.getMessage(locale, String.format("color.%d.name", index));
    }
1006403
public function getTagAndSetLocale($name, $locale = null)
    {
        $tag = $this->getTag($name);

        // Override locale or use tag locale
        // this is for when a tag does not have to be translated
        // and the app locale is determined via route parameter (etiket|tag)
        $locale = $locale ?: $tag->getLocaleForName($name);

        set_app_locale($locale);

        return $tag;
    }
1190523
public static function getLanguageFromLocale($locale)
    {
        if (strpos($locale, '_')) {
            $parts = explode('_', $locale);

            return strtolower($parts[0]);
        }

        return $locale;
    }
182267
public String key(Locale locale) {

        if (getBundle() == null) {
            return getKey();
        }
        return getBundle().getBundle(locale).key(getKey(), getArgs());
    }
794179
public boolean isMarkedNoTranslation(Locale locale) {

        if (m_noTranslation != null) {
            return CmsLocaleManager.getLocales(m_noTranslation).contains(locale);
        }
        return false;
    }
25711
public String getDisplayVariant(Locale locale) {
        String variantCode = baseLocale.getVariant();
        if (variantCode.isEmpty()) {
            return "";
        }

        try {
            normalizeAndValidateVariant(variantCode);
        } catch (IllformedLocaleException ilfe) {
            return variantCode;
        }

        String result = ICU.getDisplayVariant(this, locale);
        if (result == null) { // TODO: do we need to do this, or does ICU do it for us?
            result = ICU.getDisplayVariant(this, Locale.getDefault());
        }

        // The "old style" locale constructors allow us to pass in variants that aren't
        // valid BCP-47 variant subtags. When that happens, toLanguageTag will not emit
        // them. Note that we know variantCode.length() > 0 due to the isEmpty check at
        // the beginning of this function.
        if (result.isEmpty()) {
            return variantCode;
        }
        return result;
    }
1227704
public static function getLanguage($locale)
    {
        return isset(self::$locales[$locale])
            ? self::$locales[$locale]
            : $locale;
    }
408767
protected String getLabel(Locale locale) {

        return OpenCms.getWorkplaceManager().getMessages(locale).key(m_labelKey);
    }
713641
public static boolean hasLocale(final Locale locale) {
        try {
            ResourceBundle.getBundle(Keys.LANGUAGE, locale);

            return true;
        } catch (final MissingResourceException e) {
            return false;
        }
    }
450709
Locale getLocale(HandshakeRequest request) {
		if(null != request) {
			Map<String, List<String>> headers = request.getHeaders();
			if(null != headers) {
				List<String> accepts = headers.get(HttpHeaders.ACCEPT_LANGUAGE);
				logger.debug("Get accept-language from client headers : {}", accepts);
				if (null != accepts) {
					for (String accept : accepts) {
						try {
							return localeExtractor.extractFromAccept(accept);
						} catch (LocaleNotFoundException ex) {
						}
					}
				}
			}
		}
		return Locale.US;
	}
836066
@Override
    public void setLocale(Locale inLocale) {
        if (isCommitted() || null == inLocale) {
            return;
        }
        this.locale = inLocale;
        if (null != this.outWriter || null != this.encoding) {
            return;
        }
        EncodingUtils encodingUtils = connection.getEncodingUtils();
        this.encoding = encodingUtils.getEncodingFromLocale(inLocale);
        if (null == this.encoding) {
            this.encoding = encodingUtils.getDefaultEncoding();
        }
        if (null != this.contentType) {
            int index = this.contentType.indexOf("charset=");
            StringBuilder sb = new StringBuilder();
            if (-1 != index) {
                sb.append(this.contentType.substring(0, index - 1).trim());
            }
            if (this.encoding != null) {
                sb.append(";charset=").append(this.encoding);
            }

            this.response.setHeader("Content-Type", sb.toString());
        }
    }
643633
protected final String toLocaleStr(Locale locale) {
    if (locale == Locale.ROOT) { return ""; }
    String language = locale.getLanguage();
    String country = locale.getCountry();
    String variant = locale.getVariant();
    if (language == "" && country == "" && variant == "") { return ""; }

    StringBuilder sb = new StringBuilder();
    if (variant != "") {
      sb.append(language).append('_').append(country).append('_').append(variant);
    } else if (country != "") {
      sb.append(language).append('_').append(country);
    } else {
      sb.append(language);
    }
    return sb.toString();
  }
1045031
public static String getLocalDisplayName(String locale) {
		String desc = "" + locale;
		if (locale != null) {
			String[] langArray = locale.split("_");
	        Locale loc = null;
	        if (langArray.length == 1) {
	            loc = new Locale(langArray[0]);
	        } else if (langArray.length == 2) {
	            loc = new Locale(langArray[0], langArray[1]);
	        } else if (langArray.length == 3) {
	            loc = new Locale(langArray[0], langArray[1], langArray[2]);
	        }
	        if (loc != null) {
	        	desc = loc.getDisplayLanguage(loc);
	        }
		}
		return desc;
	}
836061
public static function formatLocale($locale)
    {
        if (\is_string($locale)) {
            $locale = strtolower($locale);
            $locale = str_replace('-', '_', $locale);
        }

        return $locale;
    }
1363603
public String getDisplayLanguage(Locale locale) {
        String languageCode = baseLocale.getLanguage();
        if (languageCode.isEmpty()) {
            return "";
        }

        // Hacks for backward compatibility.
        //
        // Our language tag will contain "und" if the languageCode is invalid
        // or missing. ICU will then return "langue indéterminée" or the equivalent
        // display language for the indeterminate language code.
        //
        // Sigh... ugh... and what not.
        final String normalizedLanguage = normalizeAndValidateLanguage(
                languageCode, false /* strict */);
        if (UNDETERMINED_LANGUAGE.equals(normalizedLanguage)) {
            return languageCode;
        }

        // TODO: We need a new hack or a complete fix for http://b/8049507 --- We would
        // cover the frameworks' tracks when they were using "tl" instead of "fil".
        String result = ICU.getDisplayLanguage(this, locale);
        if (result == null) { // TODO: do we need to do this, or does ICU do it for us?
            result = ICU.getDisplayLanguage(this, Locale.getDefault());
        }
        return result;
    }
1276375
public String getDescription(final String locale) {
        if (this.uiInfo != null) {
            val description = getLocalizedValues(locale, this.uiInfo.getDescriptions());
            return description != null ? description : super.getDescription();
        }
        return super.getDescription();
    }