static function FromCode($code) { $res = new ExcelCulture(); $ci = Localization::getCultureInfo($code); foreach (get_object_vars($ci) as $prop => $value) { $res->{$prop} = $value; } return $res; }
/** * Returns whether given value is a valid float value or not * * @param string $value floatnumber to be checked * @return bool true if valid */ function localized_to_float_number($value) { $ci = Localization::getCultureInfo(); $number = str_replace($ci->NumberFormat->GroupSeparator, "", $value); if ($ci->NumberFormat->DecimalSeparator != '.') { $number = str_replace($ci->NumberFormat->DecimalSeparator, ".", $number); } if (!is_float(floatval($number)) || !is_numeric($number)) { return false; } return $number; }
/** * @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)); } }
/** * @override */ function PreRender($args = array()) { if (!$this->CultureInfo) { $this->SetCulture(Localization::detectCulture()); } if (isset($this->value)) { $this->value = get_class_simple($this) == "uiDatePicker" ? $this->CultureInfo->FormatDate($this->value, DateTimeFormat::DF_SHORTDATE) : $this->CultureInfo->FormatDateTime($this->value); } if (isset($this->Options['defaultDate'])) { $this->Options['defaultDate'] = get_class_simple($this) == "uiDatePicker" ? $this->CultureInfo->FormatDate($this->Options['defaultDate'], DateTimeFormat::DF_SHORTDATE) : $this->CultureInfo->FormatDateTime($this->Options['defaultDate']); } parent::PreRender($args); }
/** * @override */ function PreRender($args = array()) { if (!$this->CultureInfo) { $this->SetCulture(Localization::detectCulture()); } if (isset($this->value)) { $this->value = get_class_simple($this) == "uiDatePicker" ? $this->CultureInfo->FormatDate($this->value, DateTimeFormat::DF_SHORTDATE) : $this->CultureInfo->FormatDateTime($this->value); } if (isset($this->Options['defaultDate'])) { $this->Options['defaultDate'] = get_class_simple($this) == "uiDatePicker" ? $this->CultureInfo->FormatDate($this->Options['defaultDate'], DateTimeFormat::DF_SHORTDATE) : $this->CultureInfo->FormatDateTime($this->Options['defaultDate']); } $this->script("\$('#{$this->id}').{$this->init_code}(" . system_to_json($this->Options) . ");"); parent::PreRender($args); }
private function _sample($json_dtf = false, $date_format = false, $time_format = false) { $value = time(); if ($json_dtf) { list($date_format, $time_format) = json_decode($json_dtf); } $ci = Localization::getCultureInfo($this->culture_code); if (!$ci) { return ""; } $ci->TimeZone = $this->timezone; $value = $ci->GetTimezoneDate($value); $dtf = $ci->DateTimeFormat; return $dtf->Format($value, $date_format) . " " . $dtf->Format($value, $time_format); }
/** * @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})"); } }
/** * Returns a list of option elements. * * Called via AJAX to dynamically update the control. * @attribute[RequestParam('language','string')] * @param string $language Language code * @return <AjaxResponse::Text> Html string with options */ public function ListOptions($language) { $lang = Localization::getLanguageCulture($language); if (!$lang) { $lang = Localization::getLanguageCulture('en'); } $regions = $lang->GetRegions(true); $sorted = array(); foreach ($regions as $code) { $sorted[$code] = array("name" => getString("TXT_COUNTRY_" . strtoupper($code)), "code", $code); } uasort($sorted, "RegionSelect::compareCountryNames"); $res = array(); foreach ($sorted as $code => $item) { $res[] = "<option value='{$code}'>{$item['name']}</option>"; } return implode("\n", $res); }
/** * Checks if this represents the language of another culture. * * Sample: 'en' is parent of 'en-US' * @param mixed $child Culture code or <CultureInfo> object * @return boolean true or false */ function IsParentOf($child) { if (is_string($child)) { $child = Localization::getCultureInfo($child); } if (!$child instanceof CultureInfo) { return false; } return $child->IsChildOf($this); }
/** * Prepare the variables for a credit note and generate the PDF then. * * @return void */ public function RenderCreditnote() { // prepare CI and language if (!$this->CI) { $this->CI = Localization::getCultureInfo("en-US"); } if (!$this->Language) { $this->Language = $this->CI->ResolveToLanguage(); } // prepare VAT information // rules for credit notes as defined in mantis #7982 $revchargecountries = array_merge($GLOBALS['VAT_COUNTRIES'], array("LI", "MC", "CH", "LU")); unset($revchargecountries["DE"]); // no revcharge hint for germany $rev_charge_hint = $this->VatCountryCode && in_array(strtoupper($this->VatCountryCode), $revchargecountries); $add_taxes = strtoupper($this->VatCountryCode) == "DE"; $this->RenderPDF($add_taxes, $rev_charge_hint); }
/** * @override */ function WdfRender() { if (!$this->get('isrtl') && system_is_module_loaded('localization')) { $ci = Localization::detectCulture(); if ($ci->IsRTL) { $this->set("isrtl", " dir='rtl'"); } } $res = $this->__collectResources(); $this->js = array_reverse($this->js, true); foreach (array_reverse($res) as $r) { if (starts_with(pathinfo($r, PATHINFO_EXTENSION), 'css')) { $this->addCss($r); } else { $this->addjs($r); } } $this->js = array_reverse($this->js, true); $this->set("css", $this->css); $this->set("js", $this->js); $this->set("meta", $this->meta); $this->set("content", $this->_content); return parent::WdfRender(); }
/** * Checks a given array for data for this and updates another array accordingly * * This is kind of internal, so will not be documented further. Only that it ensures typed data in the $args argument * from the $data argument. We will most likely clean this procedure up in the future. * @param array $data Combined request data * @param array $args resulting typed values * @return boolean|string true if everything went fine, an error string if not */ function UpdateArgs($data, &$args) { global $CONFIG; if ($CONFIG['requestparam']['ignore_case']) { $name = strtolower($this->Name); foreach ($data as $k => $v) { unset($data[$k]); $data[strtolower($k)] = $v; } } else { $name = $this->Name; } if (isset($GLOBALS['routing_args']) && count($GLOBALS['routing_args']) > 0 && !isset($data[$name])) { $data[$name] = array_shift($GLOBALS['routing_args']); } if (!isset($data[$name])) { if (!is_null($this->Default)) { $args[$this->Name] = $this->Default; return true; } $args[$this->Name] = null; return 'missing'; } if (!isset($GLOBALS['request_param_detected_ci'])) { if (isset($CONFIG['requestparam']['ci_detection_func']) && function_exists($CONFIG['requestparam']['ci_detection_func'])) { $GLOBALS['request_param_detected_ci'] = $CONFIG['requestparam']['ci_detection_func'](); } else { $GLOBALS['request_param_detected_ci'] = Localization::detectCulture(); } } $ci = $GLOBALS['request_param_detected_ci']; if (!is_null($this->Type)) { switch (strtolower($this->Type)) { case 'object': if (!in_object_storage($data[$name])) { return 'object not found'; } $args[$this->Name] = restore_object($data[$name]); return true; case 'array': case 'file': if (isset($data[$name]) && is_array($data[$name])) { $args[$this->Name] = $data[$name]; } return true; case 'string': case 'text': if ($this->Filter) { $args[$this->Name] = filter_var($data[$name], $this->Filter, FILTER_FLAG_NO_ENCODE_QUOTES); } else { $args[$this->Name] = $data[$name]; } return true; case 'email': $args[$this->Name] = filter_var($data[$name], FILTER_SANITIZE_EMAIL); return true; case 'url': case 'uri': $args[$this->Name] = filter_var($data[$name], FILTER_SANITIZE_URL); return true; case 'int': case 'integer': if (intval($data[$name]) . "" != $data[$name]) { // if( floatval($data[$name])."" != $data[$name] ) return 'invalid int value'; } $args[$this->Name] = intval($data[$name]); return true; case 'float': case 'double': case 'currency': if ($data[$name] . "" == "" && $this->IsOptional()) { $data[$name] = $this->Default; $args[$this->Name] = $this->Default; return true; } // if( isset($CONFIG['localization']['float_conversion']) ) // $data[$name] = call_user_func($CONFIG['localization']['float_conversion'],$data[$name]); // else if( !is_float(floatval($data[$name])) ) // $data[$name] = false; if (strtolower($this->Type) == 'currency') { $data[$name] = $ci->CurrencyFormat->StrToCurrencyValue($data[$name]); } else { $data[$name] = $ci->NumberFormat->StrToNumber($data[$name]); } if ($data[$name] === false) { return 'invalid float value'; } else { $args[$this->Name] = $data[$name]; } return true; case 'bool': case 'boolean': if ($data[$name] == '' || $data[$name] == '0' || strtolower($data[$name]) == "false") { $args[$this->Name] = false; } else { $args[$this->Name] = true; } return true; } return 'wrong type'; } $args[$this->Name] = $data[$name]; return true; }
/** * Returns a list of option elements. * * Called via AJAX to dynamically update the control. * @attribute[RequestParam('culture_code','string')] * @param string $culture_code Selected culture code * @return <AjaxResponse::Text> Html string with options */ public function ListOptions($culture_code) { $this->culture_code = $culture_code; $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 (!$ci) { $ci = Localization::getCultureInfo('en-US'); } $dtf = $ci->DateTimeFormat; foreach ($df as $d) { foreach ($tf as $t) { $sv = $dtf->Format($value, $d) . " " . $dtf->Format($value, $t); $res[] = "<option value='" . json_encode(array($d, $t)) . "'>{$sv}</option>"; } } return AjaxResponse::Text(implode("\n", $res)); }
private function SanitizeLocale($order) { $locale = $order->GetLocale(); if (!$locale) { return false; } if (is_string($locale)) { if ($tmp = Localization::getCultureInfo($locale)) { $locale = $tmp; } } if ($locale instanceof CultureInfo) { if (!$locale->IsNeutral()) { $locale = $locale->ResolveToLanguage(); } $locale = $locale->Iso2; } $locale = strtolower($locale); switch ($locale) { case 'en': return 'en_US'; case 'it': return 'it_IT'; case 'es': return 'es_ES'; case 'fr': return 'fr_FR'; case 'iw': return 'iw_IL'; case 'de': return 'de_DE'; case 'ar': return 'ar_AA'; case 'ru': return 'ru_RU'; case 'nl': return 'nl_NL'; case 'bg': return 'bg_BG'; case 'ja': return 'ja_JP'; case 'tr': return 'tr_TR'; case 'pt': return 'pt_BR'; case 'zh': return 'zh_CN'; case 'lt': return 'lt_LT'; case 'sv': return 'sv_SE'; case 'sl': return 'sl_SL'; case 'da': return 'da_DK'; case 'pl': return 'pl_PL'; } log_warn("Gate2Shop: Invalid locale '{$locale}'. Skipping argument"); return false; }
/** * Adds data to the automatic translation system. * * Use this to add a bunch of data to the translation system. * Sample is best to understand: * <code php> * function SomeControllersInitMethod() * { * $str_const = default_string('TXT_TEST','Hello {user.name}! I want to tell you all about {product.name}. Is {user.email} your email address?'); * add_trans_data('user',UserModel::Make()->eq('id',1)->current()); * add_trans_data('product',ProductModel::Make()->eq('id',1)->current()); * $this->content($str_content); * } * </code> * @param string $name Name of the data * @param mixed $data The data do add. Can be int, bool string, object, array, ... * @param int $depth Current recursion depth. Ignore this, it's internal only. * @return void */ function add_trans_data($name, $data, $depth = 0) { if ($data instanceof \ScavixWDF\Model\DataSource) { return; } if ($data instanceof \ScavixWDF\WdfException) { return; } if ($data instanceof \ScavixWDF\Base\Renderable) { return; } // todo: more class-based exceptions if ($depth > 1) { return; } $name = str_replace(array('{', '}'), array('', ''), $name); if ($data instanceof Model) { $data = $data->AsArray(); } if ($data instanceof DateTime) { if (!isset($GLOBALS['current_language'])) { detect_language(); } $ci = Localization::getCultureInfo($GLOBALS['current_language']); $GLOBALS['translation']['data'][$name . "_asdate"] = $ci->FormatDate($data); $data = $ci->FormatDateTime($data); } if (is_object($data)) { $data = (array) $data; } if (is_array($data)) { foreach ($data as $k => $v) { add_trans_data("{" . $name . "." . $k . "}", $v, $depth + 1); } return; } $GLOBALS['translation']['data'][$name] = $data; }
/** * @internal Fetch action handler * @attribute[RequestParam('languages','array',false)] */ function Fetch($languages = false) { global $CONFIG; $this->_contentdiv->content("<h1>Fetch strings</h1>"); $db_languages = $this->ds->ExecuteSql("SELECT DISTINCT lang FROM wdf_translations ORDER BY lang")->Enumerate('lang', false); $max = $this->ds->ExecuteScalar("SELECT MAX(cnt) FROM (SELECT count(*) as cnt FROM wdf_translations GROUP BY lang) AS x"); foreach ($db_languages as $i => $lang) { $count = $this->ds->ExecuteScalar("SELECT count(*) FROM wdf_translations WHERE lang=?", $lang); $db_languages[$i] = new stdClass(); $db_languages[$i]->name = Localization::getCultureInfo($lang)->EnglishName; $db_languages[$i]->code = $lang; $db_languages[$i]->percentage = round($count / $max * 100, 0); } if (!$languages) { $div = $this->_contentdiv->content(new Form()); foreach ($db_languages as $lang) { $cb = $div->content(new CheckBox('languages[]')); $cb->value = $lang->code; $div->content($cb->CreateLabel($lang->name . " ({$lang->code}, {$lang->percentage}% complete)")); $div->content("<br/>"); } $a = $div->content(new Anchor('#', 'Select all')); $a->script("\$('#{$a->id}').click(function(){ \$('input','#{$div->id}').attr('checked',true); });"); $div->content(" "); $div->AddSubmit("Fetch"); return; } $head = array(); foreach ($db_languages as $lang) { $head[$lang->code] = array('percentage_complete' => $lang->percentage / 100, 'percentage_empty' => 1 - $lang->percentage / 100, 'syntax_error_qty' => 0); } $info = "\$GLOBALS['translation']['properties'] = " . var_export($head, true); $defaults = $this->fetchTerms($CONFIG['localization']['default_language']); foreach (array_unique($languages) as $lang) { $lang = strtolower($lang); $data = $lang == $CONFIG['localization']['default_language'] ? $defaults : $this->fetchTerms($lang, $defaults); $strings = "\$GLOBALS['translation']['strings'] = " . var_export($data, true); file_put_contents($CONFIG['translation']['data_path'] . $lang . '.inc.php', "<?php\n{$info};\n{$strings};\n"); $this->_contentdiv->content("<div>Created translation file for {$lang}</div>"); } $ds = model_datasource($GLOBALS['CONFIG']['translation']['sync']['datasource']); $ds->ExecuteSql("TRUNCATE TABLE wdf_unknown_strings"); $this->_contentdiv->content("<div>Cleared the unknown strings table</div>"); foreach (cache_list_keys() as $key) { if (starts_with($key, 'lang_')) { cache_del($key); } } $this->_contentdiv->content("<div>Cleared the string cache</div>"); }
function ParticipantsCountries() { $chart = new gvGeoChart(); $chart->setTitle("Participants countries")->setDataHeader("Country", "Participants")->setSize(800, 400)->opt('is3D', true); $country_names = Localization::get_country_names(); foreach (model_datasource('system')->ExecuteSql("SELECT country, count(*) as cnt FROM participants GROUP BY country ORDER BY cnt DESC") as $row) { $chart->addDataRow($country_names[$row['country']], intval($row['cnt'])); } return $chart; }