/** * Parse a json containing the lookup table. * * @return void */ private function _fromJSON() { $uri = $this->_config->get('paths/lookup'); try { $fileContent = $this->_vfs->file_get_contents($uri); $temp = json_decode($fileContent, true); self::$lookup = $temp['lookupTable']; } catch (Exception $e) { throw new KiTT_Exception($e->getMessage(), $e->getCode()); } }
/** * Get all possible viable candidates based on a currency and language * * @param string $currency iso-4217 currency code * @param string $language iso-639-1 language code * * @return array containing possible candidates */ private function _getCandidates($currency, $language) { $candidates = $this->_lookup->getCountries($currency); // If there is only one country for this currency we ignore language // and just check to see if that country is a sales country. if (count($candidates) === 1) { $country = array_keys($candidates); if (!$this->_isSalesCountry($country[0])) { return array(); } return $country; } // Collect sales countries that support the given language $collector = array(); foreach ($candidates as $country => $languages) { if (!$this->_isSalesCountry($country)) { continue; } if (in_array($language, $languages)) { $collector[] = $country; } } return $collector; }
/** * Get the available languages for the locale and make sure that English * and the current language is included. * * @return string */ public function languages() { $languages = $this->lookup->getAllLanguages($this->country); $avail = array_merge(array('en', $this->language), $languages !== null ? $languages : array()); return json_encode(array_values(array_unique($avail))); }