updated core and modules
This commit is contained in:
@@ -42,10 +42,10 @@ class LocaleController extends ControllerBase {
|
||||
* The render array for the string search screen.
|
||||
*/
|
||||
public function translatePage() {
|
||||
return array(
|
||||
return [
|
||||
'filter' => $this->formBuilder()->getForm('Drupal\locale\Form\TranslateFilterForm'),
|
||||
'form' => $this->formBuilder()->getForm('Drupal\locale\Form\TranslateEditForm'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Drupal\locale\Form;
|
||||
|
||||
use Drupal\Component\Gettext\PoStreamWriter;
|
||||
use Drupal\Core\File\FileSystemInterface;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
@@ -23,14 +24,24 @@ class ExportForm extends FormBase {
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* The file system service.
|
||||
*
|
||||
* @var \Drupal\Core\File\FileSystemInterface
|
||||
*/
|
||||
protected $fileSystem;
|
||||
|
||||
/**
|
||||
* Constructs a new ExportForm.
|
||||
*
|
||||
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
|
||||
* The language manager.
|
||||
* @param \Drupal\Core\File\FileSystemInterface $file_system
|
||||
* The file system service.
|
||||
*/
|
||||
public function __construct(LanguageManagerInterface $language_manager) {
|
||||
public function __construct(LanguageManagerInterface $language_manager, FileSystemInterface $file_system) {
|
||||
$this->languageManager = $language_manager;
|
||||
$this->fileSystem = $file_system;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,7 +49,8 @@ class ExportForm extends FormBase {
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('language_manager')
|
||||
$container->get('language_manager'),
|
||||
$container->get('file_system')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -54,7 +66,7 @@ class ExportForm extends FormBase {
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$languages = $this->languageManager->getLanguages();
|
||||
$language_options = array();
|
||||
$language_options = [];
|
||||
foreach ($languages as $langcode => $language) {
|
||||
if (locale_is_translatable($langcode)) {
|
||||
$language_options[$langcode] = $language->getName();
|
||||
@@ -63,60 +75,59 @@ class ExportForm extends FormBase {
|
||||
$language_default = $this->languageManager->getDefaultLanguage();
|
||||
|
||||
if (empty($language_options)) {
|
||||
$form['langcode'] = array(
|
||||
$form['langcode'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => LanguageInterface::LANGCODE_SYSTEM,
|
||||
);
|
||||
$form['langcode_text'] = array(
|
||||
];
|
||||
$form['langcode_text'] = [
|
||||
'#type' => 'item',
|
||||
'#title' => $this->t('Language'),
|
||||
'#markup' => $this->t('No language available. The export will only contain source strings.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
else {
|
||||
$form['langcode'] = array(
|
||||
$form['langcode'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Language'),
|
||||
'#options' => $language_options,
|
||||
'#default_value' => $language_default->getId(),
|
||||
'#empty_option' => $this->t('Source text only, no translations'),
|
||||
'#empty_value' => LanguageInterface::LANGCODE_SYSTEM,
|
||||
);
|
||||
$form['content_options'] = array(
|
||||
];
|
||||
$form['content_options'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Export options'),
|
||||
'#collapsed' => TRUE,
|
||||
'#tree' => TRUE,
|
||||
'#states' => array(
|
||||
'invisible' => array(
|
||||
':input[name="langcode"]' => array('value' => LanguageInterface::LANGCODE_SYSTEM),
|
||||
),
|
||||
),
|
||||
);
|
||||
$form['content_options']['not_customized'] = array(
|
||||
'#states' => [
|
||||
'invisible' => [
|
||||
':input[name="langcode"]' => ['value' => LanguageInterface::LANGCODE_SYSTEM],
|
||||
],
|
||||
],
|
||||
];
|
||||
$form['content_options']['not_customized'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Include non-customized translations'),
|
||||
'#default_value' => TRUE,
|
||||
);
|
||||
$form['content_options']['customized'] = array(
|
||||
];
|
||||
$form['content_options']['customized'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Include customized translations'),
|
||||
'#default_value' => TRUE,
|
||||
);
|
||||
$form['content_options']['not_translated'] = array(
|
||||
];
|
||||
$form['content_options']['not_translated'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Include untranslated text'),
|
||||
'#default_value' => TRUE,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$form['actions'] = array(
|
||||
$form['actions'] = [
|
||||
'#type' => 'actions',
|
||||
);
|
||||
$form['actions']['submit'] = array(
|
||||
];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Export'),
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
@@ -131,7 +142,7 @@ class ExportForm extends FormBase {
|
||||
else {
|
||||
$language = NULL;
|
||||
}
|
||||
$content_options = $form_state->getValue('content_options', array());
|
||||
$content_options = $form_state->getValue('content_options', []);
|
||||
$reader = new PoDatabaseReader();
|
||||
$language_name = '';
|
||||
if ($language != NULL) {
|
||||
@@ -148,7 +159,7 @@ class ExportForm extends FormBase {
|
||||
|
||||
$item = $reader->readItem();
|
||||
if (!empty($item)) {
|
||||
$uri = tempnam('temporary://', 'po_');
|
||||
$uri = $this->fileSystem->tempnam('temporary://', 'po_');
|
||||
$header = $reader->getHeader();
|
||||
$header->setProjectName($this->config('system.site')->get('name'));
|
||||
$header->setLanguageName($language_name);
|
||||
|
||||
@@ -72,7 +72,7 @@ class ImportForm extends FormBase {
|
||||
|
||||
// Initialize a language list to the ones available, including English if we
|
||||
// are to translate Drupal to English as well.
|
||||
$existing_languages = array();
|
||||
$existing_languages = [];
|
||||
foreach ($languages as $langcode => $language) {
|
||||
if (locale_is_translatable($langcode)) {
|
||||
$existing_languages[$langcode] = $language->getName();
|
||||
@@ -88,65 +88,65 @@ class ImportForm extends FormBase {
|
||||
}
|
||||
else {
|
||||
$default = key($existing_languages);
|
||||
$language_options = array(
|
||||
$language_options = [
|
||||
(string) $this->t('Existing languages') => $existing_languages,
|
||||
(string) $this->t('Languages not yet added') => $this->languageManager->getStandardLanguageListWithoutConfigured(),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$validators = array(
|
||||
'file_validate_extensions' => array('po'),
|
||||
'file_validate_size' => array(file_upload_max_size()),
|
||||
);
|
||||
$form['file'] = array(
|
||||
$validators = [
|
||||
'file_validate_extensions' => ['po'],
|
||||
'file_validate_size' => [file_upload_max_size()],
|
||||
];
|
||||
$form['file'] = [
|
||||
'#type' => 'file',
|
||||
'#title' => $this->t('Translation file'),
|
||||
'#description' => array(
|
||||
'#description' => [
|
||||
'#theme' => 'file_upload_help',
|
||||
'#description' => $this->t('A Gettext Portable Object file.'),
|
||||
'#upload_validators' => $validators,
|
||||
),
|
||||
],
|
||||
'#size' => 50,
|
||||
'#upload_validators' => $validators,
|
||||
'#attributes' => array('class' => array('file-import-input')),
|
||||
);
|
||||
$form['langcode'] = array(
|
||||
'#attributes' => ['class' => ['file-import-input']],
|
||||
];
|
||||
$form['langcode'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Language'),
|
||||
'#options' => $language_options,
|
||||
'#default_value' => $default,
|
||||
'#attributes' => array('class' => array('langcode-input')),
|
||||
);
|
||||
'#attributes' => ['class' => ['langcode-input']],
|
||||
];
|
||||
|
||||
$form['customized'] = array(
|
||||
$form['customized'] = [
|
||||
'#title' => $this->t('Treat imported strings as custom translations'),
|
||||
'#type' => 'checkbox',
|
||||
);
|
||||
$form['overwrite_options'] = array(
|
||||
];
|
||||
$form['overwrite_options'] = [
|
||||
'#type' => 'container',
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
$form['overwrite_options']['not_customized'] = array(
|
||||
];
|
||||
$form['overwrite_options']['not_customized'] = [
|
||||
'#title' => $this->t('Overwrite non-customized translations'),
|
||||
'#type' => 'checkbox',
|
||||
'#states' => array(
|
||||
'checked' => array(
|
||||
':input[name="customized"]' => array('checked' => TRUE),
|
||||
),
|
||||
),
|
||||
);
|
||||
$form['overwrite_options']['customized'] = array(
|
||||
'#states' => [
|
||||
'checked' => [
|
||||
':input[name="customized"]' => ['checked' => TRUE],
|
||||
],
|
||||
],
|
||||
];
|
||||
$form['overwrite_options']['customized'] = [
|
||||
'#title' => $this->t('Overwrite existing customized translations'),
|
||||
'#type' => 'checkbox',
|
||||
);
|
||||
];
|
||||
|
||||
$form['actions'] = array(
|
||||
$form['actions'] = [
|
||||
'#type' => 'actions',
|
||||
);
|
||||
$form['actions']['submit'] = array(
|
||||
];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Import'),
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
@@ -172,21 +172,21 @@ class ImportForm extends FormBase {
|
||||
if (empty($language)) {
|
||||
$language = ConfigurableLanguage::createFromLangcode($form_state->getValue('langcode'));
|
||||
$language->save();
|
||||
drupal_set_message($this->t('The language %language has been created.', array('%language' => $this->t($language->label()))));
|
||||
drupal_set_message($this->t('The language %language has been created.', ['%language' => $this->t($language->label())]));
|
||||
}
|
||||
$options = array_merge(_locale_translation_default_update_options(), array(
|
||||
$options = array_merge(_locale_translation_default_update_options(), [
|
||||
'langcode' => $form_state->getValue('langcode'),
|
||||
'overwrite_options' => $form_state->getValue('overwrite_options'),
|
||||
'customized' => $form_state->getValue('customized') ? LOCALE_CUSTOMIZED : LOCALE_NOT_CUSTOMIZED,
|
||||
));
|
||||
]);
|
||||
$this->moduleHandler->loadInclude('locale', 'bulk.inc');
|
||||
$file = locale_translate_file_attach_properties($this->file, $options);
|
||||
$batch = locale_translate_batch_build(array($file->uri => $file), $options);
|
||||
$batch = locale_translate_batch_build([$file->uri => $file], $options);
|
||||
batch_set($batch);
|
||||
|
||||
// Create or update all configuration translations for this language.
|
||||
\Drupal::moduleHandler()->loadInclude('locale', 'bulk.inc');
|
||||
if ($batch = locale_config_batch_update_components($options, array($form_state->getValue('langcode')))) {
|
||||
if ($batch = locale_config_batch_update_components($options, [$form_state->getValue('langcode')])) {
|
||||
batch_set($batch);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,35 +30,35 @@ class LocaleSettingsForm extends ConfigFormBase {
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$config = $this->config('locale.settings');
|
||||
|
||||
$form['update_interval_days'] = array(
|
||||
$form['update_interval_days'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => $this->t('Check for updates'),
|
||||
'#default_value' => $config->get('translation.update_interval_days'),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'0' => $this->t('Never (manually)'),
|
||||
'7' => $this->t('Weekly'),
|
||||
'30' => $this->t('Monthly'),
|
||||
),
|
||||
'#description' => $this->t('Select how frequently you want to check for new interface translations for your currently installed modules and themes. <a href=":url">Check updates now</a>.', array(':url' => $this->url('locale.check_translation'))),
|
||||
);
|
||||
],
|
||||
'#description' => $this->t('Select how frequently you want to check for new interface translations for your currently installed modules and themes. <a href=":url">Check updates now</a>.', [':url' => $this->url('locale.check_translation')]),
|
||||
];
|
||||
|
||||
if ($directory = $config->get('translation.path')) {
|
||||
$description = $this->t('Translation files are stored locally in the %path directory. You can change this directory on the <a href=":url">File system</a> configuration page.', array('%path' => $directory, ':url' => $this->url('system.file_system_settings')));
|
||||
$description = $this->t('Translation files are stored locally in the %path directory. You can change this directory on the <a href=":url">File system</a> configuration page.', ['%path' => $directory, ':url' => $this->url('system.file_system_settings')]);
|
||||
}
|
||||
else {
|
||||
$description = $this->t('Translation files will not be stored locally. Change the Interface translation directory on the <a href=":url">File system configuration</a> page.', array(':url' => $this->url('system.file_system_settings')));
|
||||
$description = $this->t('Translation files will not be stored locally. Change the Interface translation directory on the <a href=":url">File system configuration</a> page.', [':url' => $this->url('system.file_system_settings')]);
|
||||
}
|
||||
$form['#translation_directory'] = $directory;
|
||||
$form['use_source'] = array(
|
||||
$form['use_source'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => $this->t('Translation source'),
|
||||
'#default_value' => $config->get('translation.use_source'),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
LOCALE_TRANSLATION_USE_SOURCE_REMOTE_AND_LOCAL => $this->t('Drupal translation server and local files'),
|
||||
LOCALE_TRANSLATION_USE_SOURCE_LOCAL => $this->t('Local files only'),
|
||||
),
|
||||
],
|
||||
'#description' => $this->t('The source of translation files for automatic interface translation.') . ' ' . $description,
|
||||
);
|
||||
];
|
||||
|
||||
if ($config->get('translation.overwrite_not_customized') == FALSE) {
|
||||
$default = LOCALE_TRANSLATION_OVERWRITE_NONE;
|
||||
@@ -69,17 +69,17 @@ class LocaleSettingsForm extends ConfigFormBase {
|
||||
else {
|
||||
$default = LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED;
|
||||
}
|
||||
$form['overwrite'] = array(
|
||||
$form['overwrite'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => $this->t('Import behavior'),
|
||||
'#default_value' => $default,
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
LOCALE_TRANSLATION_OVERWRITE_NONE => $this->t("Don't overwrite existing translations."),
|
||||
LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED => $this->t('Only overwrite imported translations, customized translations are kept.'),
|
||||
LOCALE_TRANSLATION_OVERWRITE_ALL => $this->t('Overwrite existing translations.'),
|
||||
),
|
||||
],
|
||||
'#description' => $this->t('How to treat existing translations when automatically updating the interface translations.'),
|
||||
);
|
||||
];
|
||||
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
@@ -91,7 +91,7 @@ class LocaleSettingsForm extends ConfigFormBase {
|
||||
parent::validateForm($form, $form_state);
|
||||
|
||||
if (empty($form['#translation_directory']) && $form_state->getValue('use_source') == LOCALE_TRANSLATION_USE_SOURCE_LOCAL) {
|
||||
$form_state->setErrorByName('use_source', $this->t('You have selected local translation source, but no <a href=":url">Interface translation directory</a> was configured.', array(':url' => $this->url('system.file_system_settings'))));
|
||||
$form_state->setErrorByName('use_source', $this->t('You have selected local translation source, but no <a href=":url">Interface translation directory</a> was configured.', [':url' => $this->url('system.file_system_settings')]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,12 +32,12 @@ class TranslateEditForm extends TranslateFormBase {
|
||||
|
||||
$form['#attached']['library'][] = 'locale/drupal.locale.admin';
|
||||
|
||||
$form['langcode'] = array(
|
||||
$form['langcode'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $filter_values['langcode'],
|
||||
);
|
||||
];
|
||||
|
||||
$form['strings'] = array(
|
||||
$form['strings'] = [
|
||||
'#type' => 'table',
|
||||
'#tree' => TRUE,
|
||||
'#language' => $langname,
|
||||
@@ -47,7 +47,7 @@ class TranslateEditForm extends TranslateFormBase {
|
||||
],
|
||||
'#empty' => $this->t('No strings available.'),
|
||||
'#attributes' => ['class' => ['locale-translate-edit-table']],
|
||||
);
|
||||
];
|
||||
|
||||
if (isset($langcode)) {
|
||||
$strings = $this->translateFilterLoadStrings();
|
||||
@@ -63,14 +63,14 @@ class TranslateEditForm extends TranslateFormBase {
|
||||
if (count($source_array) == 1) {
|
||||
// Add original string value and mark as non-plural.
|
||||
$plural = FALSE;
|
||||
$form['strings'][$string->lid]['original'] = array(
|
||||
$form['strings'][$string->lid]['original'] = [
|
||||
'#type' => 'item',
|
||||
'#title' => $this->t('Source string (@language)', array('@language' => $this->t('Built-in English'))),
|
||||
'#title' => $this->t('Source string (@language)', ['@language' => $this->t('Built-in English')]),
|
||||
'#title_display' => 'invisible',
|
||||
'#plain_text' => $source_array[0],
|
||||
'#preffix' => '<span lang="en">',
|
||||
'#suffix' => '</span>',
|
||||
);
|
||||
];
|
||||
}
|
||||
else {
|
||||
// Add original string value and mark as plural.
|
||||
@@ -79,7 +79,7 @@ class TranslateEditForm extends TranslateFormBase {
|
||||
'#type' => 'item',
|
||||
'#title' => $this->t('Singular form'),
|
||||
'#plain_text' => $source_array[0],
|
||||
'#prefix' => '<span class="visually-hidden">' . $this->t('Source string (@language)', array('@language' => $this->t('Built-in English'))) . '</span><span lang="en">',
|
||||
'#prefix' => '<span class="visually-hidden">' . $this->t('Source string (@language)', ['@language' => $this->t('Built-in English')]) . '</span><span lang="en">',
|
||||
'#suffix' => '</span>',
|
||||
];
|
||||
$original_plural = [
|
||||
@@ -108,27 +108,27 @@ class TranslateEditForm extends TranslateFormBase {
|
||||
// Approximate the number of rows to use in the default textarea.
|
||||
$rows = min(ceil(str_word_count($source_array[0]) / 12), 10);
|
||||
if (!$plural) {
|
||||
$form['strings'][$string->lid]['translations'][0] = array(
|
||||
$form['strings'][$string->lid]['translations'][0] = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => $this->t('Translated string (@language)', array('@language' => $langname)),
|
||||
'#title' => $this->t('Translated string (@language)', ['@language' => $langname]),
|
||||
'#title_display' => 'invisible',
|
||||
'#rows' => $rows,
|
||||
'#default_value' => $translation_array[0],
|
||||
'#attributes' => array('lang' => $langcode),
|
||||
);
|
||||
'#attributes' => ['lang' => $langcode],
|
||||
];
|
||||
}
|
||||
else {
|
||||
// Add a textarea for each plural variant.
|
||||
for ($i = 0; $i < $plurals; $i++) {
|
||||
$form['strings'][$string->lid]['translations'][$i] = array(
|
||||
$form['strings'][$string->lid]['translations'][$i] = [
|
||||
'#type' => 'textarea',
|
||||
// @todo Should use better labels https://www.drupal.org/node/2499639
|
||||
'#title' => ($i == 0 ? $this->t('Singular form') : $this->formatPlural($i, 'First plural form', '@count. plural form')),
|
||||
'#rows' => $rows,
|
||||
'#default_value' => isset($translation_array[$i]) ? $translation_array[$i] : '',
|
||||
'#attributes' => array('lang' => $langcode),
|
||||
'#prefix' => $i == 0 ? ('<span class="visually-hidden">' . $this->t('Translated string (@language)', array('@language' => $langname)) . '</span>') : '',
|
||||
);
|
||||
'#attributes' => ['lang' => $langcode],
|
||||
'#prefix' => $i == 0 ? ('<span class="visually-hidden">' . $this->t('Translated string (@language)', ['@language' => $langname]) . '</span>') : '',
|
||||
];
|
||||
}
|
||||
if ($plurals == 2) {
|
||||
// Simplify interface text for the most common case.
|
||||
@@ -137,11 +137,11 @@ class TranslateEditForm extends TranslateFormBase {
|
||||
}
|
||||
}
|
||||
if (count(Element::children($form['strings']))) {
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Save translations'),
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
$form['pager']['#type'] = 'pager';
|
||||
@@ -156,9 +156,9 @@ class TranslateEditForm extends TranslateFormBase {
|
||||
foreach ($form_state->getValue('strings') as $lid => $translations) {
|
||||
foreach ($translations['translations'] as $key => $value) {
|
||||
if (!locale_string_is_safe($value)) {
|
||||
$form_state->setErrorByName("strings][$lid][translations][$key", $this->t('The submitted string contains disallowed HTML: %string', array('%string' => $value)));
|
||||
$form_state->setErrorByName("translations][$langcode][$key", $this->t('The submitted string contains disallowed HTML: %string', array('%string' => $value)));
|
||||
$this->logger('locale')->warning('Attempted submission of a translation string with disallowed HTML: %string', array('%string' => $value));
|
||||
$form_state->setErrorByName("strings][$lid][translations][$key", $this->t('The submitted string contains disallowed HTML: %string', ['%string' => $value]));
|
||||
$form_state->setErrorByName("translations][$langcode][$key", $this->t('The submitted string contains disallowed HTML: %string', ['%string' => $value]));
|
||||
$this->logger('locale')->warning('Attempted submission of a translation string with disallowed HTML: %string', ['%string' => $value]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -169,12 +169,12 @@ class TranslateEditForm extends TranslateFormBase {
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$langcode = $form_state->getValue('langcode');
|
||||
$updated = array();
|
||||
$updated = [];
|
||||
|
||||
// Preload all translations for strings in the form.
|
||||
$lids = array_keys($form_state->getValue('strings'));
|
||||
$existing_translation_objects = array();
|
||||
foreach ($this->localeStorage->getTranslations(array('lid' => $lids, 'language' => $langcode, 'translated' => TRUE)) as $existing_translation_object) {
|
||||
$existing_translation_objects = [];
|
||||
foreach ($this->localeStorage->getTranslations(['lid' => $lids, 'language' => $langcode, 'translated' => TRUE]) as $existing_translation_object) {
|
||||
$existing_translation_objects[$existing_translation_object->lid] = $existing_translation_object;
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ class TranslateEditForm extends TranslateFormBase {
|
||||
|
||||
if ($is_changed) {
|
||||
// Only update or insert if we have a value to use.
|
||||
$target = isset($existing_translation_objects[$lid]) ? $existing_translation_objects[$lid] : $this->localeStorage->createTranslation(array('lid' => $lid, 'language' => $langcode));
|
||||
$target = isset($existing_translation_objects[$lid]) ? $existing_translation_objects[$lid] : $this->localeStorage->createTranslation(['lid' => $lid, 'language' => $langcode]);
|
||||
$target->setPlurals($new_translation['translations'])
|
||||
->setCustomized()
|
||||
->save();
|
||||
@@ -224,15 +224,15 @@ class TranslateEditForm extends TranslateFormBase {
|
||||
if (isset($page)) {
|
||||
$form_state->setRedirect(
|
||||
'locale.translate_page',
|
||||
array(),
|
||||
array('page' => $page)
|
||||
[],
|
||||
['page' => $page]
|
||||
);
|
||||
}
|
||||
|
||||
if ($updated) {
|
||||
// Clear cache and force refresh of JavaScript translations.
|
||||
_locale_refresh_translations(array($langcode), $updated);
|
||||
_locale_refresh_configuration(array($langcode), $updated);
|
||||
_locale_refresh_translations([$langcode], $updated);
|
||||
_locale_refresh_configuration([$langcode], $updated);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,24 +25,24 @@ class TranslateFilterForm extends TranslateFormBase {
|
||||
|
||||
$form['#attached']['library'][] = 'locale/drupal.locale.admin';
|
||||
|
||||
$form['filters'] = array(
|
||||
$form['filters'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Filter translatable strings'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
];
|
||||
foreach ($filters as $key => $filter) {
|
||||
// Special case for 'string' filter.
|
||||
if ($key == 'string') {
|
||||
$form['filters']['status']['string'] = array(
|
||||
$form['filters']['status']['string'] = [
|
||||
'#type' => 'search',
|
||||
'#title' => $filter['title'],
|
||||
'#description' => $filter['description'],
|
||||
'#default_value' => $filter_values[$key],
|
||||
);
|
||||
];
|
||||
}
|
||||
else {
|
||||
$empty_option = isset($filter['options'][$filter['default']]) ? $filter['options'][$filter['default']] : '- None -';
|
||||
$form['filters']['status'][$key] = array(
|
||||
$form['filters']['status'][$key] = [
|
||||
'#title' => $filter['title'],
|
||||
'#type' => 'select',
|
||||
'#empty_value' => $filter['default'],
|
||||
@@ -50,27 +50,27 @@ class TranslateFilterForm extends TranslateFormBase {
|
||||
'#size' => 0,
|
||||
'#options' => $filter['options'],
|
||||
'#default_value' => $filter_values[$key],
|
||||
);
|
||||
];
|
||||
if (isset($filter['states'])) {
|
||||
$form['filters']['status'][$key]['#states'] = $filter['states'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$form['filters']['actions'] = array(
|
||||
$form['filters']['actions'] = [
|
||||
'#type' => 'actions',
|
||||
'#attributes' => array('class' => array('container-inline')),
|
||||
);
|
||||
$form['filters']['actions']['submit'] = array(
|
||||
'#attributes' => ['class' => ['container-inline']],
|
||||
];
|
||||
$form['filters']['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Filter'),
|
||||
);
|
||||
];
|
||||
if (!empty($_SESSION['locale_translate_filter'])) {
|
||||
$form['filters']['actions']['reset'] = array(
|
||||
$form['filters']['actions']['reset'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Reset'),
|
||||
'#submit' => array('::resetForm'),
|
||||
);
|
||||
'#submit' => ['::resetForm'],
|
||||
];
|
||||
}
|
||||
|
||||
return $form;
|
||||
@@ -93,7 +93,7 @@ class TranslateFilterForm extends TranslateFormBase {
|
||||
* Provides a submit handler for the reset button.
|
||||
*/
|
||||
public function resetForm(array &$form, FormStateInterface $form_state) {
|
||||
$_SESSION['locale_translate_filter'] = array();
|
||||
$_SESSION['locale_translate_filter'] = [];
|
||||
$form_state->setRedirect('locale.translate_page');
|
||||
}
|
||||
|
||||
|
||||
@@ -81,8 +81,8 @@ abstract class TranslateFormBase extends FormBase {
|
||||
|
||||
// Language is sanitized to be one of the possible options in
|
||||
// translateFilterValues().
|
||||
$conditions = array('language' => $filter_values['langcode']);
|
||||
$options = array('pager limit' => 30, 'translated' => TRUE, 'untranslated' => TRUE);
|
||||
$conditions = ['language' => $filter_values['langcode']];
|
||||
$options = ['pager limit' => 30, 'translated' => TRUE, 'untranslated' => TRUE];
|
||||
|
||||
// Add translation status conditions and options.
|
||||
switch ($filter_values['translation']) {
|
||||
@@ -123,7 +123,7 @@ abstract class TranslateFormBase extends FormBase {
|
||||
return static::$filterValues;
|
||||
}
|
||||
|
||||
$filter_values = array();
|
||||
$filter_values = [];
|
||||
$filters = $this->translateFilters();
|
||||
foreach ($filters as $key => $filter) {
|
||||
$filter_values[$key] = $filter['default'];
|
||||
@@ -152,12 +152,12 @@ abstract class TranslateFormBase extends FormBase {
|
||||
* Lists locale translation filters that can be applied.
|
||||
*/
|
||||
protected function translateFilters() {
|
||||
$filters = array();
|
||||
$filters = [];
|
||||
|
||||
// Get all languages, except English.
|
||||
$this->languageManager->reset();
|
||||
$languages = $this->languageManager->getLanguages();
|
||||
$language_options = array();
|
||||
$language_options = [];
|
||||
foreach ($languages as $langcode => $language) {
|
||||
if (locale_is_translatable($langcode)) {
|
||||
$language_options[$langcode] = $language->getName();
|
||||
@@ -171,42 +171,42 @@ abstract class TranslateFormBase extends FormBase {
|
||||
$default_langcode = array_shift($available_langcodes);
|
||||
}
|
||||
|
||||
$filters['string'] = array(
|
||||
$filters['string'] = [
|
||||
'title' => $this->t('String contains'),
|
||||
'description' => $this->t('Leave blank to show all strings. The search is case sensitive.'),
|
||||
'default' => '',
|
||||
);
|
||||
];
|
||||
|
||||
$filters['langcode'] = array(
|
||||
$filters['langcode'] = [
|
||||
'title' => $this->t('Translation language'),
|
||||
'options' => $language_options,
|
||||
'default' => $default_langcode,
|
||||
);
|
||||
];
|
||||
|
||||
$filters['translation'] = array(
|
||||
$filters['translation'] = [
|
||||
'title' => $this->t('Search in'),
|
||||
'options' => array(
|
||||
'options' => [
|
||||
'all' => $this->t('Both translated and untranslated strings'),
|
||||
'translated' => $this->t('Only translated strings'),
|
||||
'untranslated' => $this->t('Only untranslated strings'),
|
||||
),
|
||||
],
|
||||
'default' => 'all',
|
||||
);
|
||||
];
|
||||
|
||||
$filters['customized'] = array(
|
||||
$filters['customized'] = [
|
||||
'title' => $this->t('Translation type'),
|
||||
'options' => array(
|
||||
'options' => [
|
||||
'all' => $this->t('All'),
|
||||
LOCALE_NOT_CUSTOMIZED => $this->t('Non-customized translation'),
|
||||
LOCALE_CUSTOMIZED => $this->t('Customized translation'),
|
||||
),
|
||||
'states' => array(
|
||||
'visible' => array(
|
||||
':input[name=translation]' => array('value' => 'translated'),
|
||||
),
|
||||
),
|
||||
],
|
||||
'states' => [
|
||||
'visible' => [
|
||||
':input[name=translation]' => ['value' => 'translated'],
|
||||
],
|
||||
],
|
||||
'default' => 'all',
|
||||
);
|
||||
];
|
||||
|
||||
return $filters;
|
||||
}
|
||||
|
||||
@@ -65,10 +65,10 @@ class TranslationStatusForm extends FormBase {
|
||||
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();
|
||||
$options = [];
|
||||
$languages_update = [];
|
||||
$languages_not_found = [];
|
||||
$projects_update = [];
|
||||
// Prepare information about projects which have available translation
|
||||
// updates.
|
||||
if ($languages && $status) {
|
||||
@@ -77,24 +77,24 @@ class TranslationStatusForm extends FormBase {
|
||||
// Build data options for the select table.
|
||||
foreach ($updates as $langcode => $update) {
|
||||
$title = $languages[$langcode]->getName();
|
||||
$locale_translation_update_info = array('#theme' => 'locale_translation_update_info');
|
||||
foreach (array('updates', 'not_found') as $update_status) {
|
||||
$locale_translation_update_info = ['#theme' => 'locale_translation_update_info'];
|
||||
foreach (['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(
|
||||
'data' => array(
|
||||
$options[$langcode] = [
|
||||
'title' => [
|
||||
'data' => [
|
||||
'#title' => $title,
|
||||
'#plain_text' => $title,
|
||||
),
|
||||
),
|
||||
'status' => array(
|
||||
'class' => array('description', 'priority-low'),
|
||||
],
|
||||
],
|
||||
'status' => [
|
||||
'class' => ['description', 'priority-low'],
|
||||
'data' => $locale_translation_update_info,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
if (!empty($update['not_found'])) {
|
||||
$languages_not_found[$langcode] = $langcode;
|
||||
}
|
||||
@@ -110,43 +110,43 @@ class TranslationStatusForm extends FormBase {
|
||||
}
|
||||
|
||||
$last_checked = $this->state->get('locale.translation_last_checked');
|
||||
$form['last_checked'] = array(
|
||||
$form['last_checked'] = [
|
||||
'#theme' => 'locale_translation_last_check',
|
||||
'#last' => $last_checked,
|
||||
);
|
||||
];
|
||||
|
||||
$header = array(
|
||||
'title' => array(
|
||||
$header = [
|
||||
'title' => [
|
||||
'data' => $this->t('Language'),
|
||||
'class' => array('title'),
|
||||
),
|
||||
'status' => array(
|
||||
'class' => ['title'],
|
||||
],
|
||||
'status' => [
|
||||
'data' => $this->t('Status'),
|
||||
'class' => array('status', 'priority-low'),
|
||||
),
|
||||
);
|
||||
'class' => ['status', 'priority-low'],
|
||||
],
|
||||
];
|
||||
|
||||
if (!$languages) {
|
||||
$empty = $this->t('No translatable languages available. <a href=":add_language">Add a language</a> first.', array(
|
||||
$empty = $this->t('No translatable languages available. <a href=":add_language">Add a language</a> first.', [
|
||||
':add_language' => $this->url('entity.configurable_language.collection'),
|
||||
));
|
||||
]);
|
||||
}
|
||||
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(
|
||||
$empty = $this->t('No translation status available. <a href=":check">Check manually</a>.', [
|
||||
':check' => $this->url('locale.check_translation'),
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
// The projects which require an update. Used by the _submit callback.
|
||||
$form['projects_update'] = array(
|
||||
$form['projects_update'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $projects_update,
|
||||
);
|
||||
];
|
||||
|
||||
$form['langcodes'] = array(
|
||||
$form['langcodes'] = [
|
||||
'#type' => 'tableselect',
|
||||
'#header' => $header,
|
||||
'#options' => $options,
|
||||
@@ -156,17 +156,17 @@ class TranslationStatusForm extends FormBase {
|
||||
'#multiple' => TRUE,
|
||||
'#required' => TRUE,
|
||||
'#not_found' => $languages_not_found,
|
||||
'#after_build' => array('locale_translation_language_table'),
|
||||
);
|
||||
'#after_build' => ['locale_translation_language_table'],
|
||||
];
|
||||
|
||||
$form['#attached']['library'][] = 'locale/drupal.locale.admin';
|
||||
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
if ($languages_update) {
|
||||
$form['actions']['submit'] = array(
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Update translations'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return $form;
|
||||
@@ -183,7 +183,7 @@ class TranslationStatusForm extends FormBase {
|
||||
* translation update status.
|
||||
*/
|
||||
protected function prepareUpdateData(array $status) {
|
||||
$updates = array();
|
||||
$updates = [];
|
||||
|
||||
// @todo Calling locale_translation_build_projects() is an expensive way to
|
||||
// get a module name. In follow-up issue
|
||||
@@ -196,22 +196,22 @@ class TranslationStatusForm extends FormBase {
|
||||
foreach ($project as $langcode => $project_info) {
|
||||
// No translation file found for this project-language combination.
|
||||
if (empty($project_info->type)) {
|
||||
$updates[$langcode]['not_found'][] = array(
|
||||
$updates[$langcode]['not_found'][] = [
|
||||
'name' => $project_info->name == 'drupal' ? $this->t('Drupal core') : $project_data[$project_info->name]->info['name'],
|
||||
'version' => $project_info->version,
|
||||
'info' => $this->createInfoString($project_info),
|
||||
);
|
||||
];
|
||||
}
|
||||
// Translation update found for this project-language combination.
|
||||
elseif ($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;
|
||||
$recent = _locale_translation_source_compare($local, $remote) == LOCALE_TRANSLATION_SOURCE_COMPARE_LT ? $remote : $local;
|
||||
$updates[$langcode]['updates'][] = array(
|
||||
$updates[$langcode]['updates'][] = [
|
||||
'name' => $project_info->name == 'drupal' ? $this->t('Drupal core') : $project_data[$project_info->name]->info['name'],
|
||||
'version' => $project_info->version,
|
||||
'timestamp' => $recent->timestamp,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -238,13 +238,13 @@ class TranslationStatusForm extends FormBase {
|
||||
$local_path = isset($project_info->files['local']->uri) ? $project_info->files['local']->uri : FALSE;
|
||||
|
||||
if (locale_translation_use_remote_source() && $remote_path && $local_path) {
|
||||
return $this->t('File not found at %remote_path nor at %local_path', array(
|
||||
return $this->t('File not found at %remote_path nor at %local_path', [
|
||||
'%remote_path' => $remote_path,
|
||||
'%local_path' => $local_path,
|
||||
));
|
||||
]);
|
||||
}
|
||||
elseif ($local_path) {
|
||||
return $this->t('File not found at %local_path', array('%local_path' => $local_path));
|
||||
return $this->t('File not found at %local_path', ['%local_path' => $local_path]);
|
||||
}
|
||||
return $this->t('Translation file location could not be determined.');
|
||||
}
|
||||
@@ -279,7 +279,7 @@ class TranslationStatusForm extends FormBase {
|
||||
$last_checked = $this->state->get('locale.translation_last_checked');
|
||||
if ($last_checked < REQUEST_TIME - LOCALE_TRANSLATION_STATUS_TTL) {
|
||||
locale_translation_clear_status();
|
||||
$batch = locale_translation_batch_update_build(array(), $langcodes, $options);
|
||||
$batch = locale_translation_batch_update_build([], $langcodes, $options);
|
||||
batch_set($batch);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -41,12 +41,12 @@ class Gettext {
|
||||
*/
|
||||
public static function fileToDatabase($file, $options) {
|
||||
// Add the default values to the options array.
|
||||
$options += array(
|
||||
'overwrite_options' => array(),
|
||||
$options += [
|
||||
'overwrite_options' => [],
|
||||
'customized' => LOCALE_NOT_CUSTOMIZED,
|
||||
'items' => -1,
|
||||
'seek' => 0,
|
||||
);
|
||||
];
|
||||
// Instantiate and initialize the stream reader for this file.
|
||||
$reader = new PoStreamReader();
|
||||
$reader->setLangcode($file->langcode);
|
||||
@@ -67,10 +67,10 @@ class Gettext {
|
||||
// Initialize the database writer.
|
||||
$writer = new PoDatabaseWriter();
|
||||
$writer->setLangcode($file->langcode);
|
||||
$writer_options = array(
|
||||
$writer_options = [
|
||||
'overwrite_options' => $options['overwrite_options'],
|
||||
'customized' => $options['customized'],
|
||||
);
|
||||
];
|
||||
$writer->setOptions($writer_options);
|
||||
$writer->setHeader($header);
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ class LocaleConfigManager {
|
||||
return $this->getTranslatableData($typed_config);
|
||||
}
|
||||
}
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,7 +163,7 @@ class LocaleConfigManager {
|
||||
* TranslatableMarkup.
|
||||
*/
|
||||
protected function getTranslatableData(TypedDataInterface $element) {
|
||||
$translatable = array();
|
||||
$translatable = [];
|
||||
if ($element instanceof TraversableTypedDataInterface) {
|
||||
foreach ($element as $key => $property) {
|
||||
$value = $this->getTranslatableData($property);
|
||||
@@ -178,11 +178,11 @@ class LocaleConfigManager {
|
||||
$value = $element->getValue();
|
||||
$definition = $element->getDataDefinition();
|
||||
if (!empty($definition['translatable']) && $value !== '' && $value !== NULL) {
|
||||
$options = array();
|
||||
$options = [];
|
||||
if (isset($definition['translation context'])) {
|
||||
$options['context'] = $definition['translation context'];
|
||||
}
|
||||
return new TranslatableMarkup($value, array(), $options);
|
||||
return new TranslatableMarkup($value, [], $options);
|
||||
}
|
||||
}
|
||||
return $translatable;
|
||||
@@ -215,7 +215,7 @@ class LocaleConfigManager {
|
||||
* @see self::getTranslatableData()
|
||||
*/
|
||||
protected function processTranslatableData($name, array $active, array $translatable, $langcode) {
|
||||
$translated = array();
|
||||
$translated = [];
|
||||
foreach ($translatable as $key => $item) {
|
||||
if (!isset($active[$key])) {
|
||||
continue;
|
||||
@@ -296,10 +296,10 @@ class LocaleConfigManager {
|
||||
* @return array
|
||||
* Array of configuration object names.
|
||||
*/
|
||||
public function getComponentNames(array $components = array()) {
|
||||
public function getComponentNames(array $components = []) {
|
||||
$components = array_filter($components);
|
||||
if ($components) {
|
||||
$names = array();
|
||||
$names = [];
|
||||
foreach ($components as $type => $list) {
|
||||
// InstallStorage::getComponentNames returns a list of folders keyed by
|
||||
// config name.
|
||||
@@ -322,8 +322,8 @@ class LocaleConfigManager {
|
||||
* Array of configuration object names.
|
||||
*/
|
||||
public function getStringNames(array $lids) {
|
||||
$names = array();
|
||||
$locations = $this->localeStorage->getLocations(array('sid' => $lids, 'type' => 'configuration'));
|
||||
$names = [];
|
||||
$locations = $this->localeStorage->getLocations(['sid' => $lids, 'type' => 'configuration']);
|
||||
foreach ($locations as $location) {
|
||||
$names[$location->name] = $location->name;
|
||||
}
|
||||
@@ -370,15 +370,15 @@ class LocaleConfigManager {
|
||||
// If translations for a language have not been loaded yet.
|
||||
if (!isset($this->translations[$name][$langcode])) {
|
||||
// Preload all translations for this configuration name and language.
|
||||
$this->translations[$name][$langcode] = array();
|
||||
foreach ($this->localeStorage->getTranslations(array('language' => $langcode, 'type' => 'configuration', 'name' => $name)) as $string) {
|
||||
$this->translations[$name][$langcode] = [];
|
||||
foreach ($this->localeStorage->getTranslations(['language' => $langcode, 'type' => 'configuration', 'name' => $name]) as $string) {
|
||||
$this->translations[$name][$langcode][$string->context][$string->source] = $string;
|
||||
}
|
||||
}
|
||||
if (!isset($this->translations[$name][$langcode][$context][$source])) {
|
||||
// There is no translation of the source string in this config location
|
||||
// to this language for this context.
|
||||
if ($translation = $this->localeStorage->findTranslation(array('source' => $source, 'context' => $context, 'language' => $langcode))) {
|
||||
if ($translation = $this->localeStorage->findTranslation(['source' => $source, 'context' => $context, 'language' => $langcode])) {
|
||||
// Look for a translation of the string. It might have one, but not
|
||||
// be saved in this configuration location yet.
|
||||
// If the string has a translation for this context to this language,
|
||||
@@ -393,7 +393,7 @@ class LocaleConfigManager {
|
||||
// location so it can be translated, and the string is faster to look
|
||||
// for next time.
|
||||
$translation = $this->localeStorage
|
||||
->createString(array('source' => $source, 'context' => $context))
|
||||
->createString(['source' => $source, 'context' => $context])
|
||||
->addLocation('configuration', $name)
|
||||
->save();
|
||||
}
|
||||
@@ -418,7 +418,7 @@ class LocaleConfigManager {
|
||||
* @return $this
|
||||
*/
|
||||
public function reset() {
|
||||
$this->translations = array();
|
||||
$this->translations = [];
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -434,7 +434,7 @@ class LocaleConfigManager {
|
||||
* @param string $context
|
||||
* The string context.
|
||||
*
|
||||
* @return \Drupal\locale\TranslationString|FALSE
|
||||
* @return \Drupal\locale\TranslationString|false
|
||||
* The translation object if the string was not empty or FALSE otherwise.
|
||||
*/
|
||||
public function getStringTranslation($name, $langcode, $source, $context) {
|
||||
@@ -442,7 +442,7 @@ class LocaleConfigManager {
|
||||
$this->translateString($name, $langcode, $source, $context);
|
||||
if ($string = $this->translations[$name][$langcode][$context][$source]) {
|
||||
if (!$string->isTranslation()) {
|
||||
$conditions = array('lid' => $string->lid, 'language' => $langcode);
|
||||
$conditions = ['lid' => $string->lid, 'language' => $langcode];
|
||||
$translation = $this->localeStorage->createTranslation($conditions);
|
||||
$this->translations[$name][$langcode][$context][$source] = $translation;
|
||||
return $translation;
|
||||
@@ -564,7 +564,7 @@ class LocaleConfigManager {
|
||||
* Total number of configuration override and active configuration objects
|
||||
* updated (saved or removed).
|
||||
*/
|
||||
public function updateConfigTranslations(array $names, array $langcodes = array()) {
|
||||
public function updateConfigTranslations(array $names, array $langcodes = []) {
|
||||
$langcodes = $langcodes ? $langcodes : array_keys($this->languageManager->getLanguages());
|
||||
$count = 0;
|
||||
foreach ($names as $name) {
|
||||
@@ -589,7 +589,7 @@ class LocaleConfigManager {
|
||||
$data = $this->filterOverride($override->get(), $translatable);
|
||||
if (!empty($processed)) {
|
||||
// Merge in the Locale managed translations with existing data.
|
||||
$data = NestedArray::mergeDeepArray(array($data, $processed), TRUE);
|
||||
$data = NestedArray::mergeDeepArray([$data, $processed], TRUE);
|
||||
}
|
||||
if (empty($data) && !$override->isNew()) {
|
||||
// The configuration override contains Locale overrides that no
|
||||
@@ -607,7 +607,7 @@ class LocaleConfigManager {
|
||||
// If the language code is the active storage language, we should
|
||||
// update. If it is English, we should only update if English is also
|
||||
// translatable.
|
||||
$active = NestedArray::mergeDeepArray(array($active, $processed), TRUE);
|
||||
$active = NestedArray::mergeDeepArray([$active, $processed], TRUE);
|
||||
$this->saveTranslationActive($name, $active);
|
||||
$count++;
|
||||
}
|
||||
@@ -629,7 +629,7 @@ class LocaleConfigManager {
|
||||
* also in $translatable.
|
||||
*/
|
||||
protected function filterOverride(array $override_data, array $translatable) {
|
||||
$filtered_data = array();
|
||||
$filtered_data = [];
|
||||
foreach ($override_data as $key => $value) {
|
||||
if (isset($translatable[$key])) {
|
||||
// If the translatable default configuration has this key, look further
|
||||
|
||||
@@ -114,7 +114,7 @@ class LocaleConfigSubscriber implements EventSubscriberInterface {
|
||||
* override. This allows us to update locale keys for data not in the
|
||||
* override but still in the active configuration.
|
||||
*/
|
||||
protected function updateLocaleStorage(StorableConfigBase $config, $langcode, array $reference_config = array()) {
|
||||
protected function updateLocaleStorage(StorableConfigBase $config, $langcode, array $reference_config = []) {
|
||||
$name = $config->getName();
|
||||
if ($this->localeConfigManager->isSupported($name) && locale_is_translatable($langcode)) {
|
||||
$translatables = $this->localeConfigManager->getTranslatableDefaultConfig($name);
|
||||
@@ -139,7 +139,7 @@ class LocaleConfigSubscriber implements EventSubscriberInterface {
|
||||
* override. This allows us to update locale keys for data not in the
|
||||
* override but still in the active configuration.
|
||||
*/
|
||||
protected function processTranslatableData($name, array $config, array $translatable, $langcode, array $reference_config = array()) {
|
||||
protected function processTranslatableData($name, array $config, array $translatable, $langcode, array $reference_config = []) {
|
||||
foreach ($translatable as $key => $item) {
|
||||
if (!isset($config[$key])) {
|
||||
if (isset($reference_config[$key])) {
|
||||
@@ -148,7 +148,7 @@ class LocaleConfigSubscriber implements EventSubscriberInterface {
|
||||
continue;
|
||||
}
|
||||
if (is_array($item)) {
|
||||
$reference_config = isset($reference_config[$key]) ? $reference_config[$key] : array();
|
||||
$reference_config = isset($reference_config[$key]) ? $reference_config[$key] : [];
|
||||
$this->processTranslatableData($name, $config[$key], $item, $langcode, $reference_config);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -57,12 +57,12 @@ class LocaleDefaultConfigStorage {
|
||||
* @param \Drupal\language\ConfigurableLanguageManagerInterface $language_manager
|
||||
* The language manager.
|
||||
*/
|
||||
public function __construct(StorageInterface $config_storage, ConfigurableLanguageManagerInterface $language_manager) {
|
||||
public function __construct(StorageInterface $config_storage, ConfigurableLanguageManagerInterface $language_manager, $install_profile) {
|
||||
$this->configStorage = $config_storage;
|
||||
$this->languageManager = $language_manager;
|
||||
|
||||
$this->requiredInstallStorage = new ExtensionInstallStorage($this->configStorage);
|
||||
$this->optionalInstallStorage = new ExtensionInstallStorage($this->configStorage, ExtensionInstallStorage::CONFIG_OPTIONAL_DIRECTORY);
|
||||
$this->requiredInstallStorage = new ExtensionInstallStorage($this->configStorage, ExtensionInstallStorage::CONFIG_INSTALL_DIRECTORY, ExtensionInstallStorage::DEFAULT_COLLECTION, TRUE, $install_profile);
|
||||
$this->optionalInstallStorage = new ExtensionInstallStorage($this->configStorage, ExtensionInstallStorage::CONFIG_OPTIONAL_DIRECTORY, ExtensionInstallStorage::DEFAULT_COLLECTION, TRUE, $install_profile);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,7 @@ class LocaleEvent extends Event {
|
||||
* @param array $lids
|
||||
* (optional) List of string identifiers that have been updated / created.
|
||||
*/
|
||||
public function __construct(array $lang_codes, array $lids = array()) {
|
||||
public function __construct(array $lang_codes, array $lids = []) {
|
||||
$this->langCodes = $lang_codes;
|
||||
$this->lids = $lids;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ class LocaleLookup extends CacheCollector {
|
||||
|
||||
$this->cache = $cache;
|
||||
$this->lock = $lock;
|
||||
$this->tags = array('locale');
|
||||
$this->tags = ['locale'];
|
||||
$this->requestStack = $request_stack;
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ class LocaleLookup extends CacheCollector {
|
||||
// cache misses that need to be written into the cache. Prevent that by
|
||||
// resetting that list. All that happens in such a case are a few uncached
|
||||
// translation lookups.
|
||||
$this->keysToPersist = array();
|
||||
$this->keysToPersist = [];
|
||||
}
|
||||
return $this->cid;
|
||||
}
|
||||
@@ -132,11 +132,11 @@ class LocaleLookup extends CacheCollector {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function resolveCacheMiss($offset) {
|
||||
$translation = $this->stringStorage->findTranslation(array(
|
||||
$translation = $this->stringStorage->findTranslation([
|
||||
'language' => $this->langcode,
|
||||
'source' => $offset,
|
||||
'context' => $this->context,
|
||||
));
|
||||
]);
|
||||
|
||||
if ($translation) {
|
||||
$value = !empty($translation->translation) ? $translation->translation : TRUE;
|
||||
@@ -144,25 +144,25 @@ class LocaleLookup extends CacheCollector {
|
||||
else {
|
||||
// We don't have the source string, update the {locales_source} table to
|
||||
// indicate the string is not translated.
|
||||
$this->stringStorage->createString(array(
|
||||
$this->stringStorage->createString([
|
||||
'source' => $offset,
|
||||
'context' => $this->context,
|
||||
'version' => \Drupal::VERSION,
|
||||
))->addLocation('path', $this->requestStack->getCurrentRequest()->getRequestUri())->save();
|
||||
])->addLocation('path', $this->requestStack->getCurrentRequest()->getRequestUri())->save();
|
||||
$value = TRUE;
|
||||
}
|
||||
|
||||
// If there is no translation available for the current language then use
|
||||
// language fallback to try other translations.
|
||||
if ($value === TRUE) {
|
||||
$fallbacks = $this->languageManager->getFallbackCandidates(array('langcode' => $this->langcode, 'operation' => 'locale_lookup', 'data' => $offset));
|
||||
$fallbacks = $this->languageManager->getFallbackCandidates(['langcode' => $this->langcode, 'operation' => 'locale_lookup', 'data' => $offset]);
|
||||
if (!empty($fallbacks)) {
|
||||
foreach ($fallbacks as $langcode) {
|
||||
$translation = $this->stringStorage->findTranslation(array(
|
||||
$translation = $this->stringStorage->findTranslation([
|
||||
'language' => $langcode,
|
||||
'source' => $offset,
|
||||
'context' => $this->context,
|
||||
));
|
||||
]);
|
||||
|
||||
if ($translation && !empty($translation->translation)) {
|
||||
$value = $translation->translation;
|
||||
|
||||
@@ -21,7 +21,7 @@ class LocaleProjectStorage implements LocaleProjectStorageInterface {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $cache = array();
|
||||
protected $cache = [];
|
||||
|
||||
/**
|
||||
* Cache status flag.
|
||||
@@ -36,7 +36,7 @@ class LocaleProjectStorage implements LocaleProjectStorageInterface {
|
||||
* @param \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value_factory
|
||||
* The key value store to use.
|
||||
*/
|
||||
function __construct(KeyValueFactoryInterface $key_value_factory) {
|
||||
public function __construct(KeyValueFactoryInterface $key_value_factory) {
|
||||
$this->keyValueStore = $key_value_factory->get('locale.project');
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class LocaleProjectStorage implements LocaleProjectStorageInterface {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($key, $default = NULL) {
|
||||
$values = $this->getMultiple(array($key));
|
||||
$values = $this->getMultiple([$key]);
|
||||
return isset($values[$key]) ? $values[$key] : $default;
|
||||
}
|
||||
|
||||
@@ -52,8 +52,8 @@ class LocaleProjectStorage implements LocaleProjectStorageInterface {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMultiple(array $keys) {
|
||||
$values = array();
|
||||
$load = array();
|
||||
$values = [];
|
||||
$load = [];
|
||||
foreach ($keys as $key) {
|
||||
// Check if we have a value in the cache.
|
||||
if (isset($this->cache[$key])) {
|
||||
@@ -87,7 +87,7 @@ class LocaleProjectStorage implements LocaleProjectStorageInterface {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($key, $value) {
|
||||
$this->setMultiple(array($key => $value));
|
||||
$this->setMultiple([$key => $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +104,7 @@ class LocaleProjectStorage implements LocaleProjectStorageInterface {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($key) {
|
||||
$this->deleteMultiple(array($key));
|
||||
$this->deleteMultiple([$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,7 +121,7 @@ class LocaleProjectStorage implements LocaleProjectStorageInterface {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function resetCache() {
|
||||
$this->cache = array();
|
||||
$this->cache = [];
|
||||
static::$all = FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class LocaleTranslation implements TranslatorInterface, DestructableInterface {
|
||||
* Array of \Drupal\locale\LocaleLookup objects indexed by language code
|
||||
* and context.
|
||||
*/
|
||||
protected $translations = array();
|
||||
protected $translations = [];
|
||||
|
||||
/**
|
||||
* The cache backend that should be used.
|
||||
@@ -137,7 +137,7 @@ class LocaleTranslation implements TranslatorInterface, DestructableInterface {
|
||||
*/
|
||||
public function reset() {
|
||||
unset($this->translateEnglish);
|
||||
$this->translations = array();
|
||||
$this->translations = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -92,7 +92,7 @@ class PluralFormula implements PluralFormulaInterface {
|
||||
/**
|
||||
* Loads the formulae and stores them on the PluralFormula object if not set.
|
||||
*
|
||||
* @return []
|
||||
* @return array
|
||||
*/
|
||||
protected function loadFormulae() {
|
||||
if (!isset($this->formulae)) {
|
||||
|
||||
@@ -45,7 +45,7 @@ class PoDatabaseReader implements PoReaderInterface {
|
||||
* Constructor, initializes with default options.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->setOptions(array());
|
||||
$this->setOptions([]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,11 +73,11 @@ class PoDatabaseReader implements PoReaderInterface {
|
||||
* Set the options for the current reader.
|
||||
*/
|
||||
public function setOptions(array $options) {
|
||||
$options += array(
|
||||
$options += [
|
||||
'customized' => FALSE,
|
||||
'not_customized' => FALSE,
|
||||
'not_translated' => FALSE,
|
||||
);
|
||||
];
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ class PoDatabaseReader implements PoReaderInterface {
|
||||
private function loadStrings() {
|
||||
$langcode = $this->langcode;
|
||||
$options = $this->options;
|
||||
$conditions = array();
|
||||
$conditions = [];
|
||||
|
||||
if (array_sum($options) == 0) {
|
||||
// If user asked to not include anything in the translation files,
|
||||
|
||||
@@ -89,14 +89,14 @@ class PoDatabaseWriter implements PoWriterInterface {
|
||||
* @param array $report
|
||||
* Associative array with result information.
|
||||
*/
|
||||
public function setReport($report = array()) {
|
||||
$report += array(
|
||||
public function setReport($report = []) {
|
||||
$report += [
|
||||
'additions' => 0,
|
||||
'updates' => 0,
|
||||
'deletes' => 0,
|
||||
'skips' => 0,
|
||||
'strings' => array(),
|
||||
);
|
||||
'strings' => [],
|
||||
];
|
||||
$this->report = $report;
|
||||
}
|
||||
|
||||
@@ -112,15 +112,15 @@ class PoDatabaseWriter implements PoWriterInterface {
|
||||
*/
|
||||
public function setOptions(array $options) {
|
||||
if (!isset($options['overwrite_options'])) {
|
||||
$options['overwrite_options'] = array();
|
||||
$options['overwrite_options'] = [];
|
||||
}
|
||||
$options['overwrite_options'] += array(
|
||||
$options['overwrite_options'] += [
|
||||
'not_customized' => FALSE,
|
||||
'customized' => FALSE,
|
||||
);
|
||||
$options += array(
|
||||
];
|
||||
$options += [
|
||||
'customized' => LOCALE_NOT_CUSTOMIZED,
|
||||
);
|
||||
];
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ class PoDatabaseWriter implements PoWriterInterface {
|
||||
*/
|
||||
public function setHeader(PoHeader $header) {
|
||||
$this->header = $header;
|
||||
$locale_plurals = \Drupal::state()->get('locale.translation.plurals') ?: array();
|
||||
$locale_plurals = \Drupal::state()->get('locale.translation.plurals') ?: [];
|
||||
|
||||
// Check for options.
|
||||
$options = $this->getOptions();
|
||||
@@ -205,10 +205,10 @@ class PoDatabaseWriter implements PoWriterInterface {
|
||||
*/
|
||||
private function importString(PoItem $item) {
|
||||
// Initialize overwrite options if not set.
|
||||
$this->options['overwrite_options'] += array(
|
||||
$this->options['overwrite_options'] += [
|
||||
'not_customized' => FALSE,
|
||||
'customized' => FALSE,
|
||||
);
|
||||
];
|
||||
$overwrite_options = $this->options['overwrite_options'];
|
||||
$customized = $this->options['customized'];
|
||||
|
||||
@@ -217,17 +217,17 @@ class PoDatabaseWriter implements PoWriterInterface {
|
||||
$translation = $item->getTranslation();
|
||||
|
||||
// Look up the source string and any existing translation.
|
||||
$strings = \Drupal::service('locale.storage')->getTranslations(array(
|
||||
$strings = \Drupal::service('locale.storage')->getTranslations([
|
||||
'language' => $this->langcode,
|
||||
'source' => $source,
|
||||
'context' => $context,
|
||||
));
|
||||
]);
|
||||
$string = reset($strings);
|
||||
|
||||
if (!empty($translation)) {
|
||||
// Skip this string unless it passes a check for dangerous code.
|
||||
if (!locale_string_is_safe($translation)) {
|
||||
\Drupal::logger('locale')->error('Import of string "%string" was skipped because of disallowed or malformed HTML.', array('%string' => $translation));
|
||||
\Drupal::logger('locale')->error('Import of string "%string" was skipped because of disallowed or malformed HTML.', ['%string' => $translation]);
|
||||
$this->report['skips']++;
|
||||
return 0;
|
||||
}
|
||||
@@ -235,10 +235,10 @@ class PoDatabaseWriter implements PoWriterInterface {
|
||||
$string->setString($translation);
|
||||
if ($string->isNew()) {
|
||||
// No translation in this language.
|
||||
$string->setValues(array(
|
||||
$string->setValues([
|
||||
'language' => $this->langcode,
|
||||
'customized' => $customized,
|
||||
));
|
||||
]);
|
||||
$string->save();
|
||||
$this->report['additions']++;
|
||||
}
|
||||
@@ -253,14 +253,14 @@ class PoDatabaseWriter implements PoWriterInterface {
|
||||
}
|
||||
else {
|
||||
// No such source string in the database yet.
|
||||
$string = \Drupal::service('locale.storage')->createString(array('source' => $source, 'context' => $context))
|
||||
$string = \Drupal::service('locale.storage')->createString(['source' => $source, 'context' => $context])
|
||||
->save();
|
||||
\Drupal::service('locale.storage')->createTranslation(array(
|
||||
\Drupal::service('locale.storage')->createTranslation([
|
||||
'lid' => $string->getId(),
|
||||
'language' => $this->langcode,
|
||||
'translation' => $translation,
|
||||
'customized' => $customized,
|
||||
))->save();
|
||||
])->save();
|
||||
|
||||
$this->report['additions']++;
|
||||
$this->report['strings'][] = $string->getId();
|
||||
|
||||
@@ -36,7 +36,7 @@ class TranslationsStream extends LocalStream {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function getDirectoryPath() {
|
||||
public function getDirectoryPath() {
|
||||
return \Drupal::config('locale.settings')->get('translation.path');
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class TranslationsStream extends LocalStream {
|
||||
* @throws \LogicException
|
||||
* PO files URL should not be public.
|
||||
*/
|
||||
function getExternalUrl() {
|
||||
public function getExternalUrl() {
|
||||
throw new \LogicException('PO files URL should not be public.');
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ abstract class StringBase implements StringInterface {
|
||||
* @param object|array $values
|
||||
* Object or array with initial values.
|
||||
*/
|
||||
public function __construct($values = array()) {
|
||||
public function __construct($values = []) {
|
||||
$this->setValues((array) $values);
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ abstract class StringBase implements StringInterface {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getValues(array $fields) {
|
||||
$values = array();
|
||||
$values = [];
|
||||
foreach ($fields as $field) {
|
||||
if (isset($this->$field)) {
|
||||
$values[$field] = $this->$field;
|
||||
@@ -151,12 +151,12 @@ abstract class StringBase implements StringInterface {
|
||||
*/
|
||||
public function getLocations($check_only = FALSE) {
|
||||
if (!isset($this->locations) && !$check_only) {
|
||||
$this->locations = array();
|
||||
foreach ($this->getStorage()->getLocations(array('sid' => $this->getId())) as $location) {
|
||||
$this->locations = [];
|
||||
foreach ($this->getStorage()->getLocations(['sid' => $this->getId()]) as $location) {
|
||||
$this->locations[$location->type][$location->name] = $location->lid;
|
||||
}
|
||||
}
|
||||
return isset($this->locations) ? $this->locations : array();
|
||||
return isset($this->locations) ? $this->locations : [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,7 +21,7 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
protected $options = [];
|
||||
|
||||
/**
|
||||
* Constructs a new StringDatabaseStorage class.
|
||||
@@ -31,7 +31,7 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
* @param array $options
|
||||
* (optional) Any additional database connection options to use in queries.
|
||||
*/
|
||||
public function __construct(Connection $connection, array $options = array()) {
|
||||
public function __construct(Connection $connection, array $options = []) {
|
||||
$this->connection = $connection;
|
||||
$this->options = $options;
|
||||
}
|
||||
@@ -39,15 +39,15 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getStrings(array $conditions = array(), array $options = array()) {
|
||||
public function getStrings(array $conditions = [], array $options = []) {
|
||||
return $this->dbStringLoad($conditions, $options, 'Drupal\locale\SourceString');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTranslations(array $conditions = array(), array $options = array()) {
|
||||
return $this->dbStringLoad($conditions, array('translation' => TRUE) + $options, 'Drupal\locale\TranslationString');
|
||||
public function getTranslations(array $conditions = [], array $options = []) {
|
||||
return $this->dbStringLoad($conditions, ['translation' => TRUE] + $options, 'Drupal\locale\TranslationString');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +69,7 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function findTranslation(array $conditions) {
|
||||
$values = $this->dbStringSelect($conditions, array('translation' => TRUE))
|
||||
$values = $this->dbStringSelect($conditions, ['translation' => TRUE])
|
||||
->execute()
|
||||
->fetchAssoc();
|
||||
|
||||
@@ -84,7 +84,7 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getLocations(array $conditions = array()) {
|
||||
public function getLocations(array $conditions = []) {
|
||||
$query = $this->connection->select('locales_location', 'l', $this->options)
|
||||
->fields('l');
|
||||
foreach ($conditions as $field => $value) {
|
||||
@@ -142,14 +142,14 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
// Make sure that the name isn't longer than 255 characters.
|
||||
$name = substr($name, 0, 255);
|
||||
if (!$lid) {
|
||||
$this->dbDelete('locales_location', array('sid' => $string->getId(), 'type' => $type, 'name' => $name))
|
||||
$this->dbDelete('locales_location', ['sid' => $string->getId(), 'type' => $type, 'name' => $name])
|
||||
->execute();
|
||||
}
|
||||
elseif ($lid === TRUE) {
|
||||
// This is a new location to add, take care not to duplicate.
|
||||
$this->connection->merge('locales_location', $this->options)
|
||||
->keys(array('sid' => $string->getId(), 'type' => $type, 'name' => $name))
|
||||
->fields(array('version' => \Drupal::VERSION))
|
||||
->keys(['sid' => $string->getId(), 'type' => $type, 'name' => $name])
|
||||
->fields(['version' => \Drupal::VERSION])
|
||||
->execute();
|
||||
$created = TRUE;
|
||||
}
|
||||
@@ -175,9 +175,9 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
if ($string->getId() && $string->getVersion() != $version) {
|
||||
$string->setVersion($version);
|
||||
$this->connection->update('locales_source', $this->options)
|
||||
->condition('lid', $string->getId())
|
||||
->fields(array('version' => $version))
|
||||
->execute();
|
||||
->condition('lid', $string->getId())
|
||||
->fields(['version' => $version])
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,11 +203,11 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteStrings($conditions) {
|
||||
$lids = $this->dbStringSelect($conditions, array('fields' => array('lid')))->execute()->fetchCol();
|
||||
$lids = $this->dbStringSelect($conditions, ['fields' => ['lid']])->execute()->fetchCol();
|
||||
if ($lids) {
|
||||
$this->dbDelete('locales_target', array('lid' => $lids))->execute();
|
||||
$this->dbDelete('locales_source', array('lid' => $lids))->execute();
|
||||
$this->dbDelete('locales_location', array('sid' => $lids))->execute();
|
||||
$this->dbDelete('locales_target', ['lid' => $lids])->execute();
|
||||
$this->dbDelete('locales_source', ['lid' => $lids])->execute();
|
||||
$this->dbDelete('locales_location', ['sid' => $lids])->execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,18 +221,18 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createString($values = array()) {
|
||||
return new SourceString($values + array('storage' => $this));
|
||||
public function createString($values = []) {
|
||||
return new SourceString($values + ['storage' => $this]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createTranslation($values = array()) {
|
||||
return new TranslationString($values + array(
|
||||
public function createTranslation($values = []) {
|
||||
return new TranslationString($values + [
|
||||
'storage' => $this,
|
||||
'is_new' => TRUE,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,10 +250,10 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
* table fields)
|
||||
*/
|
||||
protected function dbFieldTable($field) {
|
||||
if (in_array($field, array('language', 'translation', 'customized'))) {
|
||||
if (in_array($field, ['language', 'translation', 'customized'])) {
|
||||
return 't';
|
||||
}
|
||||
elseif (in_array($field, array('type', 'name'))) {
|
||||
elseif (in_array($field, ['type', 'name'])) {
|
||||
return 'l';
|
||||
}
|
||||
else {
|
||||
@@ -290,16 +290,16 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
*/
|
||||
protected function dbStringKeys($string) {
|
||||
if ($string->isSource()) {
|
||||
$keys = array('lid');
|
||||
$keys = ['lid'];
|
||||
}
|
||||
elseif ($string->isTranslation()) {
|
||||
$keys = array('lid', 'language');
|
||||
$keys = ['lid', 'language'];
|
||||
}
|
||||
if (!empty($keys) && ($values = $string->getValues($keys)) && count($keys) == count($values)) {
|
||||
return $values;
|
||||
}
|
||||
else {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
* Array of objects of the class requested.
|
||||
*/
|
||||
protected function dbStringLoad(array $conditions, array $options, $class) {
|
||||
$strings = array();
|
||||
$strings = [];
|
||||
$result = $this->dbStringSelect($conditions, $options)->execute();
|
||||
foreach ($result as $item) {
|
||||
/** @var \Drupal\locale\StringInterface $string */
|
||||
@@ -349,7 +349,7 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
* @return \Drupal\Core\Database\Query\Select
|
||||
* Query object with all the tables, fields and conditions.
|
||||
*/
|
||||
protected function dbStringSelect(array $conditions, array $options = array()) {
|
||||
protected function dbStringSelect(array $conditions, array $options = []) {
|
||||
// Start building the query with source table and check whether we need to
|
||||
// join the target table too.
|
||||
$query = $this->connection->select('locales_source', 's', $this->options)
|
||||
@@ -376,9 +376,9 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
if ($join) {
|
||||
if (isset($conditions['language'])) {
|
||||
// If we've got a language condition, we use it for the join.
|
||||
$query->$join('locales_target', 't', "t.lid = s.lid AND t.language = :langcode", array(
|
||||
$query->$join('locales_target', 't', "t.lid = s.lid AND t.language = :langcode", [
|
||||
':langcode' => $conditions['language'],
|
||||
));
|
||||
]);
|
||||
unset($conditions['language']);
|
||||
}
|
||||
else {
|
||||
@@ -387,7 +387,7 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
}
|
||||
if (!empty($options['translation'])) {
|
||||
// We cannot just add all fields because 'lid' may get null values.
|
||||
$query->fields('t', array('language', 'translation', 'customized'));
|
||||
$query->fields('t', ['language', 'translation', 'customized']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,8 +396,8 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
// array so we can consistently use IN conditions.
|
||||
if (isset($conditions['type']) || isset($conditions['name'])) {
|
||||
$subquery = $this->connection->select('locales_location', 'l', $this->options)
|
||||
->fields('l', array('sid'));
|
||||
foreach (array('type', 'name') as $field) {
|
||||
->fields('l', ['sid']);
|
||||
foreach (['type', 'name'] as $field) {
|
||||
if (isset($conditions[$field])) {
|
||||
$subquery->condition('l.' . $field, (array) $conditions[$field], 'IN');
|
||||
unset($conditions[$field]);
|
||||
@@ -417,8 +417,8 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
// Conditions for target fields when doing an outer join only make
|
||||
// sense if we add also OR field IS NULL.
|
||||
$query->condition(db_or()
|
||||
->condition($field_alias, (array) $value, 'IN')
|
||||
->isNull($field_alias)
|
||||
->condition($field_alias, (array) $value, 'IN')
|
||||
->isNull($field_alias)
|
||||
);
|
||||
}
|
||||
else {
|
||||
@@ -463,12 +463,12 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
*/
|
||||
protected function dbStringInsert($string) {
|
||||
if ($string->isSource()) {
|
||||
$string->setValues(array('context' => '', 'version' => 'none'), FALSE);
|
||||
$fields = $string->getValues(array('source', 'context', 'version'));
|
||||
$string->setValues(['context' => '', 'version' => 'none'], FALSE);
|
||||
$fields = $string->getValues(['source', 'context', 'version']);
|
||||
}
|
||||
elseif ($string->isTranslation()) {
|
||||
$string->setValues(array('customized' => 0), FALSE);
|
||||
$fields = $string->getValues(array('lid', 'language', 'translation', 'customized'));
|
||||
$string->setValues(['customized' => 0], FALSE);
|
||||
$fields = $string->getValues(['lid', 'language', 'translation', 'customized']);
|
||||
}
|
||||
if (!empty($fields)) {
|
||||
return $this->connection->insert($this->dbStringTable($string), $this->options)
|
||||
@@ -495,10 +495,10 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
*/
|
||||
protected function dbStringUpdate($string) {
|
||||
if ($string->isSource()) {
|
||||
$values = $string->getValues(array('source', 'context', 'version'));
|
||||
$values = $string->getValues(['source', 'context', 'version']);
|
||||
}
|
||||
elseif ($string->isTranslation()) {
|
||||
$values = $string->getValues(array('translation', 'customized'));
|
||||
$values = $string->getValues(['translation', 'customized']);
|
||||
}
|
||||
if (!empty($values) && $keys = $this->dbStringKeys($string)) {
|
||||
return $this->connection->merge($this->dbStringTable($string), $this->options)
|
||||
@@ -533,7 +533,7 @@ class StringDatabaseStorage implements StringStorageInterface {
|
||||
/**
|
||||
* Executes an arbitrary SELECT query string with the injected options.
|
||||
*/
|
||||
protected function dbExecute($query, array $args = array()) {
|
||||
protected function dbExecute($query, array $args = []) {
|
||||
return $this->connection->query($query, $args, $this->options);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ interface StringStorageInterface {
|
||||
* @return array
|
||||
* Array of \Drupal\locale\StringInterface objects matching the conditions.
|
||||
*/
|
||||
public function getStrings(array $conditions = array(), array $options = array());
|
||||
public function getStrings(array $conditions = [], array $options = []);
|
||||
|
||||
/**
|
||||
* Loads multiple string translation objects.
|
||||
@@ -44,7 +44,7 @@ interface StringStorageInterface {
|
||||
*
|
||||
* @see \Drupal\locale\StringStorageInterface::getStrings()
|
||||
*/
|
||||
public function getTranslations(array $conditions = array(), array $options = array());
|
||||
public function getTranslations(array $conditions = [], array $options = []);
|
||||
|
||||
/**
|
||||
* Loads string location information.
|
||||
@@ -61,7 +61,7 @@ interface StringStorageInterface {
|
||||
*
|
||||
* @see \Drupal\locale\StringStorageInterface::getStrings()
|
||||
*/
|
||||
public function getLocations(array $conditions = array());
|
||||
public function getLocations(array $conditions = []);
|
||||
|
||||
/**
|
||||
* Loads a string source object, fast query.
|
||||
@@ -164,7 +164,7 @@ interface StringStorageInterface {
|
||||
* @return \Drupal\locale\SourceString
|
||||
* New source string object.
|
||||
*/
|
||||
public function createString($values = array());
|
||||
public function createString($values = []);
|
||||
|
||||
/**
|
||||
* Creates a string translation object bound to this storage but not saved.
|
||||
@@ -175,6 +175,6 @@ interface StringStorageInterface {
|
||||
* @return \Drupal\locale\TranslationString
|
||||
* New string translation object.
|
||||
*/
|
||||
public function createTranslation($values = array());
|
||||
public function createTranslation($values = []);
|
||||
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class TranslationString extends StringBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct($values = array()) {
|
||||
public function __construct($values = []) {
|
||||
parent::__construct($values);
|
||||
if (!isset($this->isNew)) {
|
||||
// We mark the string as not new if it is a complete translation.
|
||||
|
||||
Reference in New Issue
Block a user