l10n_server-2.x-dev/l10n_migrate/src/Plugin/migrate/source/L10nServerLanguage.php
l10n_migrate/src/Plugin/migrate/source/L10nServerLanguage.php
<?php declare(strict_types=1); namespace Drupal\l10n_migrate\Plugin\migrate\source; use Drupal\Core\Language\LanguageInterface; use Drupal\migrate\Plugin\migrate\source\SqlBase; use Drupal\migrate\Row; /** * Migrate Source plugin. * * @MigrateSource( * id = "l10n_migrate_server_language", * source_module = "l10n_migrate", * ) */ class L10nServerLanguage extends SqlBase { /** * {@inheritdoc} */ public function query() { $query = $this ->select('languages', 'l') ->fields('l', [ 'language', 'name', 'native', 'direction', 'enabled', 'plurals', 'formula', 'domain', 'prefix', 'weight', 'javascript', ]); return $query; } /** * {@inheritdoc} */ public function fields() { return [ 'language' => $this->t('Language ID'), 'name' => $this->t('Name'), 'native' => $this->t('Native'), 'direction' => $this->t('Direction'), 'enabled' => $this->t('Enabled'), 'plurals' => $this->t('Plurals'), 'formula' => $this->t('Formula'), 'domain' => $this->t('Domain'), 'prefix' => $this->t('Prefix'), 'weight' => $this->t('Weight'), 'javascript' => $this->t('Javascript'), ]; } /** * {@inheritdoc} */ public function getIds() { return [ 'language' => [ 'type' => 'string', 'alias' => 'l', ], ]; } /** * {@inheritdoc} */ public function prepareRow(Row $row) { if ($row->getSourceProperty('language') === 'en') { return FALSE; } $direction = $row->getSourceProperty('direction'); $row->setSourceProperty('direction', ($direction === 1) ? LanguageInterface::DIRECTION_LTR : LanguageInterface::DIRECTION_RTL); $row->setSourceProperty('locked', FALSE); /** @var \Drupal\l10n_pconfig\DrupalOrgPluralFormula $plural_formula */ $plural_formula = \Drupal::service('l10n_pconfig.drupalorg_plural_formula'); $formulae = $plural_formula->getDrupalPluralFormulae(); if (isset($formulae[$row->getSourceProperty('language')])) { $value = $formulae[$row->getSourceProperty('language')]; if ($value == 0) { $value = 'nplurals=1; plural=0;'; } elseif ($value === '($n!=1)') { $value = 'nplurals=2; plural=(n!=1);'; } $row->setSourceProperty('formula', $value); } return parent::prepareRow($row); } }