protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $language = $input->getArgument('language'); $tableHeader = [$this->trans('commands.locale.translation.status.messages.project'), $this->trans('commands.locale.translation.status.messages.version'), $this->trans('commands.locale.translation.status.messages.local-age'), $this->trans('commands.locale.translation.status.messages.remote-age'), $this->trans('commands.locale.translation.status.messages.info')]; $languages = locale_translatable_language_list(); $status = locale_translation_get_status(); $this->getModuleHandler()->loadInclude('locale', 'compare.inc'); if (!$languages) { $io->info($this->trans('commands.locale.translation.status.messages.no-languages')); return; } elseif (empty($status)) { $io->info($this->trans('commands.locale.translation.status.messages.no-translations')); return; } if ($languages) { $projectsStatus = $this->projectsStatus(); foreach ($projectsStatus as $langcode => $rows) { $tableRows = []; if ($language != '' && !($language == $langcode || strtolower($language) == strtolower($languages[$langcode]->getName()))) { continue; } $io->info($languages[$langcode]->getName()); foreach ($rows as $row) { if ($row[0] == 'drupal') { $row[0] = $this->trans('commands.common.messages.drupal-core'); } $tableRows[] = $row; } $io->table($tableHeader, $tableRows, 'compact'); } } }
protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $moduleHandler = $this->moduleHandler; $moduleHandler->loadInclude('locale', 'inc', 'locale.translation'); $moduleHandler->loadInclude('locale', 'module'); $language = $input->getArgument('language'); $languagesObjects = locale_translatable_language_list(); $languages = $this->site->getStandardLanguages(); if (isset($languagesObjects[$language])) { $languageEntity = $languagesObjects[$language]; } elseif (array_search($language, $languages)) { $langcode = array_search($language, $languages); $languageEntity = $languagesObjects[$langcode]; } else { $io->error(sprintf($this->trans('commands.locale.language.delete.messages.invalid-language'), $language)); return 1; } try { $configurable_language_storage = $this->entityTypeManager->getStorage('configurable_language'); $configurable_language_storage->load($languageEntity->getId())->delete(); $io->info(sprintf($this->trans('commands.locale.language.delete.messages.language-deleted-successfully'), $languageEntity->getName())); } catch (\Exception $e) { $io->error($e->getMessage()); return 1; } return 0; }
protected function execute(InputInterface $input, OutputInterface $output) { $messageHelper = $this->getMessageHelper(); $moduleHandler = $this->getModuleHandler(); $moduleHandler->loadInclude('locale', 'inc', 'locale.translation'); $moduleHandler->loadInclude('locale', 'module'); $language = $input->getArgument('language'); $languagesObjects = locale_translatable_language_list(); $languages = $this->getLanguages(); if (isset($languages[$language])) { $languageEntity = $languages[$language]; } elseif (array_search($language, $languages)) { $langcode = array_search($language, $languages); $languageEntity = $languagesObjects[$langcode]; } else { $messageHelper->addErrorMessage(sprintf($this->trans('commands.locale.language.delete.messages.invalid-language'), $language)); return; } try { $configurable_language_storage = $this->getEntityManager()->getStorage('configurable_language'); $language = $configurable_language_storage->load($languageEntity->getId())->delete(); $messageHelper->addinfoMessage(sprintf($this->trans('commands.locale.language.delete.messages.language-deleted-sucessfully'), $languageEntity->getName())); } catch (\Exception $e) { $messageHelper->addErrorMessage($e->getMessage()); } }
protected function displayUpdates($language_filter, $output, $table) { $table->setHeaders([$this->trans('commands.locale.translation.status.messages.project'), $this->trans('commands.locale.translation.status.messages.version'), $this->trans('commands.locale.translation.status.messages.local-age'), $this->trans('commands.locale.translation.status.messages.remote-age'), $this->trans('commands.locale.translation.status.messages.info')]); $languages = locale_translatable_language_list(); $status = locale_translation_get_status(); $this->getModuleHandler()->loadInclude('locale', 'compare.inc'); if (!$languages) { $output->writeln('[+] <info>' . $this->trans('commands.locale.translation.status.messages.no-languages') . '</info>'); return; } elseif (empty($status)) { $output->writeln('[+] <info>' . $this->trans('commands.locale.translation.status.messages.no-translations') . '</info>'); return; } if ($languages) { $table->setStyle('compact'); $projectsStatus = $this->projectsStatus(); foreach ($projectsStatus as $langcode => $rows) { $table->setRows(array()); if ($language_filter != '' && !($language_filter == $langcode || strtolower($language_filter) == strtolower($languages[$langcode]->getName()))) { continue; } $output->writeln('[+] <info>' . $languages[$langcode]->getName() . '</info>'); foreach ($rows as $row) { if ($row[0] == 'drupal') { $row[0] = $this->trans('commands.common.messages.drupal-core'); } $table->addRow($row); } $table->render(); } } }
/** * Form builder for displaying the current translation status. * * @ingroup forms */ public function buildForm(array $form, FormStateInterface $form_state) { $languages = locale_translatable_language_list(); $status = locale_translation_get_status(); $options = array(); $languages_update = array(); $languages_not_found = array(); $projects_update = array(); // Prepare information about projects which have available translation // updates. if ($languages && $status) { $updates = $this->prepareUpdateData($status); // Build data options for the select table. foreach ($updates as $langcode => $update) { $title = String::checkPlain($languages[$langcode]->getName()); $locale_translation_update_info = array('#theme' => 'locale_translation_update_info'); foreach (array('updates', 'not_found') as $update_status) { if (isset($update[$update_status])) { $locale_translation_update_info['#' . $update_status] = $update[$update_status]; } } $options[$langcode] = array('title' => array('class' => array('label'), 'data' => array('#title' => $title, '#markup' => $title)), 'status' => array('class' => array('description', 'expand', 'priority-low'), 'data' => drupal_render($locale_translation_update_info))); if (!empty($update['not_found'])) { $languages_not_found[$langcode] = $langcode; } if (!empty($update['updates'])) { $languages_update[$langcode] = $langcode; } } // Sort the table data on language name. uasort($options, function ($a, $b) { return strcasecmp($a['title']['data']['#title'], $b['title']['data']['#title']); }); $languages_not_found = array_diff($languages_not_found, $languages_update); } $last_checked = $this->state->get('locale.translation_last_checked'); $form['last_checked'] = array('#theme' => 'locale_translation_last_check', '#last' => $last_checked); $header = array('title' => array('data' => $this->t('Language'), 'class' => array('title')), 'status' => array('data' => $this->t('Status'), 'class' => array('status', 'priority-low'))); if (!$languages) { $empty = $this->t('No translatable languages available. <a href="@add_language">Add a language</a> first.', array('@add_language' => $this->url('language.admin_overview'))); } elseif ($status) { $empty = $this->t('All translations up to date.'); } else { $empty = $this->t('No translation status available. <a href="@check">Check manually</a>.', array('@check' => $this->url('locale.check_translation'))); } // The projects which require an update. Used by the _submit callback. $form['projects_update'] = array('#type' => 'value', '#value' => $projects_update); $form['langcodes'] = array('#type' => 'tableselect', '#header' => $header, '#options' => $options, '#default_value' => $languages_update, '#empty' => $empty, '#js_select' => TRUE, '#multiple' => TRUE, '#required' => TRUE, '#not_found' => $languages_not_found, '#after_build' => array('locale_translation_language_table')); $form['#attached']['library'][] = 'locale/drupal.locale.admin'; $form['#attached']['css'] = array(drupal_get_path('module', 'locale') . '/css/locale.admin.css'); $form['actions'] = array('#type' => 'actions'); if ($languages_update) { $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Update translations')); } return $form; }
protected function displayUpdates($language_filter, $output, $table) { $table->setHeaders([$this->trans('commands.locale.translation.status.messages.project'), $this->trans('commands.locale.translation.status.messages.version'), $this->trans('commands.locale.translation.status.messages.local-age'), $this->trans('commands.locale.translation.status.messages.remote-age'), $this->trans('commands.locale.translation.status.messages.info')]); $languages = locale_translatable_language_list(); $status = locale_translation_get_status(); $this->getModuleHandler()->loadInclude('locale', 'compare.inc'); $project_data = locale_translation_build_projects(); if (!$languages) { $output->writeln('[+] <info>' . $this->trans('commands.locale.translation.status.messages.no-languages') . '</info>'); return; } elseif (empty($status)) { $output->writeln('[+] <info>' . $this->trans('commands.locale.translation.status.messages.no-translations') . '</info>'); return; } if ($languages && $status) { $table->setlayout($table::LAYOUT_COMPACT); $status_report = []; foreach ($status as $project_id => $project) { foreach ($project as $langcode => $project_info) { $info = $this->createInfoString($project_info); if ($project_info->type == LOCALE_TRANSLATION_LOCAL || $project_info->type == LOCALE_TRANSLATION_REMOTE) { $local = isset($project_info->files[LOCALE_TRANSLATION_LOCAL]) ? $project_info->files[LOCALE_TRANSLATION_LOCAL] : null; $remote = isset($project_info->files[LOCALE_TRANSLATION_REMOTE]) ? $project_info->files[LOCALE_TRANSLATION_REMOTE] : null; // Remove info because type was found $info = ''; } $local_age = $local->timestamp ? \Drupal::service('date.formatter')->formatTimeDiffSince($local->timestamp) : ''; $remote_age = $remote->timestamp ? \Drupal::service('date.formatter')->formatTimeDiffSince($remote->timestamp) : ''; $project_name = $project_info->name == 'drupal' ? $this->trans('commands.common.messages.drupal-core') : $project_data[$project_info->name]->info['name']; $status_report[$langcode][] = [$project_name, $project_info->version, $local_age, $remote_age, $info]; } } print $language_filter; foreach ($status_report as $langcode => $rows) { if ($language_filter != '' and !($language_filter == $langcode || strtolower($language_filter) == strtolower($languages[$langcode]->getName()))) { continue; } $output->writeln('[+] <info>' . $languages[$langcode]->getName() . '</info>'); foreach ($rows as $row) { $table->addRow($row); } } } $table->render($output); }
/** * Updates translation associated to a specific locale source. * * @param string $lid * The Locale ID. * @param string $target_language * Target language to update translation. * @param string $translation * Translation value. * * @return bool * Success or not updating the locale translation. */ protected function updateTranslation($lid, $target_language, $translation) { $languages = locale_translatable_language_list('name', TRUE); if (!$lid || !array_key_exists($target_language, $languages) || !$translation) { return FALSE; } $exists = db_query("SELECT COUNT(lid) FROM {locales_target} WHERE lid = :lid AND language = :language", array(':lid' => $lid, ':language' => $target_language))->fetchField(); // @todo Only singular strings are managed here, we should take care of // plural information of processed string. if (!$exists) { $fields = array('lid' => $lid, 'language' => $target_language, 'translation' => $translation, 'customized' => LOCALE_CUSTOMIZED); db_insert('locales_target')->fields($fields)->execute(); } else { $fields = array('translation' => $translation, 'customized' => LOCALE_CUSTOMIZED); db_update('locales_target')->fields($fields)->condition('lid', $lid)->condition('language', $target_language)->execute(); } // Clear locale caches. _locale_invalidate_js($target_language); \Drupal::cache()->delete('locale:' . $target_language); return TRUE; }