function chooseAction() { // TODO maybe? - prevent people from viewing this page if localization is not enabled $default_locale = strtolower(Bolts_Registry::get('default_locale', 'default')); $request = new Bolts_Request($this->getRequest()); // TODO - get cookie value and validate it // TODO - only redirect if a valid cookie value exists ! if (!$request->has('change') && false) { $this->_redirect("/" . $this->locale_code); } // Force the use of en-US if ($this->locale_code != $default_locale) { $this->locale_code = $default_locale; $this->_redirect("/" . $this->_request->getModuleName() . "/" . $this->_request->getControllerName() . "/" . $this->_request->getActionName() . "/"); } $locales_table = new Locales(); $tmp_regions = $locales_table->getDistinctRegions(); $choices = array(); foreach ($tmp_regions as $tmp_region) { if ($tmp_region['region_name'] == 'Global') { continue; } $tmp_countries = $locales_table->getDistinctCountries($tmp_region['region_name']); $tmp_pseudo_countries = $locales_table->getDistinctPseudoCountryCodes($tmp_region['region_name']); foreach ($tmp_countries as $tmp_country) { if (!empty($tmp_pseudo_countries) && in_array($tmp_country['country_code'], $tmp_pseudo_countries[0])) { continue; } $tmp_lang = $locales_table->getLanguages($tmp_region['region_name'], $tmp_country['country_code']); $tmp_country['languages'] = array(); foreach ($tmp_lang as $lan) { if (!is_null($lan['pseudo_country_code'])) { $tmp_locale_code = strtolower($lan['language_code'] . "-" . $lan['pseudo_country_code']); } else { $tmp_locale_code = strtolower($lan['language_code'] . "-" . $tmp_country['country_code']); } if (in_array($tmp_locale_code, $this->live_locales)) { $tmp_country['languages'][] = $lan; } } if (count($tmp_country['languages']) > 0) { $tmp_region['countries'][] = $tmp_country; } } if (array_key_exists('countries', $tmp_region) && count($tmp_region['countries']) > 0) { $choices[] = $tmp_region; } } $this->view->choices = $choices; if ($request->has('inline')) { $this->view->inline = $request->inline; } }