src/third_party/v8-3.25/src/i18n.js
/**
 * Validates the language tag. Section 2.2.9 of the bcp47 spec
 * defines a valid tag.
 *
 * ICU is too permissible and lets invalid tags, like
 * hant-cmn-cn, through.
 *
 * Returns false if the language tag is invalid.
 */
Validates the language tag. Section 2.2.9 of the bcp47 spec
defines a valid tag.

ICU is too permissible and lets invalid tags, like
hant-cmn-cn, through.

Returns false if the language tag is invalid.
Validates the language tag . Section 2 . 2 . 9 of the bcp47 spec defines a valid tag . ICU is too permissible and lets invalid tags like hant - cmn - cn through . Returns false if the language tag is invalid .
function isValidLanguageTag(locale) {
  if (GetLanguageTagRE().test(locale) === false) {
    return false;
  }
  if (locale.indexOf('x-') === 0) {
    return true;
  }
  locale = locale.split(/-x-/)[0];
  var variants = [];
  var extensions = [];
  var parts = locale.split(/-/);
  for (var i = 1; i < parts.length; i++) {
    var value = parts[i];
    if (GetLanguageVariantRE().test(value) === true && extensions.length === 0) {
      if (variants.indexOf(value) === -1) {
        variants.push(value);
      } else {
        return false;
      }
    }
    if (GetLanguageSingletonRE().test(value) === true) {
      if (extensions.indexOf(value) === -1) {
        extensions.push(value);
      } else {
        return false;
      }
    }
  }
  return true;
 }
function isValidLanguageTag ( locale ) { if ( GetLanguageTagRE ( ) . test ( locale ) === false ) { return false ; } if ( locale . indexOf ( 'x-' ) === 0 ) { return true ; } locale = locale . split ( / -x- / ) [ 0 ] ; var variants = [ ] ; var extensions = [ ] ; var parts = locale . split ( / - / ) ; for ( var i = 1 ; i < parts . length ; i ++ ) { var value = parts [ i ] ; if ( GetLanguageVariantRE ( ) . test ( value ) === true && extensions . length === 0 ) { if ( variants . indexOf ( value ) === - 1 ) { variants . push ( value ) ; } else { return false ; } } if ( GetLanguageSingletonRE ( ) . test ( value ) === true ) { if ( extensions . indexOf ( value ) === - 1 ) { extensions . push ( value ) ; } else { return false ; } } } return true ; }
Validates the language tag.
Validates the language tag .
// Check if it's well-formed, including grandfadered tags. // Just return if it's a x- form. It's all private. // Check if there are any duplicate variants or singletons (extensions). // Remove private use section. // Skip language since it can match variant regex, so we start from 1. // We are matching i-klingon here, but that's ok, since i-klingon-klingon // is not valid and would fail LANGUAGE_TAG_RE test.