Loading l10n_community/l10n_community.routing.yml +24 −0 Original line number Diff line number Diff line Loading @@ -80,3 +80,27 @@ l10n_community.language.translate.reset: type: entity:l10n_server_project release: type: entity:l10n_server_release l10n_community.translation_details: path: '/translate/translation-details/{translation}' defaults: _title: 'Translation history information' _controller: '\Drupal\l10n_community\Controller\L10nCommunityLanguagesController::translationDetails' requirements: _permission: 'browse translations' options: parameters: translation: type: entity:l10n_server_translation l10n_community.source_details: path: '/translate/source-details/{string}' defaults: _title: 'Source string usage details' _controller: '\Drupal\l10n_community\Controller\L10nCommunityLanguagesController::sourceDetails' requirements: _permission: 'browse translations' options: parameters: translation: type: entity:l10n_server_string l10n_community/src/Controller/L10nCommunityLanguagesController.php +52 −10 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\l10n_community\Controller; Loading @@ -14,6 +15,8 @@ use Drupal\group\Entity\Group; use Drupal\l10n_server\Entity\L10nServerProject; use Drupal\l10n_server\Entity\L10nServerProjectInterface; use Drupal\l10n_server\Entity\L10nServerReleaseInterface; use Drupal\l10n_server\Entity\L10nServerStringInterface; use Drupal\l10n_server\Entity\L10nServerTranslationInterface; use Drupal\language\Entity\ConfigurableLanguage; use Symfony\Component\DependencyInjection\ContainerInterface; Loading Loading @@ -222,7 +225,7 @@ class L10nCommunityLanguagesController extends ControllerBase { ]; $strings = $translator->getStrings($langcode, $filters, $filters['limit']); // Add RTL style if the current language's direction is RTL // Add RTL style if the current language's direction is RTL. if ($language->getDirection() == LANGUAGE::DIRECTION_RTL) { $build['#attached']['library'][] = 'l10n_community/editor-rtl'; } Loading @@ -232,12 +235,12 @@ class L10nCommunityLanguagesController extends ControllerBase { $project = L10nServerProject::load($filters['project']); $build['#title'] = $this->t('Translate %project to @language', [ '%project' => $project->label(), '@language' => $this->t($language->getName()), '@language' => $language->getName(), ]); } else { $build['#title'] = $this->t('Translate to @language', [ '@language' => $this->t($language->getName()), '@language' => $language->getName(), ]); } Loading @@ -249,15 +252,11 @@ class L10nCommunityLanguagesController extends ControllerBase { \Drupal::messenger()->addError($this->t('No strings found with this filter. Try adjusting the filter options.')); } else { //$build['filter'] = \Drupal::formBuilder()->getForm('Drupal\l10n_community\Form\TranslateForm'); //$output[] = drupal_get_form('l10n_community_translate_form', $language, $filters, $strings); $build['translate_form'] = \Drupal::formBuilder()->getForm('Drupal\l10n_community\Form\TranslateForm', $language, $filters); } $build['content'] = [ '#type' => 'item', '#markup' => __METHOD__ . '::' . $group->get('field_translation_language')->first()->getValue()['target_id'], ]; $build['#attached']['drupalSettings'] = $drupal_settings; return $build; } Loading @@ -265,6 +264,7 @@ class L10nCommunityLanguagesController extends ControllerBase { * Title callback. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup * Page title. */ public function translateTitle() { return $this->t('Translate'); Loading @@ -289,6 +289,7 @@ class L10nCommunityLanguagesController extends ControllerBase { * Title callback. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup * Page title. * * @throws \Drupal\Core\TypedData\Exception\MissingDataException */ Loading Loading @@ -320,6 +321,7 @@ class L10nCommunityLanguagesController extends ControllerBase { * Title callback. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup * Page title. */ public function exportTitle() { /** @var \Drupal\group\Entity\Group $group */ Loading Loading @@ -435,7 +437,9 @@ class L10nCommunityLanguagesController extends ControllerBase { } /** * Generate and add JS for URL replacements. These ensure we keep filter values. * Generate and add JS for URL replacements. * * These ensure we keep filter values. * * @param string $langcode * @param array $filters Loading Loading @@ -473,4 +477,42 @@ class L10nCommunityLanguagesController extends ControllerBase { return $filters; } /** * Provides full history information about translation. * * @param \Drupal\l10n_server\Entity\L10nServerTranslationInterface $translation * Translation entity. * @param bool $ajax * Whether the request came through AJAX, in which case no page theming * should be applied. Non-AJAX support is a fallback if JS is turned off. * * @return array * Translation details. */ public function translationDetails(L10nServerTranslationInterface $translation, bool $ajax) { // @see l10n_community_translation_detail() return [ '#markup' => 'L10nCommunityLanguagesController::translationDetails', ]; } /** * Generate list of projects and releases of where a string appears. * * @param \Drupal\l10n_server\Entity\L10nServerStringInterface $string * String entity. * @param bool $ajax * Whether the request came through AJAX, in which case no page theming * should be applied. Non-AJAX support is a fallback if JS is turned off. * * @return array * Source details. */ public function sourceDetails(L10nServerStringInterface $string, bool $ajax) { // @see l10n_community_string_details() return [ '#markup' => 'L10nCommunityLanguagesController::sourceDetails', ]; } } l10n_community/src/Form/TranslateForm.php 0 → 100644 +833 −0 File added.Preview size limit exceeded, changes collapsed. Show changes l10n_community/src/L10nTranslator.php +39 −6 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\l10n_community; Loading Loading @@ -36,6 +37,7 @@ class L10nTranslator { * @param string $langcode * Language code to use for the lookup. * @param array $filters * Filters, with following elements: * - 'project' * Project object to look up strings for. * - 'status' Loading @@ -57,7 +59,7 @@ class L10nTranslator { * @return array * An array of string records from database. */ function getStrings(string $langcode, array $filters, int $pager = NULL): array { public function getStrings(string $langcode, array $filters, int $pager = NULL): array { $query = $this->connection ->select('l10n_server_string', 's') ->distinct(); Loading @@ -83,7 +85,7 @@ class L10nTranslator { $query->condition('s.sid', $filters['sid']); } // Add submitted by condition // Add submitted by condition. if (!empty($filters['author'])) { $query->condition('t.uid', $filters['author']->id()); } Loading @@ -105,7 +107,8 @@ class L10nTranslator { // Context based filtering. if (isset($filters['context']) && $filters['context'] != 'all') { // We use 'none' for no context, so '' can be the defaut (for all contexts). // We use 'none' for no context, so '' can be the defaut (for all // contexts). $context = $filters['context'] == 'none' ? '' : $filters['context']; $query->condition('s.context', $context); } Loading Loading @@ -161,7 +164,8 @@ class L10nTranslator { $result = []; foreach ($strings as $string) { if ($string->suggestion) { // This string is not a translation, but we need that as a "parent" to display. // This string is not a translation, but we need that as a "parent" to // display. if (!$string->has_translation) { // No parent translation. Pretend this does not exist. // The display code will call for the suggestions. Loading @@ -184,7 +188,8 @@ class L10nTranslator { ->fetchAssoc(); if (!empty($translation)) { // It does have a translation however, so let's load it, and override. // It does have a translation however, so let's load it, and // override. foreach ($translation as $key => $value) { $string->$key = $value; } Loading @@ -196,4 +201,32 @@ class L10nTranslator { return $result; } /** * Get suggestions for a given string. * * @param string $langcode * Language code to use for the lookup. * @param int $sid * Source string ID. * * @return \Drupal\Core\Database\StatementInterface * String records from database. */ public function getSuggestions(string $langcode, int $sid): array { $query = $this->connection ->select('l10n_server_translation', 't'); $query->leftJoin('users_field_data', 'u', 'u.uid = t.uid'); $query->fields('t', [ 'tid', 'sid', 'translation', 'uid', 'created', 'changed', 'status', 'suggestion', ]); $query->addField('u', 'name', 'username'); $query->condition('t.language', $langcode); $query->condition('t.sid', $sid); $query->condition('t.status', 1); $query->condition('t.suggestion', 1); $query->orderBy('t.created'); return $query->execute(); } } l10n_server/l10n_server.module +47 −1 Original line number Diff line number Diff line <?php declare(strict_types=1); /** * @file * The localization server module. */ declare(strict_types=1); use Drupal\Core\Render\Element; use Drupal\views\Views; /** * Action flag for string addition. */ define('L10N_SERVER_ACTION_ADD', 1); /** * Action flag for approval. */ define('L10N_SERVER_ACTION_APPROVE', 2); /** * Action flag for denial. */ define('L10N_SERVER_ACTION_DECLINE', 3); /** * Action flag for demotes. */ define('L10N_SERVER_ACTION_DEMOTE', 4); /** * Action flag for re-additions. */ define('L10N_SERVER_ACTION_READD', 5); /** * Action medium flag for unknown sources. */ define('L10N_SERVER_MEDIUM_UNKNOWN', 0); /** * Action medium flag for web based actions. */ define('L10N_SERVER_MEDIUM_WEB', 1); /** * Action medium flag for web based import. */ define('L10N_SERVER_MEDIUM_IMPORT', 2); /** * Action medium flag for remote action. */ define('L10N_SERVER_MEDIUM_REMOTE', 3); /** * Implements hook_cron(). */ Loading Loading
l10n_community/l10n_community.routing.yml +24 −0 Original line number Diff line number Diff line Loading @@ -80,3 +80,27 @@ l10n_community.language.translate.reset: type: entity:l10n_server_project release: type: entity:l10n_server_release l10n_community.translation_details: path: '/translate/translation-details/{translation}' defaults: _title: 'Translation history information' _controller: '\Drupal\l10n_community\Controller\L10nCommunityLanguagesController::translationDetails' requirements: _permission: 'browse translations' options: parameters: translation: type: entity:l10n_server_translation l10n_community.source_details: path: '/translate/source-details/{string}' defaults: _title: 'Source string usage details' _controller: '\Drupal\l10n_community\Controller\L10nCommunityLanguagesController::sourceDetails' requirements: _permission: 'browse translations' options: parameters: translation: type: entity:l10n_server_string
l10n_community/src/Controller/L10nCommunityLanguagesController.php +52 −10 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\l10n_community\Controller; Loading @@ -14,6 +15,8 @@ use Drupal\group\Entity\Group; use Drupal\l10n_server\Entity\L10nServerProject; use Drupal\l10n_server\Entity\L10nServerProjectInterface; use Drupal\l10n_server\Entity\L10nServerReleaseInterface; use Drupal\l10n_server\Entity\L10nServerStringInterface; use Drupal\l10n_server\Entity\L10nServerTranslationInterface; use Drupal\language\Entity\ConfigurableLanguage; use Symfony\Component\DependencyInjection\ContainerInterface; Loading Loading @@ -222,7 +225,7 @@ class L10nCommunityLanguagesController extends ControllerBase { ]; $strings = $translator->getStrings($langcode, $filters, $filters['limit']); // Add RTL style if the current language's direction is RTL // Add RTL style if the current language's direction is RTL. if ($language->getDirection() == LANGUAGE::DIRECTION_RTL) { $build['#attached']['library'][] = 'l10n_community/editor-rtl'; } Loading @@ -232,12 +235,12 @@ class L10nCommunityLanguagesController extends ControllerBase { $project = L10nServerProject::load($filters['project']); $build['#title'] = $this->t('Translate %project to @language', [ '%project' => $project->label(), '@language' => $this->t($language->getName()), '@language' => $language->getName(), ]); } else { $build['#title'] = $this->t('Translate to @language', [ '@language' => $this->t($language->getName()), '@language' => $language->getName(), ]); } Loading @@ -249,15 +252,11 @@ class L10nCommunityLanguagesController extends ControllerBase { \Drupal::messenger()->addError($this->t('No strings found with this filter. Try adjusting the filter options.')); } else { //$build['filter'] = \Drupal::formBuilder()->getForm('Drupal\l10n_community\Form\TranslateForm'); //$output[] = drupal_get_form('l10n_community_translate_form', $language, $filters, $strings); $build['translate_form'] = \Drupal::formBuilder()->getForm('Drupal\l10n_community\Form\TranslateForm', $language, $filters); } $build['content'] = [ '#type' => 'item', '#markup' => __METHOD__ . '::' . $group->get('field_translation_language')->first()->getValue()['target_id'], ]; $build['#attached']['drupalSettings'] = $drupal_settings; return $build; } Loading @@ -265,6 +264,7 @@ class L10nCommunityLanguagesController extends ControllerBase { * Title callback. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup * Page title. */ public function translateTitle() { return $this->t('Translate'); Loading @@ -289,6 +289,7 @@ class L10nCommunityLanguagesController extends ControllerBase { * Title callback. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup * Page title. * * @throws \Drupal\Core\TypedData\Exception\MissingDataException */ Loading Loading @@ -320,6 +321,7 @@ class L10nCommunityLanguagesController extends ControllerBase { * Title callback. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup * Page title. */ public function exportTitle() { /** @var \Drupal\group\Entity\Group $group */ Loading Loading @@ -435,7 +437,9 @@ class L10nCommunityLanguagesController extends ControllerBase { } /** * Generate and add JS for URL replacements. These ensure we keep filter values. * Generate and add JS for URL replacements. * * These ensure we keep filter values. * * @param string $langcode * @param array $filters Loading Loading @@ -473,4 +477,42 @@ class L10nCommunityLanguagesController extends ControllerBase { return $filters; } /** * Provides full history information about translation. * * @param \Drupal\l10n_server\Entity\L10nServerTranslationInterface $translation * Translation entity. * @param bool $ajax * Whether the request came through AJAX, in which case no page theming * should be applied. Non-AJAX support is a fallback if JS is turned off. * * @return array * Translation details. */ public function translationDetails(L10nServerTranslationInterface $translation, bool $ajax) { // @see l10n_community_translation_detail() return [ '#markup' => 'L10nCommunityLanguagesController::translationDetails', ]; } /** * Generate list of projects and releases of where a string appears. * * @param \Drupal\l10n_server\Entity\L10nServerStringInterface $string * String entity. * @param bool $ajax * Whether the request came through AJAX, in which case no page theming * should be applied. Non-AJAX support is a fallback if JS is turned off. * * @return array * Source details. */ public function sourceDetails(L10nServerStringInterface $string, bool $ajax) { // @see l10n_community_string_details() return [ '#markup' => 'L10nCommunityLanguagesController::sourceDetails', ]; } }
l10n_community/src/Form/TranslateForm.php 0 → 100644 +833 −0 File added.Preview size limit exceeded, changes collapsed. Show changes
l10n_community/src/L10nTranslator.php +39 −6 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\l10n_community; Loading Loading @@ -36,6 +37,7 @@ class L10nTranslator { * @param string $langcode * Language code to use for the lookup. * @param array $filters * Filters, with following elements: * - 'project' * Project object to look up strings for. * - 'status' Loading @@ -57,7 +59,7 @@ class L10nTranslator { * @return array * An array of string records from database. */ function getStrings(string $langcode, array $filters, int $pager = NULL): array { public function getStrings(string $langcode, array $filters, int $pager = NULL): array { $query = $this->connection ->select('l10n_server_string', 's') ->distinct(); Loading @@ -83,7 +85,7 @@ class L10nTranslator { $query->condition('s.sid', $filters['sid']); } // Add submitted by condition // Add submitted by condition. if (!empty($filters['author'])) { $query->condition('t.uid', $filters['author']->id()); } Loading @@ -105,7 +107,8 @@ class L10nTranslator { // Context based filtering. if (isset($filters['context']) && $filters['context'] != 'all') { // We use 'none' for no context, so '' can be the defaut (for all contexts). // We use 'none' for no context, so '' can be the defaut (for all // contexts). $context = $filters['context'] == 'none' ? '' : $filters['context']; $query->condition('s.context', $context); } Loading Loading @@ -161,7 +164,8 @@ class L10nTranslator { $result = []; foreach ($strings as $string) { if ($string->suggestion) { // This string is not a translation, but we need that as a "parent" to display. // This string is not a translation, but we need that as a "parent" to // display. if (!$string->has_translation) { // No parent translation. Pretend this does not exist. // The display code will call for the suggestions. Loading @@ -184,7 +188,8 @@ class L10nTranslator { ->fetchAssoc(); if (!empty($translation)) { // It does have a translation however, so let's load it, and override. // It does have a translation however, so let's load it, and // override. foreach ($translation as $key => $value) { $string->$key = $value; } Loading @@ -196,4 +201,32 @@ class L10nTranslator { return $result; } /** * Get suggestions for a given string. * * @param string $langcode * Language code to use for the lookup. * @param int $sid * Source string ID. * * @return \Drupal\Core\Database\StatementInterface * String records from database. */ public function getSuggestions(string $langcode, int $sid): array { $query = $this->connection ->select('l10n_server_translation', 't'); $query->leftJoin('users_field_data', 'u', 'u.uid = t.uid'); $query->fields('t', [ 'tid', 'sid', 'translation', 'uid', 'created', 'changed', 'status', 'suggestion', ]); $query->addField('u', 'name', 'username'); $query->condition('t.language', $langcode); $query->condition('t.sid', $sid); $query->condition('t.status', 1); $query->condition('t.suggestion', 1); $query->orderBy('t.created'); return $query->execute(); } }
l10n_server/l10n_server.module +47 −1 Original line number Diff line number Diff line <?php declare(strict_types=1); /** * @file * The localization server module. */ declare(strict_types=1); use Drupal\Core\Render\Element; use Drupal\views\Views; /** * Action flag for string addition. */ define('L10N_SERVER_ACTION_ADD', 1); /** * Action flag for approval. */ define('L10N_SERVER_ACTION_APPROVE', 2); /** * Action flag for denial. */ define('L10N_SERVER_ACTION_DECLINE', 3); /** * Action flag for demotes. */ define('L10N_SERVER_ACTION_DEMOTE', 4); /** * Action flag for re-additions. */ define('L10N_SERVER_ACTION_READD', 5); /** * Action medium flag for unknown sources. */ define('L10N_SERVER_MEDIUM_UNKNOWN', 0); /** * Action medium flag for web based actions. */ define('L10N_SERVER_MEDIUM_WEB', 1); /** * Action medium flag for web based import. */ define('L10N_SERVER_MEDIUM_IMPORT', 2); /** * Action medium flag for remote action. */ define('L10N_SERVER_MEDIUM_REMOTE', 3); /** * Implements hook_cron(). */ Loading