/** @inheritdoc */ public static function displayForm($value, &$settings, $model) { // No point in ever showing this field if lang isn't enabled if (!\CMF::$lang_enabled) { return ''; } \Lang::load('languages', true, 'en', true, true); $settings = static::settings($settings); $include_label = isset($settings['label']) ? $settings['label'] : true; $required = isset($settings['required']) ? $settings['required'] : false; $errors = $model->getErrorsForField($settings['mapping']['fieldName']); $has_errors = count($errors) > 0; $input_attributes = isset($settings['input_attributes']) ? $settings['input_attributes'] : array('class' => 'input-xxlarge'); if ($settings['active_only']) { $options = array_map(function ($lang) { return \Arr::get(\Lang::$lines, 'en.languages.' . $lang['code'], \Lang::get('admin.errors.language.name_not_found')); }, \CMF\Model\Language::select('item.code', 'item', 'item.code')->orderBy('item.pos', 'ASC')->where('item.visible = true')->getQuery()->getArrayResult()); } else { $options = \Arr::get(\Lang::$lines, 'en.languages', array()); } // Whether to allow an empty option if (isset($settings['mapping']['nullable']) && $settings['mapping']['nullable'] && !$required && $settings['allow_empty']) { $options = array('' => '') + $options; } $label = !$include_label ? '' : \Form::label($settings['title'] . ($required ? ' *' : '') . ($has_errors ? ' - ' . $errors[0] : ''), $settings['mapping']['fieldName'], array('class' => 'item-label')); $input = \Form::select($settings['mapping']['fieldName'], $value, $options, $input_attributes); if (isset($settings['wrap']) && $settings['wrap'] === false) { return $label . $input; } return html_tag('div', array('class' => 'controls control-group' . ($has_errors ? ' error' : '')), $label . $input); }
/** * Gets a list of the active languages that have been configured */ public static function languages() { if (static::$languages !== null) { return static::$languages; } $languages = \CMF\Model\Language::select('item.id, item.code, item.top_level_domain, update_from.code AS update_from_code', 'item', 'item.code')->leftJoin('item.update_from', 'update_from')->orderBy('item.pos', 'ASC')->getQuery(); // Set the query hint if multi lingual! if (\CMF\Doctrine\Extensions\Translatable::enabled()) { $languages->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker'); } return static::$languages = $languages->getArrayResult(); }
/** * Auto translate common terms */ public function onSaveTerms($file, $lang, $language) { // Try and find child languages $childLanguages = \CMF\Model\Language::select('item')->where('update_from IS NOT NULL')->andWhere('update_from.code = :code')->andWhere('item.visible = true')->leftJoin('item.update_from', 'update_from')->setParameter('code', $language)->getQuery()->getResult(); // Run if child languages are found if (!count($childLanguages)) { return; } foreach ($childLanguages as $childLanguage) { // Translate the terms for each language $terms = $this->translateArray($lang, $language, $childLanguage->code); if (is_array($terms)) { try { \Lang::save($file, $terms, $childLanguage->code); } catch (\Exception $e) { } } } }