/*
This function detects site's language based on URL. If no URL language is detected
the default_language is used.
436531
public function languageDetection() {
        $current_url = $this->getSession()->getCurrentUrl();
        $base_url = $this->getMinkParameter('base_url');
        // Checks whether the last symbol in the base_url is /, if not it adds it
        if (substr($base_url, -1) != "/") {
            $base_url = $base_url."/";
        }
        $base_url_length = strlen($base_url);
        //Get the 2 symbols in current URL after the base_url when Clean URLs is enabled
        $clean_url_language_code = substr($current_url,$base_url_length,2);
        $not_clean_url_language_code = substr($current_url,$base_url_length+3,2);
        if(in_array($clean_url_language_code,$this->languages_iso_codes) && substr($current_url,$base_url_length+2,1) == "/") {
            return $clean_url_language_code;
        }
        else if (in_array($not_clean_url_language_code,$this->languages_iso_codes) && substr($current_url,$base_url_length+5,1) == "/"){
            return $not_clean_url_language_code;
        }
        else return $this->multilingual_parameters['default_language'];
    }
815091
function onSetLanguageCode() {
  var languageCode = $('#language-code').val() || null;
  try {
    auth.languageCode = languageCode;
    alertSuccess('Language code changed to "' + languageCode + '".');
  } catch (error) {
    alertError('Error: ' + error.code);
  }
}
127768
public static function redirectToDefaultLanguage()
    {
        $getCurrentPath = Request::path();
        $explodePath = explode('/', $getCurrentPath);

        //only proceed if there is a language found in first path and that's default language
        if(App::getLocale() == Language::getDefault("slug")) {
            $countPaths = count($explodePath);
            $getLanguage = Language::findBySlug($explodePath[0]);

            if($getLanguage) {
                if($getLanguage->isDefault) {
                    if($countPaths >= 2 && $explodePath[0] && $explodePath[1]) {
                        $urlAfterLanguage = substr($getCurrentPath, 3);
                        Redirect::to($urlAfterLanguage, 301)->send();
                    }
                    //that's shall be default language
                    else if($countPaths == 1 && $explodePath[0]) {
                        Redirect::to('/', 301)->send();
                    }
                }
            }
        }
    }
871928
public static function parseURL(array &$args, $leaveDefaultLocale = true)
    {
        // Iterate defined site locales
        foreach (self::$locales as $locale) {
            // Search locale string as URL argument
            if (($key = array_search($locale, $args)) === 0) {
                // Change current locale
                self::current($locale);

                // If this is not default locale(empty string) - remove it from URL arguments
                if ($leaveDefaultLocale || $locale != self::DEF) {
                    // Remove argument contained locale string
                    unset($args[$key]);

                    // Reindex array
                    $args = array_values($args);
                }

                // Return true status
                return true;
            }
        }

        // If we are here - this is default locale
        // Switch to current web-application $default locale
        self::current(self::DEF);

        return false;
    }
252254
public function getLanguage() {
		if ($this->languageDetection === null) {
			$this->languageDetection = new BrowserLanguageDetection();
		}
		$language = $this->languageDetection->getLanguage();
		if (file_exists(ROOT_PATH.$this->i18nMessagePath.'message_'.$language.'.php')) {
			return $language;
		} else {
			return "default";
		}
	}
1107594
def sitemap_check(url):
        
        response = urllib2.urlopen(UrlExtractor.get_sitemap_url(url, True))

        # Check if "Sitemap" is set
        return "Sitemap:" in response.read().decode('utf-8')
1342548
protected function detect($uri=NULL) {
		$this->current=$this->primary;
		if (preg_match('/^'.preg_quote($this->f3->get('BASE'),'/').'\/([^\/?]+)([\/?]|$)/',$uri?:$_SERVER['REQUEST_URI'],$m) &&
				array_key_exists($m[1],$this->languages))
			$this->current=$m[1];
		else {//auto-detect language
			$this->auto=TRUE;
			$detected=array_intersect(explode(',',$this->f3->get('LANGUAGE')),explode(',',implode(',',$this->languages)));
			if ($detected=reset($detected))
				foreach($this->languages as $lang=>$locales)
					if (in_array($detected,explode(',',$locales))) {
						$this->current=$lang;
						break;
					}
		}
		$this->f3->set('LANGUAGE',$this->languages[$this->current]);
	}
1251702
function isSameOrigin(a, b) {
  var urlA = parseURL(a);
  var urlB = parseURL(b);
  if (!urlA || !urlB) {
    return false;
  }
  if (urlA.origin === urlB.origin) {
    return true;
  }
  if (
    urlA.protocol === urlB.protocol &&
    urlA.hostname === urlB.hostname &&
    urlA.port === urlB.port
  ) {
    return true;
  }
  return false;
}
1078818
function buildOrigin(src, href) {
  try {
    const url = new URL(src, href || location.href);
    return url.origin;
  } catch (error) {
    return null;
  }
}
712518
private function setLanguageFromBrowser(): void
    {
        $userLang = App::$Properties->get('singleLanguage');
        $browserAccept = $this->getLanguages();
        if (Any::isArray($browserAccept) && count($browserAccept) > 0) {
            foreach ($browserAccept as $bLang) {
                if (Arr::in($bLang, App::$Properties->get('languages'))) {
                    $userLang = $bLang;
                    break; // stop calculating, language is founded in priority
                }
            }
        }

        // parse query string
        $queryString = null;
        if (count($this->query->all()) > 0) {
            $queryString = '?' . http_build_query($this->query->all());
        }

        // build response with redirect to language-based path
        $redirectUrl = $this->getSchemeAndHttpHost() . $this->basePath . '/' . $userLang . $this->getPathInfo() . $queryString;
        $response = new RedirectResponse($redirectUrl);
        $response->send();
        exit();
    }
606512
def get_parler_languages_from_django_cms(cms_languages=None):
    
    valid_keys = ['code', 'fallbacks', 'hide_untranslated',
                  'redirect_on_fallback']
    if cms_languages:
        if sys.version_info < (3, 0, 0):
            int_types = (int, long)
        else:
            int_types = int

        parler_languages = copy.deepcopy(cms_languages)
        for site_id, site_config in cms_languages.items():
            if site_id and (
                    not isinstance(site_id, int_types) and
                    site_id != 'default'
            ):
                del parler_languages[site_id]
                continue

            if site_id == 'default':
                for key, value in site_config.items():
                    if key not in valid_keys:
                        del parler_languages['default'][key]
            else:
                for i, lang_config in enumerate(site_config):
                    for key, value in lang_config.items():
                        if key not in valid_keys:
                            del parler_languages[site_id][i][key]
        return parler_languages
    return None
631481
def _extract_language(self):
        

        if self.language:
            return

        found = False

        for pattern in self.config.language:
            for item in self.parsed_tree.xpath(pattern):
                stripped_language = item.strip()

                if stripped_language:
                    self.language = stripped_language
                    LOGGER.info(u'Language extracted: %s.', stripped_language,
                                extra={'siteconfig': self.config.host})
                    found = True
                    break

            if found:
                break
1119059
function isSameOrigin(url) {
    let location = window.location;
    let a = document.createElement('a');

    a.href = url;

    return a.hostname == location.hostname &&
        a.port == location.port &&
        a.protocol == location.protocol;
}
991124
protected function find_language() {
        global $CFG;
        $this->language = current_language();
        $basedir = $CFG->dirroot . '/media/player/videojs/videojs/lang/';
        $langfiles = get_directory_list($basedir);
        $candidates = [];
        foreach ($langfiles as $langfile) {
            if (strtolower(pathinfo($langfile, PATHINFO_EXTENSION)) !== 'js') {
                continue;
            }
            $lang = basename($langfile, '.js');
            if (strtolower($langfile) === $this->language . '.js') {
                // Found an exact match for the language.
                $js = file_get_contents($basedir . $langfile);
                break;
            }
            if (substr($this->language, 0, 2) === strtolower(substr($langfile, 0, 2))) {
                // Not an exact match but similar, for example "pt_br" is similar to "pt".
                $candidates[$lang] = $langfile;
            }
        }
        if (empty($js) && $candidates) {
            // Exact match was not found, take the first candidate.
            $this->language = key($candidates);
            $js = file_get_contents($basedir . $candidates[$this->language]);
        }
        // Add it as a language for Video.JS.
        if (!empty($js)) {
            return "$js\n";
        }

        // Could not match, use default language of video player (English).
        $this->language = null;
        return "";
    }
1135292
def get_active_choices(self, language_code=None, site_id=None):
        
        if language_code is None:
            language_code = get_language()

        lang_dict = self.get_language(language_code, site_id=site_id)
        if not lang_dict['hide_untranslated']:
            return [language_code] + [lang for lang in lang_dict['fallbacks'] if lang != language_code]
        else:
            return [language_code]
82141
function pageLang(page) {
    return page.lang ||
      opts.lang ||
      (opts.langDirs && !u.isRootLevel(page._href) && u.topLevel(page._href)) ||
      'en';
  }
1259574
def languages
      if default_language != nil
        # Use specified default language as primary language
        [default_language]
      else
        # Calculate the intersection of native development and used languages,
        # fallback to the latter only, if it is empty
        languages = native_dev_languages & used_languages
        if languages.empty?
          used_languages
        else
          languages
        end
      end
    end