Skip to content
Snippets Groups Projects
Commit f89c2042 authored by Shibin Das's avatar Shibin Das
Browse files

Coding style fixes

parent 4dfc33a5
Branches
Tags 1.0.0-alpha2
No related merge requests found
......@@ -13,9 +13,6 @@ class StringDemoController extends ControllerBase {
/**
* Content callback.
*
* @return array
* Render array.
*/
public function content() {
// Test configuration.
......@@ -39,9 +36,9 @@ class StringDemoController extends ControllerBase {
$rows = [];
$this->prepareVariations($rows, 'Content', $languages_being_tested);
$this->prepareVariations($rows, 'Pages', $languages_being_tested);
$this->prepareVariations($rows, 's:drupal.core.node.content.label', $languages_being_tested);
$this->prepareVariations($rows, 's:dashboard.welcome_message.short', $languages_being_tested);
$this->preparePluralVariations($rows, 's:search.result.items_count', $languages_being_tested, $plural_numbers);
$this->prepareVariations($rows, 'drupal.core.node.content.label', $languages_being_tested);
$this->prepareVariations($rows, 'dashboard.welcome_message.short', $languages_being_tested);
$this->preparePluralVariations($rows, 'search.result.items_count', $languages_being_tested, $plural_numbers);
$output = [
'#title' => 'Test strings in various language',
......@@ -53,6 +50,9 @@ class StringDemoController extends ControllerBase {
return $output;
}
/**
* Prepare various cases for testing string.
*/
protected function prepareVariations(array &$rows, $string_id, array $languages_being_tested) {
$string_test = [
'id' => $string_id,
......@@ -79,10 +79,7 @@ class StringDemoController extends ControllerBase {
}
/**
* @param array $rows
* @param $string_id
* @param array $languages_being_tested
* @param array $plural_numbers
* Prepare various cases for testing complex plural forms.
*/
protected function preparePluralVariations(array &$rows, $string_id, array $languages_being_tested, array $plural_numbers) {
$string_test = [
......
......@@ -9,7 +9,7 @@ use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a String Resource
* Provides a String Resource.
*
* @RestResource(
* id = "string_i18next_collection",
......@@ -22,6 +22,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class StringCollectionResource extends ResourceBase {
/**
* The string i18next service.
*
* @var \Drupal\string_i18next\StringI18Next
*/
protected $stringI18Next;
......@@ -63,7 +65,6 @@ class StringCollectionResource extends ResourceBase {
/**
* Responds to entity GET requests.
* @return \Drupal\rest\ResourceResponse
*/
public function get($language_code) {
return new ResourceResponse($this->stringI18Next->getStrings($language_code));
......
......@@ -9,7 +9,7 @@ use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a String Resource
* Provides a String Resource.
*
* @RestResource(
* id = "string_i18next",
......@@ -22,6 +22,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class StringResource extends ResourceBase {
/**
* The string i18next service.
*
* @var \Drupal\string_i18next\StringI18Next
*/
protected $stringI18Next;
......@@ -63,7 +65,6 @@ class StringResource extends ResourceBase {
/**
* Responds to entity GET requests.
* @return \Drupal\rest\ResourceResponse
*/
public function get($language_code, $id) {
$items = explode('.', $id);
......
......@@ -14,20 +14,30 @@ class StringI18Next {
use StringTranslationTrait;
/**
* The string manager service.
*
* @var \Drupal\string\StringManagerInterface
*/
protected $stringManager;
/**
* The local storage service.
*
* @var \Drupal\locale\StringStorageInterface
*/
protected $localStorage;
/**
* The constructor.
*/
public function __construct(StringManager $string_manager, StringStorageInterface $local_storage) {
$this->stringManager = $string_manager;
$this->localStorage = $local_storage;
}
/**
* Get strings for a given language code.
*/
public function getStrings($language_code) {
$definitions = $this->stringManager->getDefinitions();
$output = [];
......@@ -52,6 +62,9 @@ class StringI18Next {
return $output;
}
/**
* Create keys compatible with i18next.
*/
protected function formatKeyForI18NextItem($key, $value) {
$key = str_replace(':', '.', $key);
if ($value['msgctxt']) {
......@@ -60,6 +73,9 @@ class StringI18Next {
return $key;
}
/**
* Convert string definition to i18next friendly definition.
*/
protected function convertPluginItemToI18NextItem($value, $language_code) {
$output = [];
$context = $value['msgctxt'] ?? '';
......@@ -79,6 +95,7 @@ class StringI18Next {
$placeholders[$placeholder_key] = '{{' . substr($placeholder_key, '1') . '}}';
}
}
// phpcs:ignore Drupal.Semantics.FunctionT
$output['string'] = $this->t($value['id'], $placeholders, $options);
return $output;
}
......
......@@ -2,8 +2,8 @@
namespace Drupal\string_tmgmt\Plugin\tmgmt\Source;
use Drupal\tmgmt_locale\Plugin\tmgmt\Source\LocaleSource;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\tmgmt_locale\Plugin\tmgmt\Source\LocaleSource;
/**
* Translation Source plugin for locale strings.
......
......@@ -5,13 +5,13 @@ namespace Drupal\string\Form;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManager;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\file\Entity\File;
use Drupal\string\StringManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\system\FileDownloadController;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Drupal\file\Entity\File;
use Drupal\Core\StreamWrapper\StreamWrapperManager;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* Form for export options.
......@@ -49,12 +49,14 @@ class ExportForm extends FormBase {
/**
* Config Factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Datetime service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $dateTime;
......@@ -62,6 +64,7 @@ class ExportForm extends FormBase {
/**
* File repository service.
*
* @var \Drupal\file\FileRepositoryInterface
*/
protected $fileRepository;
......@@ -215,6 +218,9 @@ class ExportForm extends FormBase {
return $output;
}
/**
* Get message id.
*/
protected function getStringMessageId($definition) {
$id = $definition[StringManager::STRING_ID];
if (isset($definition[StringManager::MSG_ID])) {
......@@ -223,6 +229,9 @@ class ExportForm extends FormBase {
return $id;
}
/**
* Get source id for plural form.
*/
protected function getStringMessagePluralId($definition) {
$id = '';
if (isset($definition[StringManager::MSG_ID_PLURAL])) {
......@@ -234,6 +243,9 @@ class ExportForm extends FormBase {
return $id;
}
/**
* Get source id.
*/
protected function getStringSourceId($definition) {
return $definition[StringManager::STRING_ID];
}
......
......@@ -4,8 +4,8 @@ namespace Drupal\string\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\system\FileDownloadController;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Form for export options.
......@@ -76,7 +76,7 @@ class StringSettingsForm extends ConfigFormBase {
}
/**
* @return \Drupal\Core\Language\LanguageInterface[]
* Get active languages in the system.
*/
public function getLanguages(): array {
$active_languages = $this->languageManager->getLanguages();
......@@ -99,7 +99,11 @@ class StringSettingsForm extends ConfigFormBase {
$config = $this->config(static::SETTINGS);
$form['lang_table'] = [
'#type' => 'table',
'#header' => [$this->t('Language'), $this->t('Active Plural Rule'), $this->t('Overridden Plural Rule')],
'#header' => [
$this->t('Language'),
$this->t('Active Plural Rule'),
$this->t('Overridden Plural Rule'),
],
'#empty' => $this->t('No Languages found'),
];
$active_languages = $this->getLanguages();
......
......@@ -14,6 +14,7 @@ class StringPluralFormula implements StringPluralFormulaInterface {
/**
* Config Factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
......
......@@ -31,6 +31,8 @@ class StringManager extends DefaultPluginManager implements StringManagerInterfa
const __DEPRECATED__PLURAL_FORM = 'plural_form';
/**
* The local storage service.
*
* @var \Drupal\locale\StringStorageInterface
*/
protected $localStorage;
......@@ -68,10 +70,13 @@ class StringManager extends DefaultPluginManager implements StringManagerInterfa
return $this->discovery;
}
/**
* Check if the identifier uses proper namespace.key convention.
*/
protected function checkForNamespace($id) {
$splits = explode('.', $id);
if (count($splits) < 2) {
throw new PluginException("Plugin 'id' is must have format 'namespace.key'. {$id} is invalid");
throw new PluginException("Plugin 'id' must contain format 'namespace.key'. The id '{$id}' is invalid");
}
}
......
......@@ -10,7 +10,7 @@ use Drupal\string\StringManager;
*
* The purpose of this translator is to provide default translation when
* no other method provides any. The default is picked up from the string
* plugin item defined in my_module.string.yml
* plugin item defined in my_module.string.yml.
*
* E.g. Consider the following item inside my_module.string.yml,
* ```
......@@ -27,6 +27,8 @@ use Drupal\string\StringManager;
class StringTranslationDefaults extends StaticTranslation {
/**
* The string service.
*
* @var \Drupal\string\StringManager
*/
protected $stringManager;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment