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; }
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); }
/** * @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>"); }
/** * 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; }
/** * 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); }
/** * 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; }