Ask about default langauge

@throws \Exception
966435
private function askAboutDefaultLanguage()
    {
        $languageList = [];
        foreach(Language::ISOlist() as $language){
            $languageList[] = $language->name;
        }

        $languageName = $this->anticipate('What is your site\'s primary language?', $languageList, 'English');
        $this->PRIMARY_LANGUAGE = Language::getISOByName($languageName);
        if(!$this->PRIMARY_LANGUAGE) {
            throw  new \Exception('Langauge could not be found in ISO 639.1 list!');
        }
    }
739322
public function getLanguage()
    {
        if ($this->project->getEmailMultiLanguage() && $this->language) {
            return $this->language;
        } else {
            return $this->project->getLocaleDefault();
        }
    }
1236885
private function _checkTemplateLanguage()
    {
        if (!defined("PSI_DEFAULT_TEMPLATE") || (($this->_template = strtolower(trim(PSI_DEFAULT_TEMPLATE))) == "") || !file_exists(PSI_APP_ROOT.'/templates/'.$this->_template.".css")) {
            $this->_template = 'phpsysinfo';
        }
        if (!defined("PSI_DEFAULT_BOOTSTRAP_TEMPLATE") || (($this->_bootstrap_template = strtolower(trim(PSI_DEFAULT_BOOTSTRAP_TEMPLATE))) == "") || !file_exists(PSI_APP_ROOT.'/templates/'.$this->_bootstrap_template."_bootstrap.css")) {
            $this->_bootstrap_template = 'phpsysinfo';
        }
        $this->_pick_template = !defined("PSI_SHOW_PICKLIST_TEMPLATE") || (PSI_SHOW_PICKLIST_TEMPLATE !== false);

        if (!defined("PSI_DEFAULT_LANG") || (($this->_language = strtolower(trim(PSI_DEFAULT_LANG))) == "") || !file_exists(PSI_APP_ROOT.'/language/'.$this->_language.".xml")) {
            $this->_language = 'en';
        }
        $this->_pick_language = !defined("PSI_SHOW_PICKLIST_LANG") || (PSI_SHOW_PICKLIST_LANG !== false);
    }
262677
private function getBrowserLanguageOrDefault()
    {
        if ($browserLanguage = getenv('HTTP_ACCEPT_LANGUAGE')) {
            $browserLocale = substr($browserLanguage, 0, 2);
            if (in_array($browserLocale, TypiCMS::enabledLocales())) {
                return $browserLocale;
            }
        }

        return config('app.locale');
    }
551271
protected function _initTranslate()
    {
        $this->bootstrap('locale');

        $language = $this->locale->getLanguage();

        /*
         * Scan for files with -<languagecode> and disable notices when the requested
         * language is not found
         */
        $options = array( 'adapter'         => 'gettext',
                          'content'         => GEMS_LIBRARY_DIR . '/languages/',
                          'disableNotices'  => true,
                          'scan'            => \Zend_Translate::LOCALE_FILENAME);

        $translate = new \Zend_Translate($options);

        // If we don't find the needed language, use a fake translator to disable notices
        if (! $translate->isAvailable($language)) {
            $translate = \MUtil_Translate_Adapter_Potemkin::create();
        }

        //Now if we have a project specific language file, add it
        $projectLanguageDir = APPLICATION_PATH . '/languages/';
        if (file_exists($projectLanguageDir)) {
            $options['content']        = $projectLanguageDir;
            $options['disableNotices'] = true;
            $projectTranslations       = new \Zend_Translate($options);
            //But only when it has the requested language
            if ($projectTranslations->isAvailable($language)) {
                $translate->addTranslation(array('content' => $projectTranslations));
            }
            unset($projectTranslations);  //Save some memory
        }

        $translate->setLocale($language);
        \Zend_Registry::set('Zend_Translate', $translate);

        // Fix for _init resource being case insensitive
        $container = $this->getContainer();
        $adapter   = $translate->getAdapter();
        $container->translateAdapter = $adapter;
        $this->translateAdapter      = $adapter;

        return $translate;
    }
1348350
protected function defaults(): self
    {
        $this->option('-h, --help', 'Show help')->on([$this, 'showHelp']);
        $this->option('-V, --version', 'Show version')->on([$this, 'showVersion']);
        $this->option('-v, --verbosity', 'Verbosity level', null, 0)->on(function () {
            $this->set('verbosity', ($this->verbosity ?? 0) + 1);

            return false;
        });

        // @codeCoverageIgnoreStart
        $this->onExit(function ($exitCode = 0) {
            exit($exitCode);
        });
        // @codeCoverageIgnoreEnd

        return $this;
    }
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();
                    }
                }
            }
        }
    }
671891
private function loadDefaultTranslations()
    {
        $language = $this->appConfig->getLanguage();

        if ($language !== null) {
            $this->loadTranslationMessages($language);
        }
    }
202676
protected function searchDefaultTranslate()
    {
        // call in: loadInternalData()
        if ($this->searchContent) {
            $this->listAllDefaultTranslate = $this->searchContent->getList();

            if ($this->dictionary && $this->listAllDefaultTranslate) {
                // if define dictionary
                foreach ($this->listAllDefaultTranslate as $identification => $item) {
                    if ($item['type'] == 'translation') {
                        $message = $item['value'];
                        // save only not exist identification and only string message or identification is same like dictionary index (default translate)
//                        if ((!isset($this->dictionary[$identification]) && !is_array($message)) || $this->dictionary[$identification] == $identification) {
                        if (!isset($this->dictionary[$identification]) || $this->dictionary[$identification] == $identification) {
                            // call only save default value load from files
                            $this->saveTranslate($identification, $message);
                        }
                    }
                }
            }
        }
    }
105669
public static function getDefaultLanguage()
    {
        if (null === self::$defaultLanguage) {
            self::$defaultLanguage = LangQuery::create()->findOneByByDefault(1);

            if (null === self::$defaultLanguage) {
                throw new \RuntimeException("No default language is defined. Please define one.");
            }
        }

        return self::$defaultLanguage;
    }
370749
public function ask($text, $default = '', $displayDefault = true)
    {
        if ($displayDefault && !empty($default)) {
            $defaultText = $default;
            if (strlen($defaultText) > 30) {
                $defaultText = substr($default, 0, 30) . '...';
            }
            $text .= " [$defaultText]";
        }
        $this->textWriter->write("$text ");
        return trim(fgets(STDIN)) ?: $default;
    }
981821
protected function initLangAndLocale () {
		$rawUaLanguages = $this->globalServer['HTTP_ACCEPT_LANGUAGE'];
		if (extension_loaded('Intl')) {
			$langAndLocaleStr = \locale_accept_from_http($rawUaLanguages);
			$langAndLocaleArr = $langAndLocaleStr !== NULL
				? explode('_', $langAndLocaleStr)
				: [NULL, NULL];
		} else {
			$languagesAndLocales = static::ParseHttpAcceptLang($rawUaLanguages);
			$langAndLocaleArr = current($languagesAndLocales);
			if (is_array($langAndLocaleArr)) 
				$langAndLocaleArr = current($langAndLocaleArr);
		}
		if ($langAndLocaleArr[0] === NULL) $langAndLocaleArr[0] = '';
		if (count($langAndLocaleArr) > 1 && $langAndLocaleArr[1] === NULL) $langAndLocaleArr[1] = '';
		list($this->lang, $this->locale) = $langAndLocaleArr;
	}
290338
public function getLang(): ?Translator
    {
        if (!$this->hasLang()) {
            $this->setLang($this->getDefaultLang());
        }
        return $this->lang;
    }
726140
private static function init()
    {
        if (!self::$defaultLng) {
            $config = Application::getConfigManager()->loadForModule('Cmf\Language');
            self::$defaultLng = strtolower($config->defaultLanguage);
            $currentLng = $config->currentLanguage;
            self::$currentLng = $currentLng ? strtolower($currentLng) : strtolower($config->defaultLanguage);
        }
    }
481423
public function setUserDefaultLanguage($lang)
    {
        $app = Application::getFacadeApplication();
        $db = $app['database']->connection();
        $session = $app['session'];

        $this->uDefaultLanguage = $lang;
        $session->set('uDefaultLanguage', $lang);
        $db->Execute('update Users set uDefaultLanguage = ? where uID = ?', array($lang, $this->getUserID()));
    }
185761
public function index()
    {
        $this->defaultData();
        $userLangService = $this->getServiceLocator()->get(UserLanguageServiceInterface::class);
        $this->setData('user-data-lang-enabled', $userLangService->isDataLanguageEnabled());
        $this->setView('user/list.tpl');
    }
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();
    }