Пример #1
0
 private function _languageSelect($lang)
 {
     global $CONFIG;
     $sel = new Select();
     $sel->SetCurrentValue($lang);
     $known = $sel->CreateGroup('Languages with translations');
     $avail = $sel->CreateGroup('Available languages');
     $counts = array();
     foreach ($this->ds->ExecuteSql("SELECT lang,count(*) as cnt FROM wdf_translations GROUP BY lang") as $row) {
         $counts[$row['lang']] = intval($row['cnt']);
     }
     $total = max($counts);
     foreach (Localization::get_language_names() as $code => $name) {
         if (isset($counts[$code])) {
             $name = "{$name} ({$counts[$code]})";
             if ($code == $CONFIG['localization']['default_language']) {
                 $name .= " [default]";
             } else {
                 $name .= " [" . floor($counts[$code] / $total * 100) . "%]";
             }
         }
         $sel->AddOption($code, $name, false, isset($counts[$code]) && $counts[$code] > 0 ? $known : $avail);
     }
     return $sel;
 }
 /**
  * @param string $culture_code Culture code (see <CultureInfo>)
  * @param mixed $selected_date_format The currently selected date format or false
  * @param mixed $selected_time_format The currently selected time format or false
  * @param string $timezone Timezone identifier or false
  */
 function __initialize($culture_code, $selected_date_format = false, $selected_time_format = false, $timezone = false)
 {
     parent::__initialize();
     $this->script("Locale_Settings_Init();");
     $this->setData('role', 'datetimeformat');
     $this->setData('controller', buildQuery($this->id));
     $this->culture_code = $culture_code;
     if ($selected_date_format || $selected_time_format) {
         $this->SetCurrentValue(json_encode(array($selected_date_format ? $selected_date_format : false, $selected_time_format ? $selected_time_format : false)));
     }
     $df = array(DateTimeFormat::DF_LONGDATE, DateTimeFormat::DF_SHORTDATE, DateTimeFormat::DF_MONTHDAY, DateTimeFormat::DF_YEARMONTH);
     $tf = array(DateTimeFormat::DF_LONGTIME, DateTimeFormat::DF_SHORTTIME);
     $value = time();
     $ci = Localization::getCultureInfo($culture_code);
     if ($timezone) {
         $ci->SetTimezone($timezone);
         $value = $ci->GetTimezoneDate($value);
     }
     $dtf = $ci->DateTimeFormat;
     foreach ($df as $d) {
         foreach ($tf as $t) {
             $sv = $dtf->Format($value, $d) . " " . $dtf->Format($value, $t);
             $this->AddOption(json_encode(array($d, $t)), $sv);
         }
     }
 }
 /**
  * @param string $current_timezone Currently selected timezone
  */
 function __initialize($current_timezone = false)
 {
     parent::__initialize();
     $this->script("Locale_Settings_Init();");
     $this->setData('role', 'timezone');
     if (!$current_timezone) {
         $current_timezone = Localization::getTimeZone();
     }
     $this->SetCurrentValue($current_timezone);
     foreach (Localization::GetAllTimeZones() as $tz) {
         $this->AddOption($tz, str_replace("_", " ", $tz));
     }
 }
 /**
  * @param string $currency_code A valid currency code
  * @param mixed $selected_format The currently selected format
  */
 function __initialize($currency_code, $selected_format = false)
 {
     parent::__initialize();
     $this->script("Locale_Settings_Init();");
     $this->setData('role', 'currenyformat');
     $this->setData('controller', buildQuery($this->id));
     if ($selected_format) {
         $this->SetCurrentValue($selected_format);
     }
     $samples = $this->getCurrencySamples($currency_code, 1234.56, true);
     foreach ($samples as $code => $label) {
         $this->AddOption($code, $label);
     }
 }
Пример #5
0
 /**
  * @param mixed $current_language_code Currently selected language
  * @param type $current_region_code Currently selected region
  */
 function __initialize($current_language_code = false, $current_region_code = false)
 {
     parent::__initialize();
     $this->script("Locale_Settings_Init();");
     $this->setData('role', 'region');
     $this->setData('controller', buildQuery($this->id));
     if ($current_language_code) {
         if ($current_language_code instanceof CultureInfo) {
             $lang = $current_language_code->ResolveToLanguage();
         } else {
             $lang = Localization::getLanguageCulture($current_language_code);
         }
         if (!$lang) {
             $lang = Localization::detectCulture()->ResolveToLanguage();
         }
         $regions = $lang->GetRegions(false);
         if (!$current_region_code) {
             $current_region_code = $lang->DefaultRegion()->Code;
         }
     } else {
         $regions = Localization::get_all_regions(false);
     }
     if ($current_region_code) {
         if ($current_region_code instanceof CultureInfo) {
             $this->SetCurrentValue($current_region_code->DefaultRegion()->Code);
         } else {
             $this->SetCurrentValue($current_region_code);
         }
     }
     if (count($regions) > 0) {
         $cc = current_controller(false);
         $translations_active = $cc instanceof Renderable && $cc->_translate;
         $sorted = array();
         foreach ($regions as $reg) {
             if (!$reg) {
                 continue;
             }
             $code = $reg->Code;
             if ($translations_active) {
                 $sorted[$code] = array("name" => tds("TXT_COUNTRY_" . strtoupper($code), $reg->EnglishName), "code", $code);
             } else {
                 $sorted[$code] = array("name" => $reg->EnglishName, "code", $code);
             }
         }
         uasort($sorted, __CLASS__ . "::compareCountryNames");
         foreach ($sorted as $code => $item) {
             $this->AddOption($code, $item['name']);
         }
     }
 }
 /**
  * @param string $current_currency_code Currently selected currency
  * @param array $supported_currencies Array of supported currencies or false
  */
 function __initialize($current_currency_code = false, $supported_currencies = false)
 {
     parent::__initialize();
     $this->script("Locale_Settings_Init();");
     $this->setData('role', 'currency');
     $this->current_currency_code = $current_currency_code;
     if ($current_currency_code) {
         $this->SetCurrentValue($current_currency_code);
     }
     if (!$supported_currencies) {
         $supported_currencies = Localization::get_currency_codes();
     }
     foreach ($supported_currencies as $code) {
         $ci = Localization::get_currency_culture($code);
         $this->AddOption($code, "{$ci->CurrencyFormat->Code} ({$ci->CurrencyFormat->Symbol})");
     }
 }
 /**
  * @param mixed $current_language_code Currently selected language
  */
 function __initialize($current_language_code = false)
 {
     parent::__initialize();
     $this->script("Locale_Settings_Init();");
     $this->setData('role', 'language');
     if ($current_language_code) {
         if ($current_language_code instanceof CultureInfo) {
             $lang = $current_language_code->ResolveToLanguage();
         } else {
             $lang = Localization::getLanguageCulture($current_language_code);
         }
         if (!$lang) {
             $lang = Localization::detectCulture()->ResolveToLanguage();
         }
         $this->SetCurrentValue($lang->Code);
     }
     foreach (getAvailableLanguages() as $code) {
         $lang = Localization::getLanguageCulture($code);
         $this->AddOption($code, "{$lang->NativeName} ({$lang->EnglishName})");
     }
 }
Пример #8
0
 private function CreateSelect($sel_name)
 {
     $Select = new Select($sel_name);
     foreach ($this->_scale as $val => $desc) {
         $selected = $val == $this->_value ? true : false;
         $Select->AddOption($val, $desc, $selected);
     }
     return $Select;
 }