public function appendPreferences($context) { Administration::instance()->Page->addScriptToHead(URL . '/symphony/assets/jquery.js', 9200000); Administration::instance()->Page->addScriptToHead(URL . '/extensions/gettext/assets/gettext.js', 9300000); $group = new XMLElement('fieldset', null, array('class' => 'settings')); $group->appendChild(new XMLElement('legend', 'Gettext')); $div = new XMLElement('div'); // PARSER $label = Widget::Label('Parser'); $options = array(); $options[] = array(gettext::PARSER_TYPE_PO, gettext::getParserType() == gettext::PARSER_TYPE_PO, __('GNU Gettext (PO) ')); $options[] = array(gettext::PARSER_TYPE_I18N, gettext::getParserType() == gettext::PARSER_TYPE_I18N, __('i18n Properties')); $label->appendChild(Widget::Select('settings[gettext][parser]', $options, array('id' => 'gettext_parser'))); $div->appendChild($label); $group->appendChild($div); // OPTIONS $container = Widget::Label('Options', null, null, 'gettext_options', gettext::getParserType() == gettext::PARSER_TYPE_PO ? array('style' => 'display:none') : null); $div = new XMLElement('div'); $label = Widget::Label(); $input = Widget::Input('settings[gettext][params]', 'true', 'checkbox'); if (gettext::addParameters()) { $input->setAttribute('checked', 'checked'); } $label->setValue($input->generate() . ' ' . __('Add resources to parameter pool')); $div->appendChild($label); $label = Widget::Label(); $input = Widget::Input('settings[gettext][mergedefault]', 'true', 'checkbox'); if (gettext::addParameters()) { $input->setAttribute('checked', 'checked'); } $label->setValue($input->generate() . ' ' . __('Use default values if localized key is not available')); $div->appendChild($label); $container->appendChild($div); $group->appendChild($container); // Append preferences $context['wrapper']->appendChild($group); }
public function grab(&$param_pool) { $result = new XMLElement($this->dsParamROOTELEMENT); $result->setAttribute('type', gettext::getParserType()); $parser = gettext::getParser(); $resources = $parser->parse(); if ($parser instanceof POParser) { foreach ($resources as $resource) { $resourceNode = new XMLElement('resource'); $resourceNode->setAttribute('regionCode', $resource['rc']); $resourceNode->setAttribute('languageCode', $resource['lc']); $resourceNode->setAttribute('countryCode', $resource['cc']); $content = $resource['content']; foreach ($content as $name => $context) { $contextNode = new XMLElement('context'); if ($name != '') { $contextNode->setAttribute('name', $name); } foreach ($context as $item) { $itemNode = new XMLElement('item'); $itemNode->appendChild(new XMLElement('msgid', $item['msgid'])); if (isset($item['msgid_plural'])) { $itemNode->appendChild(new XMLElement('msgid_plural', $item['msgid_plural'])); } if (is_array($item['msgstr'])) { for ($i = 0; $i < count($item['msgstr']); $i++) { $node = new XMLElement('msgstr', $item['msgstr'][$i]); $node->setAttribute('index', $i); $itemNode->appendChild($node); } } else { $itemNode->appendChild(new XMLElement('msgstr', $item['msgstr'])); } $contextNode->appendChild($itemNode); } $resourceNode->appendChild($contextNode); } $result->appendChild($resourceNode); } /* $localizedResources = $resources[$languagCode]; $content = $localizedResources['content']['']; foreach($content as $item) { $name = gettext::createValidParameterName($item['msgid']); $value = $item['msgstr']; $context["params"][$name] = $value; } */ } else { if ($parser instanceof i18nParser) { foreach ($resources as $resource) { $resourceNode = new XMLElement('resource'); $resourceNode->setAttribute('regionCode', $resource['rc']); $resourceNode->setAttribute('languageCode', $resource['lc']); $resourceNode->setAttribute('countryCode', $resource['cc']); $content = $resource['content']; foreach ($content as $name => $value) { if (empty($value)) { if (isset($resources['']['content'][$name])) { $value = $resources['']['content'][$name]; } $value = empty($value) ? $name : $value; } $itemNode = new XMLElement('item', $value); $itemNode->setAttribute('name', $name); $resourceNode->appendChild($itemNode); } $result->appendChild($resourceNode); } } } return $result; }