Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -116,11 +116,11 @@
|
|||
*/
|
||||
function hook_locale_translation_projects_alter(&$projects) {
|
||||
// The translations are located at a custom translation sever.
|
||||
$projects['existing_project'] = array(
|
||||
'info' => array(
|
||||
$projects['existing_project'] = [
|
||||
'info' => [
|
||||
'interface translation server pattern' => 'http://example.com/files/translations/%core/%project/%project-%version.%language.po',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,16 +33,16 @@ require_once __DIR__ . '/locale.translation.inc';
|
|||
* batch is finished. Optional, defaults to TRUE.
|
||||
* - 'use_remote': Whether or not to check the remote translation file.
|
||||
* Optional, defaults to TRUE.
|
||||
* @param array|\ArrayAccess $context.
|
||||
* @param array|\ArrayAccess $context
|
||||
* The batch context.
|
||||
*/
|
||||
function locale_translation_batch_status_check($project, $langcode, array $options, &$context) {
|
||||
$failure = $checked = FALSE;
|
||||
$options += array(
|
||||
$options += [
|
||||
'finish_feedback' => TRUE,
|
||||
'use_remote' => TRUE,
|
||||
);
|
||||
$source = locale_translation_get_status(array($project), array($langcode));
|
||||
];
|
||||
$source = locale_translation_get_status([$project], [$langcode]);
|
||||
$source = $source[$project][$langcode];
|
||||
|
||||
// Check the status of local translation files.
|
||||
|
@ -82,7 +82,7 @@ function locale_translation_batch_status_check($project, $langcode, array $optio
|
|||
if ($failure && !$checked) {
|
||||
$context['results']['failed_files'][] = $source->name;
|
||||
}
|
||||
$context['message'] = t('Checked translation for %project.', array('%project' => $source->project));
|
||||
$context['message'] = t('Checked translation for %project.', ['%project' => $source->project]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,7 +99,7 @@ function locale_translation_batch_status_finished($success, $results) {
|
|||
if ($success) {
|
||||
if (isset($results['failed_files'])) {
|
||||
if (\Drupal::moduleHandler()->moduleExists('dblog') && \Drupal::currentUser()->hasPermission('access site reports')) {
|
||||
$message = \Drupal::translation()->formatPlural(count($results['failed_files']), 'One translation file could not be checked. <a href=":url">See the log</a> for details.', '@count translation files could not be checked. <a href=":url">See the log</a> for details.', array(':url' => \Drupal::url('dblog.overview')));
|
||||
$message = \Drupal::translation()->formatPlural(count($results['failed_files']), 'One translation file could not be checked. <a href=":url">See the log</a> for details.', '@count translation files could not be checked. <a href=":url">See the log</a> for details.', [':url' => \Drupal::url('dblog.overview')]);
|
||||
}
|
||||
else {
|
||||
$message = \Drupal::translation()->formatPlural(count($results['failed_files']), 'One translation files could not be checked. See the log for details.', '@count translation files could not be checked. See the log for details.');
|
||||
|
@ -139,12 +139,12 @@ function locale_translation_batch_status_finished($success, $results) {
|
|||
* @see locale_translation_batch_fetch_import()
|
||||
*/
|
||||
function locale_translation_batch_fetch_download($project, $langcode, &$context) {
|
||||
$sources = locale_translation_get_status(array($project), array($langcode));
|
||||
$sources = locale_translation_get_status([$project], [$langcode]);
|
||||
if (isset($sources[$project][$langcode])) {
|
||||
$source = $sources[$project][$langcode];
|
||||
if (isset($source->type) && $source->type == LOCALE_TRANSLATION_REMOTE) {
|
||||
if ($file = locale_translation_download_source($source->files[LOCALE_TRANSLATION_REMOTE], 'translations://')) {
|
||||
$context['message'] = t('Downloaded translation for %project.', array('%project' => $source->project));
|
||||
$context['message'] = t('Downloaded translation for %project.', ['%project' => $source->project]);
|
||||
locale_translation_status_save($source->name, $source->langcode, LOCALE_TRANSLATION_LOCAL, $file);
|
||||
}
|
||||
else {
|
||||
|
@ -173,16 +173,16 @@ function locale_translation_batch_fetch_download($project, $langcode, &$context)
|
|||
* @see locale_translation_batch_fetch_download()
|
||||
*/
|
||||
function locale_translation_batch_fetch_import($project, $langcode, $options, &$context) {
|
||||
$sources = locale_translation_get_status(array($project), array($langcode));
|
||||
$sources = locale_translation_get_status([$project], [$langcode]);
|
||||
if (isset($sources[$project][$langcode])) {
|
||||
$source = $sources[$project][$langcode];
|
||||
if (isset($source->type)) {
|
||||
if ($source->type == LOCALE_TRANSLATION_REMOTE || $source->type == LOCALE_TRANSLATION_LOCAL) {
|
||||
$file = $source->files[LOCALE_TRANSLATION_LOCAL];
|
||||
module_load_include('bulk.inc', 'locale');
|
||||
$options += array(
|
||||
'message' => t('Importing translation for %project.', array('%project' => $source->project)),
|
||||
);
|
||||
$options += [
|
||||
'message' => t('Importing translation for %project.', ['%project' => $source->project]),
|
||||
];
|
||||
// Import the translation file. For large files the batch operations is
|
||||
// progressive and will be called repeatedly until finished.
|
||||
locale_translate_batch_import($file, $options, $context);
|
||||
|
@ -191,7 +191,7 @@ function locale_translation_batch_fetch_import($project, $langcode, $options, &$
|
|||
if (isset($context['finished']) && $context['finished'] == 1) {
|
||||
// The import is successful.
|
||||
if (isset($context['results']['files'][$file->uri])) {
|
||||
$context['message'] = t('Imported translation for %project.', array('%project' => $source->project));
|
||||
$context['message'] = t('Imported translation for %project.', ['%project' => $source->project]);
|
||||
|
||||
// Save the data of imported source into the {locale_file} table and
|
||||
// update the current translation status.
|
||||
|
@ -243,7 +243,7 @@ function locale_translation_http_check($uri) {
|
|||
$actual_uri = (string) $request_uri;
|
||||
}
|
||||
]])->head($uri);
|
||||
$result = array();
|
||||
$result = [];
|
||||
|
||||
// Return the effective URL if it differs from the requested.
|
||||
if ($actual_uri && $actual_uri !== $uri) {
|
||||
|
@ -262,10 +262,10 @@ function locale_translation_http_check($uri) {
|
|||
// theme does not define the location of a translation file. By default
|
||||
// the file is checked at the translation server, but it will not be
|
||||
// found there.
|
||||
$logger->notice('Translation file not found: @uri.', array('@uri' => $uri));
|
||||
$logger->notice('Translation file not found: @uri.', ['@uri' => $uri]);
|
||||
return TRUE;
|
||||
}
|
||||
$logger->notice('HTTP request to @url failed with error: @error.', array('@url' => $uri, '@error' => $response->getStatusCode() . ' ' . $response->getReasonPhrase()));
|
||||
$logger->notice('HTTP request to @url failed with error: @error.', ['@url' => $uri, '@error' => $response->getStatusCode() . ' ' . $response->getReasonPhrase()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -298,6 +298,6 @@ function locale_translation_download_source($source_file, $directory = 'temporar
|
|||
$file->timestamp = filemtime($uri);
|
||||
return $file;
|
||||
}
|
||||
\Drupal::logger('locale')->error('Unable to download translation file @uri.', array('@uri' => $source_file->uri));
|
||||
\Drupal::logger('locale')->error('Unable to download translation file @uri.', ['@uri' => $source_file->uri]);
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
@ -37,14 +37,14 @@ use Drupal\locale\Locale;
|
|||
* See https://www.drupal.org/node/1191488.
|
||||
*/
|
||||
function locale_translate_batch_import_files(array $options, $force = FALSE) {
|
||||
$options += array(
|
||||
'overwrite_options' => array(),
|
||||
$options += [
|
||||
'overwrite_options' => [],
|
||||
'customized' => LOCALE_NOT_CUSTOMIZED,
|
||||
'finish_feedback' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
if (!empty($options['langcode'])) {
|
||||
$langcodes = array($options['langcode']);
|
||||
$langcodes = [$options['langcode']];
|
||||
}
|
||||
else {
|
||||
// If langcode was not provided, make sure to only import files for the
|
||||
|
@ -52,11 +52,11 @@ function locale_translate_batch_import_files(array $options, $force = FALSE) {
|
|||
$langcodes = array_keys(\Drupal::languageManager()->getLanguages());
|
||||
}
|
||||
|
||||
$files = locale_translate_get_interface_translation_files(array(), $langcodes);
|
||||
$files = locale_translate_get_interface_translation_files([], $langcodes);
|
||||
|
||||
if (!$force) {
|
||||
$result = db_select('locale_file', 'lf')
|
||||
->fields('lf', array('langcode', 'uri', 'timestamp'))
|
||||
->fields('lf', ['langcode', 'uri', 'timestamp'])
|
||||
->condition('langcode', $langcodes)
|
||||
->execute()
|
||||
->fetchAllAssoc('uri');
|
||||
|
@ -84,9 +84,9 @@ function locale_translate_batch_import_files(array $options, $force = FALSE) {
|
|||
* @return array
|
||||
* An array of interface translation files keyed by their URI.
|
||||
*/
|
||||
function locale_translate_get_interface_translation_files(array $projects = array(), array $langcodes = array()) {
|
||||
function locale_translate_get_interface_translation_files(array $projects = [], array $langcodes = []) {
|
||||
module_load_include('compare.inc', 'locale');
|
||||
$files = array();
|
||||
$files = [];
|
||||
$projects = $projects ? $projects : array_keys(locale_translation_get_projects());
|
||||
$langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list());
|
||||
|
||||
|
@ -95,7 +95,7 @@ function locale_translate_get_interface_translation_files(array $projects = arra
|
|||
// {project}-{version}.{langcode}.po.
|
||||
// Only files of known projects and languages will be returned.
|
||||
$directory = \Drupal::config('locale.settings')->get('translation.path');
|
||||
$result = file_scan_directory($directory, '![a-z_]+(\-[0-9a-z\.\-\+]+|)\.[^\./]+\.po$!', array('recurse' => FALSE));
|
||||
$result = file_scan_directory($directory, '![a-z_]+(\-[0-9a-z\.\-\+]+|)\.[^\./]+\.po$!', ['recurse' => FALSE]);
|
||||
|
||||
foreach ($result as $file) {
|
||||
// Update the file object with project name and version from the file name.
|
||||
|
@ -132,30 +132,30 @@ function locale_translate_get_interface_translation_files(array $projects = arra
|
|||
* A batch structure or FALSE if $files was empty.
|
||||
*/
|
||||
function locale_translate_batch_build(array $files, array $options) {
|
||||
$options += array(
|
||||
'overwrite_options' => array(),
|
||||
$options += [
|
||||
'overwrite_options' => [],
|
||||
'customized' => LOCALE_NOT_CUSTOMIZED,
|
||||
'finish_feedback' => TRUE,
|
||||
);
|
||||
];
|
||||
if (count($files)) {
|
||||
$operations = array();
|
||||
$operations = [];
|
||||
foreach ($files as $file) {
|
||||
// We call locale_translate_batch_import for every batch operation.
|
||||
$operations[] = array('locale_translate_batch_import', array($file, $options));
|
||||
$operations[] = ['locale_translate_batch_import', [$file, $options]];
|
||||
}
|
||||
// Save the translation status of all files.
|
||||
$operations[] = array('locale_translate_batch_import_save', array());
|
||||
$operations[] = ['locale_translate_batch_import_save', []];
|
||||
|
||||
// Add a final step to refresh JavaScript and configuration strings.
|
||||
$operations[] = array('locale_translate_batch_refresh', array());
|
||||
$operations[] = ['locale_translate_batch_refresh', []];
|
||||
|
||||
$batch = array(
|
||||
$batch = [
|
||||
'operations' => $operations,
|
||||
'title' => t('Importing interface translations'),
|
||||
'progress_message' => '',
|
||||
'error_message' => t('Error importing interface translations'),
|
||||
'file' => drupal_get_path('module', 'locale') . '/locale.bulk.inc',
|
||||
);
|
||||
];
|
||||
if ($options['finish_feedback']) {
|
||||
$batch['finished'] = 'locale_translate_batch_finished';
|
||||
}
|
||||
|
@ -185,25 +185,25 @@ function locale_translate_batch_build(array $files, array $options) {
|
|||
* LOCALE_NOT_CUSTOMIZED.
|
||||
* - 'message': Alternative message to display during import. Note, this must
|
||||
* be sanitized text.
|
||||
* @param array|\ArrayAccess $context.
|
||||
* @param array|\ArrayAccess $context
|
||||
* Contains a list of files imported.
|
||||
*/
|
||||
function locale_translate_batch_import($file, array $options, &$context) {
|
||||
// Merge the default values in the $options array.
|
||||
$options += array(
|
||||
'overwrite_options' => array(),
|
||||
$options += [
|
||||
'overwrite_options' => [],
|
||||
'customized' => LOCALE_NOT_CUSTOMIZED,
|
||||
);
|
||||
];
|
||||
|
||||
if (isset($file->langcode) && $file->langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED) {
|
||||
|
||||
try {
|
||||
if (empty($context['sandbox'])) {
|
||||
$context['sandbox']['parse_state'] = array(
|
||||
$context['sandbox']['parse_state'] = [
|
||||
'filesize' => filesize(drupal_realpath($file->uri)),
|
||||
'chunk_size' => 200,
|
||||
'seek' => 0,
|
||||
);
|
||||
];
|
||||
}
|
||||
// Update the seek and the number of items in the $options array().
|
||||
$options['seek'] = $context['sandbox']['parse_state']['seek'];
|
||||
|
@ -220,10 +220,10 @@ function locale_translate_batch_import($file, array $options, &$context) {
|
|||
// https://www.drupal.org/node/1089472.
|
||||
$context['finished'] = min(0.95, $report['seek'] / filesize($file->uri));
|
||||
if (isset($options['message'])) {
|
||||
$context['message'] = t('@message (@percent%).', array('@message' => $options['message'], '@percent' => (int) ($context['finished'] * 100)));
|
||||
$context['message'] = t('@message (@percent%).', ['@message' => $options['message'], '@percent' => (int) ($context['finished'] * 100)]);
|
||||
}
|
||||
else {
|
||||
$context['message'] = t('Importing translation file: %filename (@percent%).', array('%filename' => $file->filename, '@percent' => (int) ($context['finished'] * 100)));
|
||||
$context['message'] = t('Importing translation file: %filename (@percent%).', ['%filename' => $file->filename, '@percent' => (int) ($context['finished'] * 100)]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -240,7 +240,7 @@ function locale_translate_batch_import($file, array $options, &$context) {
|
|||
// Each import iteration reports statistics in an array. The results of
|
||||
// each iteration are added and merged here and stored per file.
|
||||
if (!isset($context['results']['stats']) || !isset($context['results']['stats'][$file->uri])) {
|
||||
$context['results']['stats'][$file->uri] = array();
|
||||
$context['results']['stats'][$file->uri] = [];
|
||||
}
|
||||
foreach ($report as $key => $value) {
|
||||
if (is_numeric($report[$key])) {
|
||||
|
@ -250,7 +250,7 @@ function locale_translate_batch_import($file, array $options, &$context) {
|
|||
$context['results']['stats'][$file->uri][$key] += $report[$key];
|
||||
}
|
||||
elseif (is_array($value)) {
|
||||
$context['results']['stats'][$file->uri] += array($key => array());
|
||||
$context['results']['stats'][$file->uri] += [$key => []];
|
||||
$context['results']['stats'][$file->uri][$key] = array_merge($context['results']['stats'][$file->uri][$key], $value);
|
||||
}
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ function locale_translate_batch_import($file, array $options, &$context) {
|
|||
catch (Exception $exception) {
|
||||
// Import failed. Store the data of the failing file.
|
||||
$context['results']['failed_files'][] = $file;
|
||||
\Drupal::logger('locale')->notice('Unable to import translations file: @file', array('@file' => $file->uri));
|
||||
\Drupal::logger('locale')->notice('Unable to import translations file: @file', ['@file' => $file->uri]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ function locale_translate_batch_import($file, array $options, &$context) {
|
|||
*
|
||||
* Save data of imported files.
|
||||
*
|
||||
* @param array|\ArrayAccess $context.
|
||||
* @param array|\ArrayAccess $context
|
||||
* Contains a list of imported files.
|
||||
*/
|
||||
function locale_translate_batch_import_save($context) {
|
||||
|
@ -293,12 +293,12 @@ function locale_translate_batch_import_save($context) {
|
|||
*
|
||||
* Refreshes translations after importing strings.
|
||||
*
|
||||
* @param array|\ArrayAccess $context.
|
||||
* @param array|\ArrayAccess $context
|
||||
* Contains a list of strings updated and information about the progress.
|
||||
*/
|
||||
function locale_translate_batch_refresh(&$context) {
|
||||
if (!isset($context['sandbox']['refresh'])) {
|
||||
$strings = $langcodes = array();
|
||||
$strings = $langcodes = [];
|
||||
if (isset($context['results']['stats'])) {
|
||||
// Get list of unique string identifiers and language codes updated.
|
||||
$langcodes = array_unique(array_values($context['results']['languages']));
|
||||
|
@ -311,7 +311,7 @@ function locale_translate_batch_refresh(&$context) {
|
|||
$context['message'] = t('Updating translations for JavaScript and default configuration.');
|
||||
$context['sandbox']['refresh']['strings'] = array_unique($strings);
|
||||
$context['sandbox']['refresh']['languages'] = $langcodes;
|
||||
$context['sandbox']['refresh']['names'] = array();
|
||||
$context['sandbox']['refresh']['names'] = [];
|
||||
$context['results']['stats']['config'] = 0;
|
||||
$context['sandbox']['refresh']['count'] = count($strings);
|
||||
|
||||
|
@ -324,12 +324,12 @@ function locale_translate_batch_refresh(&$context) {
|
|||
}
|
||||
elseif ($name = array_shift($context['sandbox']['refresh']['names'])) {
|
||||
// Refresh all languages for one object at a time.
|
||||
$count = Locale::config()->updateConfigTranslations(array($name), $context['sandbox']['refresh']['languages']);
|
||||
$count = Locale::config()->updateConfigTranslations([$name], $context['sandbox']['refresh']['languages']);
|
||||
$context['results']['stats']['config'] += $count;
|
||||
// Inherit finished information from the "parent" string lookup step so
|
||||
// visual display of status will make sense.
|
||||
$context['finished'] = $context['sandbox']['refresh']['names_finished'];
|
||||
$context['message'] = t('Updating default configuration (@percent%).', array('@percent' => (int) ($context['finished'] * 100)));
|
||||
$context['message'] = t('Updating default configuration (@percent%).', ['@percent' => (int) ($context['finished'] * 100)]);
|
||||
}
|
||||
elseif (!empty($context['sandbox']['refresh']['strings'])) {
|
||||
// Not perfect but will give some indication of progress.
|
||||
|
@ -367,7 +367,7 @@ function locale_translate_batch_finished($success, array $results) {
|
|||
$additions = $updates = $deletes = $skips = $config = 0;
|
||||
if (isset($results['failed_files'])) {
|
||||
if (\Drupal::moduleHandler()->moduleExists('dblog') && \Drupal::currentUser()->hasPermission('access site reports')) {
|
||||
$message = \Drupal::translation()->formatPlural(count($results['failed_files']), 'One translation file could not be imported. <a href=":url">See the log</a> for details.', '@count translation files could not be imported. <a href=":url">See the log</a> for details.', array(':url' => \Drupal::url('dblog.overview')));
|
||||
$message = \Drupal::translation()->formatPlural(count($results['failed_files']), 'One translation file could not be imported. <a href=":url">See the log</a> for details.', '@count translation files could not be imported. <a href=":url">See the log</a> for details.', [':url' => \Drupal::url('dblog.overview')]);
|
||||
}
|
||||
else {
|
||||
$message = \Drupal::translation()->formatPlural(count($results['failed_files']), 'One translation file could not be imported. See the log for details.', '@count translation files could not be imported. See the log for details.');
|
||||
|
@ -375,7 +375,7 @@ function locale_translate_batch_finished($success, array $results) {
|
|||
drupal_set_message($message, 'error');
|
||||
}
|
||||
if (isset($results['files'])) {
|
||||
$skipped_files = array();
|
||||
$skipped_files = [];
|
||||
// If there are no results and/or no stats (eg. coping with an empty .po
|
||||
// file), simply do nothing.
|
||||
if ($results && isset($results['stats'])) {
|
||||
|
@ -392,19 +392,19 @@ function locale_translate_batch_finished($success, array $results) {
|
|||
drupal_set_message(\Drupal::translation()->formatPlural(count($results['files']),
|
||||
'One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.',
|
||||
'@count translation files imported. %number translations were added, %update translations were updated and %delete translations were removed.',
|
||||
array('%number' => $additions, '%update' => $updates, '%delete' => $deletes)
|
||||
['%number' => $additions, '%update' => $updates, '%delete' => $deletes]
|
||||
));
|
||||
$logger->notice('Translations imported: %number added, %update updated, %delete removed.', array('%number' => $additions, '%update' => $updates, '%delete' => $deletes));
|
||||
$logger->notice('Translations imported: %number added, %update updated, %delete removed.', ['%number' => $additions, '%update' => $updates, '%delete' => $deletes]);
|
||||
|
||||
if ($skips) {
|
||||
if (\Drupal::moduleHandler()->moduleExists('dblog') && \Drupal::currentUser()->hasPermission('access site reports')) {
|
||||
$message = \Drupal::translation()->formatPlural($skips, 'One translation string was skipped because of disallowed or malformed HTML. <a href=":url">See the log</a> for details.', '@count translation strings were skipped because of disallowed or malformed HTML. <a href=":url">See the log</a> for details.', array(':url' => \Drupal::url('dblog.overview')));
|
||||
$message = \Drupal::translation()->formatPlural($skips, 'One translation string was skipped because of disallowed or malformed HTML. <a href=":url">See the log</a> for details.', '@count translation strings were skipped because of disallowed or malformed HTML. <a href=":url">See the log</a> for details.', [':url' => \Drupal::url('dblog.overview')]);
|
||||
}
|
||||
else {
|
||||
$message = \Drupal::translation()->formatPlural($skips, 'One translation string was skipped because of disallowed or malformed HTML. See the log for details.', '@count translation strings were skipped because of disallowed or malformed HTML. See the log for details.');
|
||||
}
|
||||
drupal_set_message($message, 'warning');
|
||||
$logger->warning('@count disallowed HTML string(s) in files: @files.', array('@count' => $skips, '@files' => implode(',', $skipped_files)));
|
||||
$logger->warning('@count disallowed HTML string(s) in files: @files.', ['@count' => $skips, '@files' => implode(',', $skipped_files)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -448,13 +448,13 @@ function locale_translate_file_create($filepath) {
|
|||
* @return object
|
||||
* Modified file object.
|
||||
*/
|
||||
function locale_translate_file_attach_properties($file, array $options = array()) {
|
||||
function locale_translate_file_attach_properties($file, array $options = []) {
|
||||
// If $file is a file entity, convert it to a stdClass.
|
||||
if ($file instanceof FileInterface) {
|
||||
$file = (object) array(
|
||||
$file = (object) [
|
||||
'filename' => $file->getFilename(),
|
||||
'uri' => $file->getFileUri(),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Extract project, version and language code from the file name. Supported:
|
||||
|
@ -499,7 +499,7 @@ function locale_translate_file_attach_properties($file, array $options = array()
|
|||
* TRUE if files are removed successfully. FALSE if one or more files could
|
||||
* not be deleted.
|
||||
*/
|
||||
function locale_translate_delete_translation_files(array $projects = array(), array $langcodes = array()) {
|
||||
function locale_translate_delete_translation_files(array $projects = [], array $langcodes = []) {
|
||||
$fail = FALSE;
|
||||
locale_translation_file_history_delete($projects, $langcodes);
|
||||
|
||||
|
@ -531,7 +531,7 @@ function locale_translate_delete_translation_files(array $projects = array(), ar
|
|||
* @return array
|
||||
* The batch definition.
|
||||
*/
|
||||
function locale_config_batch_update_components(array $options, array $langcodes = array(), array $components = array()) {
|
||||
function locale_config_batch_update_components(array $options, array $langcodes = [], array $components = []) {
|
||||
$langcodes = $langcodes ? $langcodes : array_keys(\Drupal::languageManager()->getLanguages());
|
||||
if ($langcodes && $names = Locale::config()->getComponentNames($components)) {
|
||||
return locale_config_batch_build($names, $langcodes, $options);
|
||||
|
@ -555,11 +555,11 @@ function locale_config_batch_update_components(array $options, array $langcodes
|
|||
*
|
||||
* @see locale_config_batch_refresh_name()
|
||||
*/
|
||||
function locale_config_batch_build(array $names, array $langcodes, array $options = array()) {
|
||||
$options += array('finish_feedback' => TRUE);
|
||||
function locale_config_batch_build(array $names, array $langcodes, array $options = []) {
|
||||
$options += ['finish_feedback' => TRUE];
|
||||
$i = 0;
|
||||
$batch_names = array();
|
||||
$operations = array();
|
||||
$batch_names = [];
|
||||
$operations = [];
|
||||
foreach ($names as $name) {
|
||||
$batch_names[] = $name;
|
||||
$i++;
|
||||
|
@ -568,20 +568,20 @@ function locale_config_batch_build(array $names, array $langcodes, array $option
|
|||
// request. We batch a small number of configuration object upgrades
|
||||
// together to improve the overall performance of the process.
|
||||
if ($i % 20 == 0) {
|
||||
$operations[] = array('locale_config_batch_refresh_name', array($batch_names, $langcodes));
|
||||
$batch_names = array();
|
||||
$operations[] = ['locale_config_batch_refresh_name', [$batch_names, $langcodes]];
|
||||
$batch_names = [];
|
||||
}
|
||||
}
|
||||
if (!empty($batch_names)) {
|
||||
$operations[] = array('locale_config_batch_refresh_name', array($batch_names, $langcodes));
|
||||
$operations[] = ['locale_config_batch_refresh_name', [$batch_names, $langcodes]];
|
||||
}
|
||||
$batch = array(
|
||||
$batch = [
|
||||
'operations' => $operations,
|
||||
'title' => t('Updating configuration translations'),
|
||||
'init_message' => t('Starting configuration update'),
|
||||
'error_message' => t('Error updating configuration translations'),
|
||||
'file' => drupal_get_path('module', 'locale') . '/locale.bulk.inc',
|
||||
);
|
||||
];
|
||||
if (!empty($options['finish_feedback'])) {
|
||||
$batch['completed'] = 'locale_config_batch_finished';
|
||||
}
|
||||
|
@ -597,7 +597,7 @@ function locale_config_batch_build(array $names, array $langcodes, array $option
|
|||
* An array of names of configuration objects to update.
|
||||
* @param array $langcodes
|
||||
* (optional) Array of language codes to update. Defaults to all languages.
|
||||
* @param array|\ArrayAccess $context.
|
||||
* @param array|\ArrayAccess $context
|
||||
* Contains a list of files imported.
|
||||
*
|
||||
* @see locale_config_batch_build()
|
||||
|
@ -630,8 +630,8 @@ function locale_config_batch_finished($success, array $results) {
|
|||
if ($success) {
|
||||
$configuration = isset($results['stats']['config']) ? $results['stats']['config'] : 0;
|
||||
if ($configuration) {
|
||||
drupal_set_message(t('The configuration was successfully updated. There are %number configuration objects updated.', array('%number' => $configuration)));
|
||||
\Drupal::logger('locale')->notice('The configuration was successfully updated. %number configuration objects updated.', array('%number' => $configuration));
|
||||
drupal_set_message(t('The configuration was successfully updated. There are %number configuration objects updated.', ['%number' => $configuration]));
|
||||
\Drupal::logger('locale')->notice('The configuration was successfully updated. %number configuration objects updated.', ['%number' => $configuration]);
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('No configuration objects have been updated.'));
|
||||
|
|
|
@ -66,7 +66,7 @@ function locale_translation_build_projects() {
|
|||
}
|
||||
|
||||
// For every project store information.
|
||||
$data += array(
|
||||
$data += [
|
||||
'name' => $name,
|
||||
'version' => isset($data['info']['version']) ? $data['info']['version'] : '',
|
||||
'core' => isset($data['info']['core']) ? $data['info']['core'] : \Drupal::CORE_COMPATIBILITY,
|
||||
|
@ -74,7 +74,7 @@ function locale_translation_build_projects() {
|
|||
// gettext file. Use the default if not.
|
||||
'server_pattern' => isset($data['info']['interface translation server pattern']) && $data['info']['interface translation server pattern'] ? $data['info']['interface translation server pattern'] : $default_server['pattern'],
|
||||
'status' => !empty($data['project_status']) ? 1 : 0,
|
||||
);
|
||||
];
|
||||
|
||||
$project = (object) $data;
|
||||
$projects[$name] = $project;
|
||||
|
@ -95,14 +95,14 @@ function locale_translation_build_projects() {
|
|||
* Array of project data including .info.yml file data.
|
||||
*/
|
||||
function locale_translation_project_list() {
|
||||
$projects = &drupal_static(__FUNCTION__, array());
|
||||
$projects = &drupal_static(__FUNCTION__, []);
|
||||
if (empty($projects)) {
|
||||
$projects = array();
|
||||
$projects = [];
|
||||
|
||||
$additional_whitelist = array(
|
||||
$additional_whitelist = [
|
||||
'interface translation project',
|
||||
'interface translation server pattern',
|
||||
);
|
||||
];
|
||||
$module_data = _locale_translation_prepare_project_list(system_rebuild_module_data(), 'module');
|
||||
$theme_data = _locale_translation_prepare_project_list(\Drupal::service('theme_handler')->rebuildThemeData(), 'theme');
|
||||
$project_info = new ProjectInfo();
|
||||
|
@ -163,9 +163,9 @@ function locale_translation_default_translation_server() {
|
|||
// fallback.
|
||||
$pattern = $pattern ? $pattern : LOCALE_TRANSLATION_DEFAULT_SERVER_PATTERN;
|
||||
|
||||
return array(
|
||||
return [
|
||||
'pattern' => $pattern,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -181,7 +181,7 @@ function locale_translation_default_translation_server() {
|
|||
*
|
||||
* @todo Return batch or NULL.
|
||||
*/
|
||||
function locale_translation_check_projects($projects = array(), $langcodes = array()) {
|
||||
function locale_translation_check_projects($projects = [], $langcodes = []) {
|
||||
if (locale_translation_use_remote_source()) {
|
||||
// Retrieve the status of both remote and local translation sources by
|
||||
// using a batch process.
|
||||
|
@ -207,7 +207,7 @@ function locale_translation_check_projects($projects = array(), $langcodes = arr
|
|||
* @param string $langcodes
|
||||
* Array of language codes. Defaults to all translatable languages.
|
||||
*/
|
||||
function locale_translation_check_projects_batch($projects = array(), $langcodes = array()) {
|
||||
function locale_translation_check_projects_batch($projects = [], $langcodes = []) {
|
||||
// Build and set the batch process.
|
||||
$batch = locale_translation_batch_status_build($projects, $langcodes);
|
||||
batch_set($batch);
|
||||
|
@ -231,21 +231,21 @@ function locale_translation_check_projects_batch($projects = array(), $langcodes
|
|||
* @return array
|
||||
* Batch definition array.
|
||||
*/
|
||||
function locale_translation_batch_status_build($projects = array(), $langcodes = array()) {
|
||||
function locale_translation_batch_status_build($projects = [], $langcodes = []) {
|
||||
$projects = $projects ? $projects : array_keys(locale_translation_get_projects());
|
||||
$langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list());
|
||||
$options = _locale_translation_default_update_options();
|
||||
|
||||
$operations = _locale_translation_batch_status_operations($projects, $langcodes, $options);
|
||||
|
||||
$batch = array(
|
||||
$batch = [
|
||||
'operations' => $operations,
|
||||
'title' => t('Checking translations'),
|
||||
'progress_message' => '',
|
||||
'finished' => 'locale_translation_batch_status_finished',
|
||||
'error_message' => t('Error checking translation updates.'),
|
||||
'file' => drupal_get_path('module', 'locale') . '/locale.batch.inc',
|
||||
);
|
||||
];
|
||||
return $batch;
|
||||
}
|
||||
|
||||
|
@ -263,13 +263,13 @@ function locale_translation_batch_status_build($projects = array(), $langcodes =
|
|||
* @return array
|
||||
* Array of batch operations.
|
||||
*/
|
||||
function _locale_translation_batch_status_operations($projects, $langcodes, $options = array()) {
|
||||
$operations = array();
|
||||
function _locale_translation_batch_status_operations($projects, $langcodes, $options = []) {
|
||||
$operations = [];
|
||||
|
||||
foreach ($projects as $project) {
|
||||
foreach ($langcodes as $langcode) {
|
||||
// Check status of local and remote translation sources.
|
||||
$operations[] = array('locale_translation_batch_status_check', array($project, $langcode, $options));
|
||||
$operations[] = ['locale_translation_batch_status_check', [$project, $langcode, $options]];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -295,7 +295,7 @@ function _locale_translation_batch_status_operations($projects, $langcodes, $opt
|
|||
* @param array $langcodes
|
||||
* Array of language codes. Defaults to all translatable languages.
|
||||
*/
|
||||
function locale_translation_check_projects_local($projects = array(), $langcodes = array()) {
|
||||
function locale_translation_check_projects_local($projects = [], $langcodes = []) {
|
||||
$projects = locale_translation_get_projects($projects);
|
||||
$langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list());
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ require_once __DIR__ . '/locale.translation.inc';
|
|||
* @return array
|
||||
* Batch definition array.
|
||||
*/
|
||||
function locale_translation_batch_update_build($projects = array(), $langcodes = array(), $options = array()) {
|
||||
function locale_translation_batch_update_build($projects = [], $langcodes = [], $options = []) {
|
||||
module_load_include('compare.inc', 'locale');
|
||||
$projects = $projects ? $projects : array_keys(locale_translation_get_projects());
|
||||
$langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list());
|
||||
|
@ -38,14 +38,14 @@ function locale_translation_batch_update_build($projects = array(), $langcodes =
|
|||
// Download and import translations.
|
||||
$operations = array_merge($operations, _locale_translation_fetch_operations($projects, $langcodes, $options));
|
||||
|
||||
$batch = array(
|
||||
$batch = [
|
||||
'operations' => $operations,
|
||||
'title' => t('Updating translations'),
|
||||
'progress_message' => '',
|
||||
'error_message' => t('Error importing translation files'),
|
||||
'finished' => 'locale_translation_batch_fetch_finished',
|
||||
'file' => drupal_get_path('module', 'locale') . '/locale.batch.inc',
|
||||
);
|
||||
];
|
||||
return $batch;
|
||||
}
|
||||
|
||||
|
@ -63,18 +63,18 @@ function locale_translation_batch_update_build($projects = array(), $langcodes =
|
|||
* @return array
|
||||
* Batch definition array.
|
||||
*/
|
||||
function locale_translation_batch_fetch_build($projects = array(), $langcodes = array(), $options = array()) {
|
||||
function locale_translation_batch_fetch_build($projects = [], $langcodes = [], $options = []) {
|
||||
$projects = $projects ? $projects : array_keys(locale_translation_get_projects());
|
||||
$langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list());
|
||||
|
||||
$batch = array(
|
||||
$batch = [
|
||||
'operations' => _locale_translation_fetch_operations($projects, $langcodes, $options),
|
||||
'title' => t('Updating translations.'),
|
||||
'progress_message' => '',
|
||||
'error_message' => t('Error importing translation files'),
|
||||
'finished' => 'locale_translation_batch_fetch_finished',
|
||||
'file' => drupal_get_path('module', 'locale') . '/locale.batch.inc',
|
||||
);
|
||||
];
|
||||
return $batch;
|
||||
}
|
||||
|
||||
|
@ -93,14 +93,14 @@ function locale_translation_batch_fetch_build($projects = array(), $langcodes =
|
|||
* Array of batch operations.
|
||||
*/
|
||||
function _locale_translation_fetch_operations($projects, $langcodes, $options) {
|
||||
$operations = array();
|
||||
$operations = [];
|
||||
|
||||
foreach ($projects as $project) {
|
||||
foreach ($langcodes as $langcode) {
|
||||
if (locale_translation_use_remote_source()) {
|
||||
$operations[] = array('locale_translation_batch_fetch_download', array($project, $langcode));
|
||||
$operations[] = ['locale_translation_batch_fetch_download', [$project, $langcode]];
|
||||
}
|
||||
$operations[] = array('locale_translation_batch_fetch_import', array($project, $langcode, $options));
|
||||
$operations[] = ['locale_translation_batch_fetch_import', [$project, $langcode, $options]];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ function locale_uninstall() {
|
|||
$locale_js_directory = 'public://' . $config->get('javascript.directory');
|
||||
|
||||
if (is_dir($locale_js_directory)) {
|
||||
$locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: array();
|
||||
$locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: [];
|
||||
foreach ($locale_javascripts as $langcode => $file_suffix) {
|
||||
if (!empty($file_suffix)) {
|
||||
file_unmanaged_delete($locale_js_directory . '/' . $langcode . '_' . $file_suffix . '.js');
|
||||
|
@ -51,183 +51,183 @@ function locale_uninstall() {
|
|||
* Implements hook_schema().
|
||||
*/
|
||||
function locale_schema() {
|
||||
$schema['locales_source'] = array(
|
||||
$schema['locales_source'] = [
|
||||
'description' => 'List of English source strings.',
|
||||
'fields' => array(
|
||||
'lid' => array(
|
||||
'fields' => [
|
||||
'lid' => [
|
||||
'type' => 'serial',
|
||||
'not null' => TRUE,
|
||||
'description' => 'Unique identifier of this string.',
|
||||
),
|
||||
'source' => array(
|
||||
],
|
||||
'source' => [
|
||||
'type' => 'text',
|
||||
'mysql_type' => 'blob',
|
||||
'not null' => TRUE,
|
||||
'description' => 'The original string in English.',
|
||||
),
|
||||
'context' => array(
|
||||
],
|
||||
'context' => [
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'The context this string applies to.',
|
||||
),
|
||||
'version' => array(
|
||||
],
|
||||
'version' => [
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 20,
|
||||
'not null' => TRUE,
|
||||
'default' => 'none',
|
||||
'description' => 'Version of Drupal where the string was last used (for locales optimization).',
|
||||
),
|
||||
),
|
||||
'primary key' => array('lid'),
|
||||
'indexes' => array(
|
||||
'source_context' => array(array('source', 30), 'context'),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
'primary key' => ['lid'],
|
||||
'indexes' => [
|
||||
'source_context' => [['source', 30], 'context'],
|
||||
],
|
||||
];
|
||||
|
||||
$schema['locales_target'] = array(
|
||||
$schema['locales_target'] = [
|
||||
'description' => 'Stores translated versions of strings.',
|
||||
'fields' => array(
|
||||
'lid' => array(
|
||||
'fields' => [
|
||||
'lid' => [
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'Source string ID. References {locales_source}.lid.',
|
||||
),
|
||||
'translation' => array(
|
||||
],
|
||||
'translation' => [
|
||||
'type' => 'text',
|
||||
'mysql_type' => 'blob',
|
||||
'not null' => TRUE,
|
||||
'description' => 'Translation string value in this language.',
|
||||
),
|
||||
'language' => array(
|
||||
],
|
||||
'language' => [
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 12,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'Language code. References {language}.langcode.',
|
||||
),
|
||||
'customized' => array(
|
||||
],
|
||||
'customized' => [
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0, // LOCALE_NOT_CUSTOMIZED
|
||||
'description' => 'Boolean indicating whether the translation is custom to this site.',
|
||||
),
|
||||
),
|
||||
'primary key' => array('language', 'lid'),
|
||||
'foreign keys' => array(
|
||||
'locales_source' => array(
|
||||
],
|
||||
],
|
||||
'primary key' => ['language', 'lid'],
|
||||
'foreign keys' => [
|
||||
'locales_source' => [
|
||||
'table' => 'locales_source',
|
||||
'columns' => array('lid' => 'lid'),
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'lid' => array('lid'),
|
||||
),
|
||||
);
|
||||
'columns' => ['lid' => 'lid'],
|
||||
],
|
||||
],
|
||||
'indexes' => [
|
||||
'lid' => ['lid'],
|
||||
],
|
||||
];
|
||||
|
||||
$schema['locales_location'] = array(
|
||||
$schema['locales_location'] = [
|
||||
'description' => 'Location information for source strings.',
|
||||
'fields' => array(
|
||||
'lid' => array(
|
||||
'fields' => [
|
||||
'lid' => [
|
||||
'type' => 'serial',
|
||||
'not null' => TRUE,
|
||||
'description' => 'Unique identifier of this location.',
|
||||
),
|
||||
'sid' => array(
|
||||
],
|
||||
'sid' => [
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'description' => 'Unique identifier of this string.',
|
||||
),
|
||||
'type' => array(
|
||||
],
|
||||
'type' => [
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 50,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'The location type (file, config, path, etc).',
|
||||
),
|
||||
'name' => array(
|
||||
],
|
||||
'name' => [
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'Type dependent location information (file name, path, etc).',
|
||||
),
|
||||
'version' => array(
|
||||
],
|
||||
'version' => [
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 20,
|
||||
'not null' => TRUE,
|
||||
'default' => 'none',
|
||||
'description' => 'Version of Drupal where the location was found.',
|
||||
),
|
||||
),
|
||||
'primary key' => array('lid'),
|
||||
'foreign keys' => array(
|
||||
'locales_source' => array(
|
||||
],
|
||||
],
|
||||
'primary key' => ['lid'],
|
||||
'foreign keys' => [
|
||||
'locales_source' => [
|
||||
'table' => 'locales_source',
|
||||
'columns' => array('sid' => 'lid'),
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'string_id' => array('sid'),
|
||||
'string_type' => array('sid', 'type'),
|
||||
),
|
||||
);
|
||||
'columns' => ['sid' => 'lid'],
|
||||
],
|
||||
],
|
||||
'indexes' => [
|
||||
'string_id' => ['sid'],
|
||||
'string_type' => ['sid', 'type'],
|
||||
],
|
||||
];
|
||||
|
||||
$schema['locale_file'] = array(
|
||||
$schema['locale_file'] = [
|
||||
'description' => 'File import status information for interface translation files.',
|
||||
'fields' => array(
|
||||
'project' => array(
|
||||
'fields' => [
|
||||
'project' => [
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => '255',
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'A unique short name to identify the project the file belongs to.',
|
||||
),
|
||||
'langcode' => array(
|
||||
],
|
||||
'langcode' => [
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => '12',
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'Language code of this translation. References {language}.langcode.',
|
||||
),
|
||||
'filename' => array(
|
||||
],
|
||||
'filename' => [
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'Filename of the imported file.',
|
||||
),
|
||||
'version' => array(
|
||||
],
|
||||
'version' => [
|
||||
'type' => 'varchar',
|
||||
'length' => '128',
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'Version tag of the imported file.',
|
||||
),
|
||||
'uri' => array(
|
||||
],
|
||||
'uri' => [
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'URI of the remote file, the resulting local file or the locally imported file.',
|
||||
),
|
||||
'timestamp' => array(
|
||||
],
|
||||
'timestamp' => [
|
||||
'type' => 'int',
|
||||
'not null' => FALSE,
|
||||
'default' => 0,
|
||||
'description' => 'Unix timestamp of the imported file.',
|
||||
),
|
||||
'last_checked' => array(
|
||||
],
|
||||
'last_checked' => [
|
||||
'type' => 'int',
|
||||
'not null' => FALSE,
|
||||
'default' => 0,
|
||||
'description' => 'Unix timestamp of the last time this translation was confirmed to be the most recent release available.',
|
||||
),
|
||||
),
|
||||
'primary key' => array('project', 'langcode'),
|
||||
);
|
||||
],
|
||||
],
|
||||
'primary key' => ['project', 'langcode'],
|
||||
];
|
||||
return $schema;
|
||||
}
|
||||
|
||||
|
@ -235,10 +235,10 @@ function locale_schema() {
|
|||
* Implements hook_requirements().
|
||||
*/
|
||||
function locale_requirements($phase) {
|
||||
$requirements = array();
|
||||
$requirements = [];
|
||||
if ($phase == 'runtime') {
|
||||
$available_updates = array();
|
||||
$untranslated = array();
|
||||
$available_updates = [];
|
||||
$untranslated = [];
|
||||
$languages = locale_translatable_language_list();
|
||||
|
||||
if ($languages) {
|
||||
|
@ -258,39 +258,48 @@ function locale_requirements($phase) {
|
|||
|
||||
if ($available_updates || $untranslated) {
|
||||
if ($available_updates) {
|
||||
$requirements['locale_translation'] = array(
|
||||
$requirements['locale_translation'] = [
|
||||
'title' => 'Translation update status',
|
||||
'value' => \Drupal::l(t('Updates available'), new Url('locale.translate_status')),
|
||||
'severity' => REQUIREMENT_WARNING,
|
||||
'description' => t('Updates available for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', array('@languages' => implode(', ', $available_updates), ':updates' => \Drupal::url('locale.translate_status'))),
|
||||
);
|
||||
'description' => t('Updates available for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', ['@languages' => implode(', ', $available_updates), ':updates' => \Drupal::url('locale.translate_status')]),
|
||||
];
|
||||
}
|
||||
else {
|
||||
$requirements['locale_translation'] = array(
|
||||
$requirements['locale_translation'] = [
|
||||
'title' => 'Translation update status',
|
||||
'value' => t('Missing translations'),
|
||||
'severity' => REQUIREMENT_INFO,
|
||||
'description' => t('Missing translations for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', array('@languages' => implode(', ', $untranslated), ':updates' => \Drupal::url('locale.translate_status'))),
|
||||
);
|
||||
'description' => t('Missing translations for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', ['@languages' => implode(', ', $untranslated), ':updates' => \Drupal::url('locale.translate_status')]),
|
||||
];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$requirements['locale_translation'] = array(
|
||||
$requirements['locale_translation'] = [
|
||||
'title' => 'Translation update status',
|
||||
'value' => t('Up to date'),
|
||||
'severity' => REQUIREMENT_OK,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$requirements['locale_translation'] = array(
|
||||
$requirements['locale_translation'] = [
|
||||
'title' => 'Translation update status',
|
||||
'value' => \Drupal::l(t('Can not determine status'), new Url('locale.translate_status')),
|
||||
'severity' => REQUIREMENT_WARNING,
|
||||
'description' => t('No translation status is available. See the <a href=":updates">Available translation updates</a> page for more information.', array(':updates' => \Drupal::url('locale.translate_status'))),
|
||||
);
|
||||
'description' => t('No translation status is available. See the <a href=":updates">Available translation updates</a> page for more information.', [':updates' => \Drupal::url('locale.translate_status')]),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $requirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete translation status data in state.
|
||||
*/
|
||||
function locale_update_8300() {
|
||||
// Delete the old translation status data, it will be rebuilt and stored in
|
||||
// the new key value collection.
|
||||
\Drupal::state()->delete('locale.translation_status');
|
||||
}
|
||||
|
|
|
@ -146,30 +146,30 @@ function locale_help($route_name, RouteMatchInterface $route_match) {
|
|||
case 'help.page.locale':
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('The Interface Translation module allows you to translate interface text (<em>strings</em>) into different languages, and to switch between them for the display of interface text. It uses the functionality provided by the <a href=":language">Language module</a>. For more information, see the <a href=":doc-url">online documentation for the Interface Translation module</a>.', array(':doc-url' => 'https://www.drupal.org/documentation/modules/locale/', ':language' => \Drupal::url('help.page', array('name' => 'language')))) . '</p>';
|
||||
$output .= '<p>' . t('The Interface Translation module allows you to translate interface text (<em>strings</em>) into different languages, and to switch between them for the display of interface text. It uses the functionality provided by the <a href=":language">Language module</a>. For more information, see the <a href=":doc-url">online documentation for the Interface Translation module</a>.', [':doc-url' => 'https://www.drupal.org/documentation/modules/locale/', ':language' => \Drupal::url('help.page', ['name' => 'language'])]) . '</p>';
|
||||
$output .= '<h3>' . t('Uses') . '</h3>';
|
||||
$output .= '<dl>';
|
||||
$output .= '<dt>' . t('Importing translation files') . '</dt>';
|
||||
$output .= '<dd>' . t('Translation files with translated interface text are imported automatically when languages are added on the <a href=":languages">Languages</a> page, or when modules or themes are enabled. On the <a href=":locale-settings">Interface translation settings</a> page, the <em>Translation source</em> can be restricted to local files only, or to include the <a href=":server">Drupal translation server</a>. Although modules and themes may not be fully translated in all languages, new translations become available frequently. You can specify whether and how often to check for translation file updates and whether to overwrite existing translations on the <a href=":locale-settings">Interface translation settings</a> page. You can also manually import a translation file on the <a href=":import">Interface translation import</a> page.', array(':import' => \Drupal::url('locale.translate_import'), ':locale-settings' => \Drupal::url('locale.settings'), ':languages' => \Drupal::url('entity.configurable_language.collection'), ':server' => 'https://localize.drupal.org')) . '</dd>';
|
||||
$output .= '<dd>' . t('Translation files with translated interface text are imported automatically when languages are added on the <a href=":languages">Languages</a> page, or when modules or themes are enabled. On the <a href=":locale-settings">Interface translation settings</a> page, the <em>Translation source</em> can be restricted to local files only, or to include the <a href=":server">Drupal translation server</a>. Although modules and themes may not be fully translated in all languages, new translations become available frequently. You can specify whether and how often to check for translation file updates and whether to overwrite existing translations on the <a href=":locale-settings">Interface translation settings</a> page. You can also manually import a translation file on the <a href=":import">Interface translation import</a> page.', [':import' => \Drupal::url('locale.translate_import'), ':locale-settings' => \Drupal::url('locale.settings'), ':languages' => \Drupal::url('entity.configurable_language.collection'), ':server' => 'https://localize.drupal.org']) . '</dd>';
|
||||
$output .= '<dt>' . t('Checking the translation status') . '</dt>';
|
||||
$output .= '<dd>' . t('You can check how much of the interface on your site is translated into which language on the <a href=":languages">Languages</a> page. On the <a href=":translation-updates">Available translation updates</a> page, you can check whether interface translation updates are available on the <a href=":server">Drupal translation server</a>.', array(':languages' => \Drupal::url('entity.configurable_language.collection'), ':translation-updates' => \Drupal::url('locale.translate_status'), ':server' => 'https://localize.drupal.org')) . '<dd>';
|
||||
$output .= '<dd>' . t('You can check how much of the interface on your site is translated into which language on the <a href=":languages">Languages</a> page. On the <a href=":translation-updates">Available translation updates</a> page, you can check whether interface translation updates are available on the <a href=":server">Drupal translation server</a>.', [':languages' => \Drupal::url('entity.configurable_language.collection'), ':translation-updates' => \Drupal::url('locale.translate_status'), ':server' => 'https://localize.drupal.org']) . '<dd>';
|
||||
$output .= '<dt>' . t('Translating individual strings') . '</dt>';
|
||||
$output .= '<dd>' . t('You can translate individual strings directly on the <a href=":translate">User interface translation</a> page, or download the currently-used translation file for a specific language on the <a href=":export">Interface translation export</a> page. Once you have edited the translation file, you can then import it again on the <a href=":import">Interface translation import</a> page.', array(':translate' => \Drupal::url('locale.translate_page'), ':export' => \Drupal::url('locale.translate_export'), ':import' => \Drupal::url('locale.translate_import'))) . '</dd>';
|
||||
$output .= '<dd>' . t('You can translate individual strings directly on the <a href=":translate">User interface translation</a> page, or download the currently-used translation file for a specific language on the <a href=":export">Interface translation export</a> page. Once you have edited the translation file, you can then import it again on the <a href=":import">Interface translation import</a> page.', [':translate' => \Drupal::url('locale.translate_page'), ':export' => \Drupal::url('locale.translate_export'), ':import' => \Drupal::url('locale.translate_import')]) . '</dd>';
|
||||
$output .= '<dt>' . t('Overriding default English strings') . '</dt>';
|
||||
$output .= '<dd>' . t('If translation is enabled for English, you can <em>override</em> the default English interface text strings in your site with other English text strings on the <a href=":translate">User interface translation</a> page. Translation is off by default for English, but you can turn it on by visiting the <em>Edit language</em> page for <em>English</em> from the <a href=":languages">Languages</a> page.', array(':translate' => \Drupal::url('locale.translate_page'), ':languages' => \Drupal::url('entity.configurable_language.collection'))) . '</dd>';
|
||||
$output .= '<dd>' . t('If translation is enabled for English, you can <em>override</em> the default English interface text strings in your site with other English text strings on the <a href=":translate">User interface translation</a> page. Translation is off by default for English, but you can turn it on by visiting the <em>Edit language</em> page for <em>English</em> from the <a href=":languages">Languages</a> page.', [':translate' => \Drupal::url('locale.translate_page'), ':languages' => \Drupal::url('entity.configurable_language.collection')]) . '</dd>';
|
||||
$output .= '</dl>';
|
||||
return $output;
|
||||
|
||||
case 'entity.configurable_language.collection':
|
||||
return '<p>' . t('Interface translations are automatically imported when a language is added, or when new modules or themes are enabled. The report <a href=":update">Available translation updates</a> shows the status. Interface text can be customized in the <a href=":translate">user interface translation</a> page.', array(':update' => \Drupal::url('locale.translate_status'), ':translate' => \Drupal::url('locale.translate_page'))) . '</p>';
|
||||
return '<p>' . t('Interface translations are automatically imported when a language is added, or when new modules or themes are enabled. The report <a href=":update">Available translation updates</a> shows the status. Interface text can be customized in the <a href=":translate">user interface translation</a> page.', [':update' => \Drupal::url('locale.translate_status'), ':translate' => \Drupal::url('locale.translate_page')]) . '</p>';
|
||||
|
||||
case 'locale.translate_page':
|
||||
$output = '<p>' . t('This page allows a translator to search for specific translated and untranslated strings, and is used when creating or editing translations. (Note: Because translation tasks involve many strings, it may be more convenient to <a title="User interface translation export" href=":export">export</a> strings for offline editing in a desktop Gettext translation editor.) Searches may be limited to strings in a specific language.', array(':export' => \Drupal::url('locale.translate_export'))) . '</p>';
|
||||
$output = '<p>' . t('This page allows a translator to search for specific translated and untranslated strings, and is used when creating or editing translations. (Note: Because translation tasks involve many strings, it may be more convenient to <a title="User interface translation export" href=":export">export</a> strings for offline editing in a desktop Gettext translation editor.) Searches may be limited to strings in a specific language.', [':export' => \Drupal::url('locale.translate_export')]) . '</p>';
|
||||
return $output;
|
||||
|
||||
case 'locale.translate_import':
|
||||
$output = '<p>' . t('Translation files are automatically downloaded and imported when <a title="Languages" href=":language">languages</a> are added, or when modules or themes are enabled.', array(':language' => \Drupal::url('entity.configurable_language.collection'))) . '</p>';
|
||||
$output .= '<p>' . t('This page allows translators to manually import translated strings contained in a Gettext Portable Object (.po) file. Manual import may be used for customized translations or for the translation of custom modules and themes. To customize translations you can download a translation file from the <a href=":url">Drupal translation server</a> or <a title="User interface translation export" href=":export">export</a> translations from the site, customize the translations using a Gettext translation editor, and import the result using this page.', array(':url' => 'https://localize.drupal.org', ':export' => \Drupal::url('locale.translate_export'))) . '</p>';
|
||||
$output = '<p>' . t('Translation files are automatically downloaded and imported when <a title="Languages" href=":language">languages</a> are added, or when modules or themes are enabled.', [':language' => \Drupal::url('entity.configurable_language.collection')]) . '</p>';
|
||||
$output .= '<p>' . t('This page allows translators to manually import translated strings contained in a Gettext Portable Object (.po) file. Manual import may be used for customized translations or for the translation of custom modules and themes. To customize translations you can download a translation file from the <a href=":url">Drupal translation server</a> or <a title="User interface translation export" href=":export">export</a> translations from the site, customize the translations using a Gettext translation editor, and import the result using this page.', [':url' => 'https://localize.drupal.org', ':export' => \Drupal::url('locale.translate_export')]) . '</p>';
|
||||
$output .= '<p>' . t('Note that importing large .po files may take several minutes.') . '</p>';
|
||||
return $output;
|
||||
|
||||
|
@ -182,16 +182,16 @@ function locale_help($route_name, RouteMatchInterface $route_match) {
|
|||
* Implements hook_theme().
|
||||
*/
|
||||
function locale_theme() {
|
||||
return array(
|
||||
'locale_translation_last_check' => array(
|
||||
'variables' => array('last' => NULL),
|
||||
return [
|
||||
'locale_translation_last_check' => [
|
||||
'variables' => ['last' => NULL],
|
||||
'file' => 'locale.pages.inc',
|
||||
),
|
||||
'locale_translation_update_info' => array(
|
||||
'variables' => array('updates' => array(), 'not_found' => array()),
|
||||
],
|
||||
'locale_translation_update_info' => [
|
||||
'variables' => ['updates' => [], 'not_found' => []],
|
||||
'file' => 'locale.pages.inc',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -223,11 +223,11 @@ function locale_configurable_language_update(ConfigurableLanguageInterface $lang
|
|||
*/
|
||||
function locale_configurable_language_delete(ConfigurableLanguageInterface $language) {
|
||||
// Remove translations.
|
||||
\Drupal::service('locale.storage')->deleteTranslations(array('language' => $language->id()));
|
||||
\Drupal::service('locale.storage')->deleteTranslations(['language' => $language->id()]);
|
||||
|
||||
// Remove interface translation files.
|
||||
module_load_include('inc', 'locale', 'locale.bulk');
|
||||
locale_translate_delete_translation_files(array(), array($language->id()));
|
||||
locale_translate_delete_translation_files([], [$language->id()]);
|
||||
|
||||
// Remove translated configuration objects.
|
||||
Locale::config()->deleteLanguageTranslations($language->id());
|
||||
|
@ -237,7 +237,7 @@ function locale_configurable_language_delete(ConfigurableLanguageInterface $lang
|
|||
\Drupal::cache('render')->deleteAll();
|
||||
|
||||
// Clear locale translation caches.
|
||||
locale_translation_status_delete_languages(array($language->id()));
|
||||
locale_translation_status_delete_languages([$language->id()]);
|
||||
\Drupal::cache()->delete('locale:' . $language->id());
|
||||
}
|
||||
|
||||
|
@ -277,7 +277,7 @@ function locale_get_plural($count, $langcode = NULL) {
|
|||
|
||||
// Used to store precomputed plural indexes corresponding to numbers
|
||||
// individually for each language.
|
||||
$plural_indexes = &drupal_static(__FUNCTION__ . ':plurals', array());
|
||||
$plural_indexes = &drupal_static(__FUNCTION__ . ':plurals', []);
|
||||
|
||||
$langcode = $langcode ? $langcode : $language_interface->getId();
|
||||
|
||||
|
@ -323,7 +323,7 @@ function locale_modules_installed($modules) {
|
|||
* Implements hook_module_preuninstall().
|
||||
*/
|
||||
function locale_module_preuninstall($module) {
|
||||
$components['module'] = array($module);
|
||||
$components['module'] = [$module];
|
||||
locale_system_remove($components);
|
||||
}
|
||||
|
||||
|
@ -399,7 +399,7 @@ function locale_system_set_config_langcodes() {
|
|||
* translations for, indexed by type.
|
||||
*/
|
||||
function locale_system_update(array $components) {
|
||||
$components += array('module' => array(), 'theme' => array());
|
||||
$components += ['module' => [], 'theme' => []];
|
||||
$list = array_merge($components['module'], $components['theme']);
|
||||
|
||||
// Skip running the translation imports if in the installer,
|
||||
|
@ -446,7 +446,7 @@ function locale_system_update(array $components) {
|
|||
* translations for, indexed by type.
|
||||
*/
|
||||
function locale_system_remove($components) {
|
||||
$components += array('module' => array(), 'theme' => array());
|
||||
$components += ['module' => [], 'theme' => []];
|
||||
$list = array_merge($components['module'], $components['theme']);
|
||||
if ($language_list = locale_translatable_language_list()) {
|
||||
module_load_include('compare.inc', 'locale');
|
||||
|
@ -460,7 +460,7 @@ function locale_system_remove($components) {
|
|||
locale_translation_file_history_delete($list);
|
||||
|
||||
// Remove translation files.
|
||||
locale_translate_delete_translation_files($list, array());
|
||||
locale_translate_delete_translation_files($list, []);
|
||||
|
||||
// Remove translatable projects.
|
||||
// Follow-up issue https://www.drupal.org/node/1842362 to replace the
|
||||
|
@ -486,7 +486,7 @@ function locale_cache_flush() {
|
|||
*/
|
||||
function locale_js_alter(&$javascript, AttachedAssetsInterface $assets) {
|
||||
// @todo Remove this in https://www.drupal.org/node/2421323.
|
||||
$files = array();
|
||||
$files = [];
|
||||
foreach ($javascript as $item) {
|
||||
if (isset($item['type']) && $item['type'] == 'file') {
|
||||
// Ignore the JS translation placeholder file.
|
||||
|
@ -529,11 +529,11 @@ function locale_js_alter(&$javascript, AttachedAssetsInterface $assets) {
|
|||
* The filepath to the translation file or NULL if no translation is
|
||||
* applicable.
|
||||
*/
|
||||
function locale_js_translate(array $files = array()) {
|
||||
function locale_js_translate(array $files = []) {
|
||||
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
|
||||
|
||||
$dir = 'public://' . \Drupal::config('locale.settings')->get('javascript.directory');
|
||||
$parsed = \Drupal::state()->get('system.javascript_parsed') ?: array();
|
||||
$parsed = \Drupal::state()->get('system.javascript_parsed') ?: [];
|
||||
$new_files = FALSE;
|
||||
|
||||
foreach ($files as $filepath) {
|
||||
|
@ -571,7 +571,7 @@ function locale_js_translate(array $files = array()) {
|
|||
}
|
||||
|
||||
// Add the translation JavaScript file to the page.
|
||||
$locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: array();
|
||||
$locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: [];
|
||||
$translation_file = NULL;
|
||||
if (!empty($files) && !empty($locale_javascripts[$language_interface->getId()])) {
|
||||
// Add the translation JavaScript file to the page.
|
||||
|
@ -624,7 +624,7 @@ function locale_form_language_admin_overview_form_alter(&$form, FormStateInterfa
|
|||
$languages = $form['languages']['#languages'];
|
||||
|
||||
$total_strings = \Drupal::service('locale.storage')->countStrings();
|
||||
$stats = array_fill_keys(array_keys($languages), array());
|
||||
$stats = array_fill_keys(array_keys($languages), []);
|
||||
|
||||
// If we have source strings, count translations and calculate progress.
|
||||
if (!empty($total_strings)) {
|
||||
|
@ -640,26 +640,26 @@ function locale_form_language_admin_overview_form_alter(&$form, FormStateInterfa
|
|||
array_splice($form['languages']['#header'], -1, 0, ['translation-interface' => t('Interface translation')]);
|
||||
|
||||
foreach ($languages as $langcode => $language) {
|
||||
$stats[$langcode] += array(
|
||||
$stats[$langcode] += [
|
||||
'translated' => 0,
|
||||
'ratio' => 0,
|
||||
);
|
||||
];
|
||||
if (!$language->isLocked() && locale_is_translatable($langcode)) {
|
||||
$form['languages'][$langcode]['locale_statistics'] = array(
|
||||
$form['languages'][$langcode]['locale_statistics'] = [
|
||||
'#markup' => \Drupal::l(
|
||||
t('@translated/@total (@ratio%)', array(
|
||||
t('@translated/@total (@ratio%)', [
|
||||
'@translated' => $stats[$langcode]['translated'],
|
||||
'@total' => $total_strings,
|
||||
'@ratio' => $stats[$langcode]['ratio'],
|
||||
)),
|
||||
new Url('locale.translate_page', array(), array('query' => array('langcode' => $langcode)))
|
||||
]),
|
||||
new Url('locale.translate_page', [], ['query' => ['langcode' => $langcode]])
|
||||
),
|
||||
);
|
||||
];
|
||||
}
|
||||
else {
|
||||
$form['languages'][$langcode]['locale_statistics'] = array(
|
||||
$form['languages'][$langcode]['locale_statistics'] = [
|
||||
'#markup' => t('not applicable'),
|
||||
);
|
||||
];
|
||||
}
|
||||
// #type = link doesn't work with #weight on table.
|
||||
// reset and set it back after locale_statistics to get it at the right end.
|
||||
|
@ -695,7 +695,7 @@ function locale_form_language_admin_add_form_alter_submit($form, FormStateInterf
|
|||
|
||||
if (\Drupal::config('locale.settings')->get('translation.import_enabled')) {
|
||||
// Download and import translations for the newly added language.
|
||||
$batch = locale_translation_batch_update_build(array(), array($langcode), $options);
|
||||
$batch = locale_translation_batch_update_build([], [$langcode], $options);
|
||||
batch_set($batch);
|
||||
}
|
||||
|
||||
|
@ -704,7 +704,7 @@ function locale_form_language_admin_add_form_alter_submit($form, FormStateInterf
|
|||
// because then we extract English sources from shipped configuration.
|
||||
if (\Drupal::config('locale.settings')->get('translation.import_enabled') || $langcode == 'en') {
|
||||
\Drupal::moduleHandler()->loadInclude('locale', 'bulk.inc');
|
||||
if ($batch = locale_config_batch_update_components($options, array($langcode))) {
|
||||
if ($batch = locale_config_batch_update_components($options, [$langcode])) {
|
||||
batch_set($batch);
|
||||
}
|
||||
}
|
||||
|
@ -715,11 +715,11 @@ function locale_form_language_admin_add_form_alter_submit($form, FormStateInterf
|
|||
*/
|
||||
function locale_form_language_admin_edit_form_alter(&$form, FormStateInterface $form_state) {
|
||||
if ($form['langcode']['#type'] == 'value' && $form['langcode']['#value'] == 'en') {
|
||||
$form['locale_translate_english'] = array(
|
||||
$form['locale_translate_english'] = [
|
||||
'#title' => t('Enable interface translation to English'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => \Drupal::configFactory()->getEditable('locale.settings')->get('translate_english'),
|
||||
);
|
||||
];
|
||||
$form['actions']['submit']['#submit'][] = 'locale_form_language_admin_edit_form_alter_submit';
|
||||
}
|
||||
}
|
||||
|
@ -750,16 +750,16 @@ function locale_is_translatable($langcode) {
|
|||
* Add interface translation directory setting to directories configuration.
|
||||
*/
|
||||
function locale_form_system_file_system_settings_alter(&$form, FormStateInterface $form_state) {
|
||||
$form['translation_path'] = array(
|
||||
$form['translation_path'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Interface translations directory'),
|
||||
'#default_value' => \Drupal::configFactory()->getEditable('locale.settings')->get('translation.path'),
|
||||
'#maxlength' => 255,
|
||||
'#description' => t('A local file system path where interface translation files will be stored.'),
|
||||
'#required' => TRUE,
|
||||
'#after_build' => array('system_check_directory'),
|
||||
'#after_build' => ['system_check_directory'],
|
||||
'#weight' => 10,
|
||||
);
|
||||
];
|
||||
if ($form['file_default_scheme']) {
|
||||
$form['file_default_scheme']['#weight'] = 20;
|
||||
}
|
||||
|
@ -814,7 +814,7 @@ function locale_preprocess_node(&$variables) {
|
|||
* Array of translation file objects.
|
||||
*/
|
||||
function locale_translation_get_file_history() {
|
||||
$history = &drupal_static(__FUNCTION__, array());
|
||||
$history = &drupal_static(__FUNCTION__, []);
|
||||
|
||||
if (empty($history)) {
|
||||
// Get file history from the database.
|
||||
|
@ -838,15 +838,15 @@ function locale_translation_get_file_history() {
|
|||
*/
|
||||
function locale_translation_update_file_history($file) {
|
||||
$status = db_merge('locale_file')
|
||||
->key(array(
|
||||
->key([
|
||||
'project' => $file->project,
|
||||
'langcode' => $file->langcode,
|
||||
))
|
||||
->fields(array(
|
||||
])
|
||||
->fields([
|
||||
'version' => $file->version,
|
||||
'timestamp' => $file->timestamp,
|
||||
'last_checked' => $file->last_checked,
|
||||
))
|
||||
])
|
||||
->execute();
|
||||
// The file history has changed, flush the static cache now.
|
||||
// @todo Can we make this more fine grained?
|
||||
|
@ -863,7 +863,7 @@ function locale_translation_update_file_history($file) {
|
|||
* @param array $langcodes
|
||||
* Language code(s) to be deleted from the file history.
|
||||
*/
|
||||
function locale_translation_file_history_delete($projects = array(), $langcodes = array()) {
|
||||
function locale_translation_file_history_delete($projects = [], $langcodes = []) {
|
||||
$query = db_delete('locale_file');
|
||||
if (!empty($projects)) {
|
||||
$query->condition('project', $projects, 'IN');
|
||||
|
@ -880,8 +880,8 @@ function locale_translation_file_history_delete($projects = array(), $langcodes
|
|||
* @todo What is 'translation status'?
|
||||
*/
|
||||
function locale_translation_get_status($projects = NULL, $langcodes = NULL) {
|
||||
$result = array();
|
||||
$status = \Drupal::state()->get('locale.translation_status');
|
||||
$result = [];
|
||||
$status = \Drupal::keyValue('locale.translation_status')->getAll();
|
||||
module_load_include('translation.inc', 'locale');
|
||||
$projects = $projects ? $projects : array_keys(locale_translation_get_projects());
|
||||
$langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list());
|
||||
|
@ -894,7 +894,7 @@ function locale_translation_get_status($projects = NULL, $langcodes = NULL) {
|
|||
$result[$project][$langcode] = $status[$project][$langcode];
|
||||
}
|
||||
else {
|
||||
$sources = locale_translation_build_sources(array($project), array($langcode));
|
||||
$sources = locale_translation_build_sources([$project], [$langcode]);
|
||||
if (isset($sources[$project][$langcode])) {
|
||||
$result[$project][$langcode] = $sources[$project][$langcode];
|
||||
}
|
||||
|
@ -913,19 +913,15 @@ function locale_translation_get_status($projects = NULL, $langcodes = NULL) {
|
|||
* Language code.
|
||||
* @param string $type
|
||||
* Type of data to be stored.
|
||||
* @param array $data
|
||||
* @param object $data
|
||||
* File object also containing timestamp when the translation is last updated.
|
||||
*/
|
||||
function locale_translation_status_save($project, $langcode, $type, $data) {
|
||||
// Follow-up issue: https://www.drupal.org/node/1842362.
|
||||
// Split status storage per module/language and expire individually. This will
|
||||
// improve performance for large sites.
|
||||
|
||||
// Load the translation status or build it if not already available.
|
||||
module_load_include('translation.inc', 'locale');
|
||||
$status = locale_translation_get_status();
|
||||
if (empty($status)) {
|
||||
$projects = locale_translation_get_projects(array($project));
|
||||
$projects = locale_translation_get_projects([$project]);
|
||||
if (isset($projects[$project])) {
|
||||
$status[$project][$langcode] = locale_translation_source_build($projects[$project], $langcode);
|
||||
}
|
||||
|
@ -959,7 +955,7 @@ function locale_translation_status_save($project, $langcode, $type, $data) {
|
|||
break;
|
||||
}
|
||||
|
||||
\Drupal::state()->set('locale.translation_status', $status);
|
||||
\Drupal::keyValue('locale.translation_status')->set($project, $status[$project]);
|
||||
\Drupal::state()->set('locale.translation_last_checked', REQUEST_TIME);
|
||||
}
|
||||
}
|
||||
|
@ -978,8 +974,8 @@ function locale_translation_status_delete_languages($langcodes) {
|
|||
unset($status[$project][$langcode]);
|
||||
}
|
||||
}
|
||||
\Drupal::keyValue('locale.translation_status')->set($project, $status[$project]);
|
||||
}
|
||||
\Drupal::state()->set('locale.translation_status', $status);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -990,21 +986,14 @@ function locale_translation_status_delete_languages($langcodes) {
|
|||
* Project name(s) to be deleted from the cache.
|
||||
*/
|
||||
function locale_translation_status_delete_projects($projects) {
|
||||
$status = locale_translation_get_status();
|
||||
|
||||
foreach ($status as $project => $languages) {
|
||||
if (in_array($project, $projects)) {
|
||||
unset($status[$project]);
|
||||
}
|
||||
}
|
||||
\Drupal::state()->set('locale.translation_status', $status);
|
||||
\Drupal::keyValue('locale.translation_status')->deleteMultiple($projects);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the translation status cache.
|
||||
*/
|
||||
function locale_translation_clear_status() {
|
||||
\Drupal::state()->delete('locale.translation_status');
|
||||
\Drupal::keyValue('locale.translation_status')->deleteAll();
|
||||
\Drupal::state()->delete('locale.translation_last_checked');
|
||||
}
|
||||
|
||||
|
@ -1060,7 +1049,7 @@ function locale_string_is_safe($string) {
|
|||
// string. https://www.drupal.org/node/2372127
|
||||
$string = preg_replace('/\[[a-z0-9_-]+(:[a-z0-9_-]+)+\]/i', '', $string);
|
||||
|
||||
return Html::decodeEntities($string) == Html::decodeEntities(Xss::filter($string, array('a', 'abbr', 'acronym', 'address', 'b', 'bdo', 'big', 'blockquote', 'br', 'caption', 'cite', 'code', 'col', 'colgroup', 'dd', 'del', 'dfn', 'dl', 'dt', 'em', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'ins', 'kbd', 'li', 'ol', 'p', 'pre', 'q', 'samp', 'small', 'span', 'strong', 'sub', 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'tt', 'ul', 'var')));
|
||||
return Html::decodeEntities($string) == Html::decodeEntities(Xss::filter($string, ['a', 'abbr', 'acronym', 'address', 'b', 'bdo', 'big', 'blockquote', 'br', 'caption', 'cite', 'code', 'col', 'colgroup', 'dd', 'del', 'dfn', 'dl', 'dt', 'em', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'ins', 'kbd', 'li', 'ol', 'p', 'pre', 'q', 'samp', 'small', 'span', 'strong', 'sub', 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'tt', 'ul', 'var']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1077,11 +1066,11 @@ function locale_string_is_safe($string) {
|
|||
* (optional) List of string identifiers that have been updated / created.
|
||||
* If not provided, all caches for the affected languages are cleared.
|
||||
*/
|
||||
function _locale_refresh_translations($langcodes, $lids = array()) {
|
||||
function _locale_refresh_translations($langcodes, $lids = []) {
|
||||
if (!empty($langcodes)) {
|
||||
// Update javascript translations if any of the strings has a javascript
|
||||
// location, or if no string ids were provided, update all languages.
|
||||
if (empty($lids) || ($strings = \Drupal::service('locale.storage')->getStrings(array('lid' => $lids, 'type' => 'javascript')))) {
|
||||
if (empty($lids) || ($strings = \Drupal::service('locale.storage')->getStrings(['lid' => $lids, 'type' => 'javascript']))) {
|
||||
array_map('_locale_invalidate_js', $langcodes);
|
||||
}
|
||||
}
|
||||
|
@ -1186,22 +1175,22 @@ function _locale_parse_js_file($filepath) {
|
|||
[,\)]
|
||||
~sx', $file, $plural_matches);
|
||||
|
||||
$matches = array();
|
||||
$matches = [];
|
||||
|
||||
// Add strings from Drupal.t().
|
||||
foreach ($t_matches[1] as $key => $string) {
|
||||
$matches[] = array(
|
||||
$matches[] = [
|
||||
'source' => _locale_strip_quotes($string),
|
||||
'context' => _locale_strip_quotes($t_matches[2][$key]),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Add string from Drupal.formatPlural().
|
||||
foreach ($plural_matches[1] as $key => $string) {
|
||||
$matches[] = array(
|
||||
$matches[] = [
|
||||
'source' => _locale_strip_quotes($string) . LOCALE_PLURAL_DELIMITER . _locale_strip_quotes($plural_matches[2][$key]),
|
||||
'context' => _locale_strip_quotes($plural_matches[3][$key]),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Loop through all matches and process them.
|
||||
|
@ -1235,7 +1224,7 @@ function _locale_parse_js_file($filepath) {
|
|||
* New content of the 'system.javascript_parsed' variable.
|
||||
*/
|
||||
function _locale_invalidate_js($langcode = NULL) {
|
||||
$parsed = \Drupal::state()->get('system.javascript_parsed') ?: array();
|
||||
$parsed = \Drupal::state()->get('system.javascript_parsed') ?: [];
|
||||
|
||||
if (empty($langcode)) {
|
||||
// Invalidate all languages.
|
||||
|
@ -1275,12 +1264,12 @@ function _locale_rebuild_js($langcode = NULL) {
|
|||
|
||||
// Construct the array for JavaScript translations.
|
||||
// Only add strings with a translation to the translations array.
|
||||
$conditions = array(
|
||||
$conditions = [
|
||||
'type' => 'javascript',
|
||||
'language' => $language->getId(),
|
||||
'translated' => TRUE,
|
||||
);
|
||||
$translations = array();
|
||||
];
|
||||
$translations = [];
|
||||
foreach (\Drupal::service('locale.storage')->getTranslations($conditions) as $data) {
|
||||
$translations[$data->context][$data->source] = $data->translation;
|
||||
}
|
||||
|
@ -1289,9 +1278,9 @@ function _locale_rebuild_js($langcode = NULL) {
|
|||
$data_hash = NULL;
|
||||
$data = $status = '';
|
||||
if (!empty($translations)) {
|
||||
$data = array(
|
||||
$data = [
|
||||
'strings' => $translations,
|
||||
);
|
||||
];
|
||||
|
||||
$locale_plurals = \Drupal::service('locale.plural.formula')->getFormula($language->getId());
|
||||
if ($locale_plurals) {
|
||||
|
@ -1308,7 +1297,7 @@ function _locale_rebuild_js($langcode = NULL) {
|
|||
|
||||
// Delete old file, if we have no translations anymore, or a different file to
|
||||
// be saved.
|
||||
$locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: array();
|
||||
$locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: [];
|
||||
$changed_hash = !isset($locale_javascripts[$language->getId()]) || ($locale_javascripts[$language->getId()] != $data_hash);
|
||||
if (!empty($locale_javascripts[$language->getId()]) && (!$data || $changed_hash)) {
|
||||
file_unmanaged_delete($dir . '/' . $language->getId() . '_' . $locale_javascripts[$language->getId()] . '.js');
|
||||
|
@ -1359,24 +1348,24 @@ function _locale_rebuild_js($langcode = NULL) {
|
|||
$logger = \Drupal::logger('locale');
|
||||
switch ($status) {
|
||||
case 'updated':
|
||||
$logger->notice('Updated JavaScript translation file for the language %language.', array('%language' => $language->getName()));
|
||||
$logger->notice('Updated JavaScript translation file for the language %language.', ['%language' => $language->getName()]);
|
||||
return TRUE;
|
||||
|
||||
case 'rebuilt':
|
||||
$logger->warning('JavaScript translation file %file.js was lost.', array('%file' => $locale_javascripts[$language->getId()]));
|
||||
$logger->warning('JavaScript translation file %file.js was lost.', ['%file' => $locale_javascripts[$language->getId()]]);
|
||||
// Proceed to the 'created' case as the JavaScript translation file has
|
||||
// been created again.
|
||||
|
||||
case 'created':
|
||||
$logger->notice('Created JavaScript translation file for the language %language.', array('%language' => $language->getName()));
|
||||
$logger->notice('Created JavaScript translation file for the language %language.', ['%language' => $language->getName()]);
|
||||
return TRUE;
|
||||
|
||||
case 'deleted':
|
||||
$logger->notice('Removed JavaScript translation file for the language %language because no translations currently exist for that language.', array('%language' => $language->getName()));
|
||||
$logger->notice('Removed JavaScript translation file for the language %language because no translations currently exist for that language.', ['%language' => $language->getName()]);
|
||||
return TRUE;
|
||||
|
||||
case 'error':
|
||||
$logger->error('An error occurred during creation of the JavaScript translation file for the language %language.', array('%language' => $language->getName()));
|
||||
$logger->error('An error occurred during creation of the JavaScript translation file for the language %language.', ['%language' => $language->getName()]);
|
||||
return FALSE;
|
||||
|
||||
default:
|
||||
|
@ -1394,7 +1383,7 @@ function locale_translation_language_table($form_element) {
|
|||
// Remove checkboxes of languages without updates.
|
||||
if ($form_element['#not_found']) {
|
||||
foreach ($form_element['#not_found'] as $langcode) {
|
||||
$form_element[$langcode] = array();
|
||||
$form_element[$langcode] = [];
|
||||
}
|
||||
}
|
||||
return $form_element;
|
||||
|
|
|
@ -29,7 +29,7 @@ function locale_translation_manual_status() {
|
|||
if (batch_get()) {
|
||||
return batch_process('admin/reports/translations');
|
||||
}
|
||||
return new RedirectResponse(\Drupal::url('locale.translate_status', array(), array('absolute' => TRUE)));
|
||||
return new RedirectResponse(\Drupal::url('locale.translate_status', [], ['absolute' => TRUE]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,5 +72,5 @@ function template_preprocess_locale_translation_last_check(array &$variables) {
|
|||
$last = $variables['last'];
|
||||
$variables['last_checked'] = ($last != NULL);
|
||||
$variables['time'] = \Drupal::service('date.formatter')->formatTimeDiffSince($last);
|
||||
$variables['link'] = \Drupal::l(t('Check manually'), new Url('locale.check_translation', array(), array('query' => \Drupal::destination()->getAsArray())));
|
||||
$variables['link'] = \Drupal::l(t('Check manually'), new Url('locale.check_translation', [], ['query' => \Drupal::destination()->getAsArray()]));
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
services:
|
||||
locale.default.config.storage:
|
||||
class: Drupal\locale\LocaleDefaultConfigStorage
|
||||
arguments: ['@config.storage', '@language_manager']
|
||||
arguments: ['@config.storage', '@language_manager', '%install_profile%']
|
||||
public: false
|
||||
locale.config_manager:
|
||||
class: Drupal\locale\LocaleConfigManager
|
||||
|
|
|
@ -52,8 +52,8 @@ const LOCALE_TRANSLATION_SOURCE_COMPARE_GT = 1;
|
|||
*
|
||||
* @see locale_translation_build_projects()
|
||||
*/
|
||||
function locale_translation_get_projects(array $project_names = array()) {
|
||||
$projects = &drupal_static(__FUNCTION__, array());
|
||||
function locale_translation_get_projects(array $project_names = []) {
|
||||
$projects = &drupal_static(__FUNCTION__, []);
|
||||
|
||||
if (empty($projects)) {
|
||||
// Get project data from the database.
|
||||
|
@ -100,7 +100,7 @@ function locale_translation_clear_cache_projects() {
|
|||
* @see locale_translation_source_build()
|
||||
*/
|
||||
function locale_translation_load_sources(array $projects = NULL, array $langcodes = NULL) {
|
||||
$sources = array();
|
||||
$sources = [];
|
||||
$projects = $projects ? $projects : array_keys(locale_translation_get_projects());
|
||||
$langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list());
|
||||
|
||||
|
@ -129,8 +129,8 @@ function locale_translation_load_sources(array $projects = NULL, array $langcode
|
|||
*
|
||||
* @see locale_translation_source_build()
|
||||
*/
|
||||
function locale_translation_build_sources(array $projects = array(), array $langcodes = array()) {
|
||||
$sources = array();
|
||||
function locale_translation_build_sources(array $projects = [], array $langcodes = []) {
|
||||
$sources = [];
|
||||
$projects = locale_translation_get_projects($projects);
|
||||
$langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list());
|
||||
|
||||
|
@ -173,7 +173,7 @@ function locale_translation_source_check_file($source) {
|
|||
$directory = $source_file->directory;
|
||||
$filename = '/' . preg_quote($source_file->filename) . '$/';
|
||||
|
||||
if ($files = file_scan_directory($directory, $filename, array('key' => 'name', 'recurse' => FALSE))) {
|
||||
if ($files = file_scan_directory($directory, $filename, ['key' => 'name', 'recurse' => FALSE])) {
|
||||
$file = current($files);
|
||||
$source_file->uri = $file->uri;
|
||||
$source_file->timestamp = filemtime($file->uri);
|
||||
|
@ -244,35 +244,35 @@ function locale_translation_source_build($project, $langcode, $filename = NULL)
|
|||
// remote file. The local version of this file will only be checked if a
|
||||
// translations directory has been defined. If the server_pattern is a local
|
||||
// file path we will only check for a file in the local file system.
|
||||
$files = array();
|
||||
$files = [];
|
||||
if (_locale_translation_file_is_remote($source->server_pattern)) {
|
||||
$files[LOCALE_TRANSLATION_REMOTE] = (object) array(
|
||||
$files[LOCALE_TRANSLATION_REMOTE] = (object) [
|
||||
'project' => $project->name,
|
||||
'langcode' => $langcode,
|
||||
'version' => $project->version,
|
||||
'type' => LOCALE_TRANSLATION_REMOTE,
|
||||
'filename' => locale_translation_build_server_pattern($source, basename($source->server_pattern)),
|
||||
'uri' => locale_translation_build_server_pattern($source, $source->server_pattern),
|
||||
);
|
||||
$files[LOCALE_TRANSLATION_LOCAL] = (object) array(
|
||||
];
|
||||
$files[LOCALE_TRANSLATION_LOCAL] = (object) [
|
||||
'project' => $project->name,
|
||||
'langcode' => $langcode,
|
||||
'version' => $project->version,
|
||||
'type' => LOCALE_TRANSLATION_LOCAL,
|
||||
'filename' => locale_translation_build_server_pattern($source, $filename),
|
||||
'directory' => 'translations://',
|
||||
);
|
||||
];
|
||||
$files[LOCALE_TRANSLATION_LOCAL]->uri = $files[LOCALE_TRANSLATION_LOCAL]->directory . $files[LOCALE_TRANSLATION_LOCAL]->filename;
|
||||
}
|
||||
else {
|
||||
$files[LOCALE_TRANSLATION_LOCAL] = (object) array(
|
||||
$files[LOCALE_TRANSLATION_LOCAL] = (object) [
|
||||
'project' => $project->name,
|
||||
'langcode' => $langcode,
|
||||
'version' => $project->version,
|
||||
'type' => LOCALE_TRANSLATION_LOCAL,
|
||||
'filename' => locale_translation_build_server_pattern($source, basename($source->server_pattern)),
|
||||
'directory' => locale_translation_build_server_pattern($source, drupal_dirname($source->server_pattern)),
|
||||
);
|
||||
];
|
||||
$files[LOCALE_TRANSLATION_LOCAL]->uri = $files[LOCALE_TRANSLATION_LOCAL]->directory . '/' . $files[LOCALE_TRANSLATION_LOCAL]->filename;
|
||||
}
|
||||
$source->files = $files;
|
||||
|
@ -310,12 +310,12 @@ function locale_translation_source_build($project, $langcode, $filename = NULL)
|
|||
* String with replaced placeholders.
|
||||
*/
|
||||
function locale_translation_build_server_pattern($project, $template) {
|
||||
$variables = array(
|
||||
$variables = [
|
||||
'%project' => $project->name,
|
||||
'%version' => $project->version,
|
||||
'%core' => $project->core,
|
||||
'%language' => isset($project->langcode) ? $project->langcode : '%language',
|
||||
);
|
||||
];
|
||||
return strtr($template, $variables);
|
||||
}
|
||||
|
||||
|
@ -323,7 +323,7 @@ function locale_translation_build_server_pattern($project, $template) {
|
|||
* Populate a queue with project to check for translation updates.
|
||||
*/
|
||||
function locale_cron_fill_queue() {
|
||||
$updates = array();
|
||||
$updates = [];
|
||||
$config = \Drupal::config('locale.settings');
|
||||
|
||||
// Determine which project+language should be updated.
|
||||
|
@ -335,7 +335,7 @@ function locale_cron_fill_queue() {
|
|||
$files = db_select('locale_file', 'f')
|
||||
->condition('f.project', array_keys($projects), 'IN')
|
||||
->condition('f.last_checked', $last, '<')
|
||||
->fields('f', array('project', 'langcode'))
|
||||
->fields('f', ['project', 'langcode'])
|
||||
->execute()->fetchAll();
|
||||
foreach ($files as $file) {
|
||||
$updates[$file->project][] = $file->langcode;
|
||||
|
@ -343,7 +343,7 @@ function locale_cron_fill_queue() {
|
|||
// Update the last_checked timestamp of the project+language that will
|
||||
// be checked for updates.
|
||||
db_update('locale_file')
|
||||
->fields(array('last_checked' => REQUEST_TIME))
|
||||
->fields(['last_checked' => REQUEST_TIME])
|
||||
->condition('project', $file->project)
|
||||
->condition('langcode', $file->langcode)
|
||||
->execute();
|
||||
|
@ -357,7 +357,7 @@ function locale_cron_fill_queue() {
|
|||
$queue = \Drupal::queue('locale_translation', TRUE);
|
||||
|
||||
foreach ($updates as $project => $languages) {
|
||||
$batch = locale_translation_batch_update_build(array($project), $languages, $options);
|
||||
$batch = locale_translation_batch_update_build([$project], $languages, $options);
|
||||
foreach ($batch['operations'] as $item) {
|
||||
$queue->createItem($item);
|
||||
}
|
||||
|
@ -429,13 +429,13 @@ function _locale_translation_source_compare($source1, $source2) {
|
|||
*/
|
||||
function _locale_translation_default_update_options() {
|
||||
$config = \Drupal::config('locale.settings');
|
||||
return array(
|
||||
return [
|
||||
'customized' => LOCALE_NOT_CUSTOMIZED,
|
||||
'overwrite_options' => array(
|
||||
'overwrite_options' => [
|
||||
'not_customized' => $config->get('translation.overwrite_not_customized'),
|
||||
'customized' => $config->get('translation.overwrite_customized'),
|
||||
),
|
||||
],
|
||||
'finish_feedback' => TRUE,
|
||||
'use_remote' => locale_translation_use_remote_source(),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
|
|
@ -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'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -66,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();
|
||||
|
@ -75,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;
|
||||
}
|
||||
|
||||
|
@ -143,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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ class StringDatabaseStorage implements StringStorageInterface {
|
|||
$string->setVersion($version);
|
||||
$this->connection->update('locales_source', $this->options)
|
||||
->condition('lid', $string->getId())
|
||||
->fields(array('version' => $version))
|
||||
->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 = []);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,13 +18,13 @@ class LocaleConfigTranslationImportTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language', 'locale_test_translate');
|
||||
public static $modules = ['language', 'locale_test_translate'];
|
||||
|
||||
/**
|
||||
* Test update changes configuration translations if enabled after language.
|
||||
*/
|
||||
public function testConfigTranslationImport() {
|
||||
$admin_user = $this->drupalCreateUser(array('administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'administer permissions'));
|
||||
$admin_user = $this->drupalCreateUser(['administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'administer permissions']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Add a language. The Afrikaans translation file of locale_test_translate
|
||||
|
@ -32,7 +32,7 @@ class LocaleConfigTranslationImportTest extends WebTestBase {
|
|||
ConfigurableLanguage::createFromLangcode('af')->save();
|
||||
|
||||
// Enable locale module.
|
||||
$this->container->get('module_installer')->install(array('locale'));
|
||||
$this->container->get('module_installer')->install(['locale']);
|
||||
$this->resetAll();
|
||||
|
||||
// Enable import of translations. By default this is disabled for automated
|
||||
|
@ -42,9 +42,9 @@ class LocaleConfigTranslationImportTest extends WebTestBase {
|
|||
->save();
|
||||
|
||||
// Add translation permissions now that the locale module has been enabled.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'authenticated[translate interface]' => 'translate interface',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/people/permissions', $edit, t('Save permissions'));
|
||||
|
||||
// Check and update the translation status. This will import the Afrikaans
|
||||
|
@ -57,7 +57,7 @@ class LocaleConfigTranslationImportTest extends WebTestBase {
|
|||
$status['drupal']['af']->type = 'current';
|
||||
\Drupal::state()->set('locale.translation_status', $status);
|
||||
|
||||
$this->drupalPostForm('admin/reports/translations', array(), t('Update translations'));
|
||||
$this->drupalPostForm('admin/reports/translations', [], t('Update translations'));
|
||||
|
||||
// Check if configuration translations have been imported.
|
||||
$override = \Drupal::languageManager()->getLanguageConfigOverride('af', 'system.maintenance');
|
||||
|
@ -77,7 +77,7 @@ class LocaleConfigTranslationImportTest extends WebTestBase {
|
|||
// import. Test that this override is in place.
|
||||
$this->assertFalse($this->config('locale.settings')->get('translation.import_enabled'), 'Translations imports are disabled by default in the Testing profile.');
|
||||
|
||||
$admin_user = $this->drupalCreateUser(array('administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'administer permissions', 'translate configuration'));
|
||||
$admin_user = $this->drupalCreateUser(['administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'administer permissions', 'translate configuration']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Enable import of translations. By default this is disabled for automated
|
||||
|
@ -90,7 +90,7 @@ class LocaleConfigTranslationImportTest extends WebTestBase {
|
|||
$this->drupalPostForm('admin/config/regional/language/add', ['predefined_langcode' => 'af'], t('Add language'));
|
||||
|
||||
// Add the system branding block to the page.
|
||||
$this->drupalPlaceBlock('system_branding_block', array('region' => 'header', 'id' => 'site-branding'));
|
||||
$this->drupalPlaceBlock('system_branding_block', ['region' => 'header', 'id' => 'site-branding']);
|
||||
$this->drupalPostForm('admin/config/system/site-information', ['site_slogan' => 'Test site slogan'], 'Save configuration');
|
||||
$this->drupalPostForm('admin/config/system/site-information/translate/af/edit', ['translation[config_names][system.site][slogan]' => 'Test site slogan in Afrikaans'], 'Save translation');
|
||||
|
||||
|
@ -109,7 +109,7 @@ class LocaleConfigTranslationImportTest extends WebTestBase {
|
|||
->save();
|
||||
|
||||
// Install any module.
|
||||
$this->drupalPostForm('admin/modules', ['modules[Core][dblog][enable]' => 'dblog'], t('Install'));
|
||||
$this->drupalPostForm('admin/modules', ['modules[dblog][enable]' => 'dblog'], t('Install'));
|
||||
$this->assertText('Module Database Logging has been enabled.');
|
||||
|
||||
// Get the front page and ensure that the translated configuration still
|
||||
|
@ -130,12 +130,12 @@ class LocaleConfigTranslationImportTest extends WebTestBase {
|
|||
/**
|
||||
* Test removing a string from Locale deletes configuration translations.
|
||||
*/
|
||||
function testLocaleRemovalAndConfigOverrideDelete() {
|
||||
public function testLocaleRemovalAndConfigOverrideDelete() {
|
||||
// Enable the locale module.
|
||||
$this->container->get('module_installer')->install(['locale']);
|
||||
$this->resetAll();
|
||||
|
||||
$admin_user = $this->drupalCreateUser(array('administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'administer permissions', 'translate interface'));
|
||||
$admin_user = $this->drupalCreateUser(['administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'administer permissions', 'translate interface']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Enable import of translations. By default this is disabled for automated
|
||||
|
@ -153,7 +153,7 @@ class LocaleConfigTranslationImportTest extends WebTestBase {
|
|||
// Remove the string from translation to simulate a Locale removal. Note
|
||||
// that is no current way of doing this in the UI.
|
||||
$locale_storage = \Drupal::service('locale.storage');
|
||||
$string = $locale_storage->findString(array('source' => 'Locale can translate'));
|
||||
$string = $locale_storage->findString(['source' => 'Locale can translate']);
|
||||
\Drupal::service('locale.storage')->delete($string);
|
||||
// Force a rebuild of config translations.
|
||||
$count = Locale::config()->updateConfigTranslations(['locale_test_translate.settings'], ['af']);
|
||||
|
@ -167,12 +167,12 @@ class LocaleConfigTranslationImportTest extends WebTestBase {
|
|||
/**
|
||||
* Test removing a string from Locale changes configuration translations.
|
||||
*/
|
||||
function testLocaleRemovalAndConfigOverridePreserve() {
|
||||
public function testLocaleRemovalAndConfigOverridePreserve() {
|
||||
// Enable the locale module.
|
||||
$this->container->get('module_installer')->install(['locale']);
|
||||
$this->resetAll();
|
||||
|
||||
$admin_user = $this->drupalCreateUser(array('administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'administer permissions', 'translate interface'));
|
||||
$admin_user = $this->drupalCreateUser(['administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'administer permissions', 'translate interface']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Enable import of translations. By default this is disabled for automated
|
||||
|
@ -198,18 +198,18 @@ class LocaleConfigTranslationImportTest extends WebTestBase {
|
|||
$this->assertEqual($expected, $override->get());
|
||||
|
||||
// Set the translated string to empty.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => 'Locale can translate',
|
||||
'langcode' => 'af',
|
||||
'translation' => 'all',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$textareas = $this->xpath('//textarea');
|
||||
$textarea = current($textareas);
|
||||
$lid = (string) $textarea[0]['name'];
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$lid => '',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
|
||||
|
||||
$override = \Drupal::languageManager()->getLanguageConfigOverride('af', 'locale_test_translate.settings');
|
||||
|
|
|
@ -24,7 +24,7 @@ class LocaleConfigTranslationTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('locale', 'contact', 'contact_test');
|
||||
public static $modules = ['locale', 'contact', 'contact_test'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -42,15 +42,15 @@ class LocaleConfigTranslationTest extends WebTestBase {
|
|||
|
||||
// Add custom language.
|
||||
$this->langcode = 'xx';
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'translate interface', 'administer modules', 'access site-wide contact form', 'administer contact forms', 'administer site configuration'));
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages', 'translate interface', 'administer modules', 'access site-wide contact form', 'administer contact forms', 'administer site configuration']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$name = $this->randomMachineName(16);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => $this->langcode,
|
||||
'label' => $name,
|
||||
'direction' => LanguageInterface::DIRECTION_LTR,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
// Set path prefix.
|
||||
$edit = ["prefix[$this->langcode]" => $this->langcode];
|
||||
|
@ -63,23 +63,23 @@ class LocaleConfigTranslationTest extends WebTestBase {
|
|||
public function testConfigTranslation() {
|
||||
// Check that the maintenance message exists and create translation for it.
|
||||
$source = '@site is currently under maintenance. We should be back shortly. Thank you for your patience.';
|
||||
$string = $this->storage->findString(array('source' => $source, 'context' => '', 'type' => 'configuration'));
|
||||
$string = $this->storage->findString(['source' => $source, 'context' => '', 'type' => 'configuration']);
|
||||
$this->assertTrue($string, 'Configuration strings have been created upon installation.');
|
||||
|
||||
// Translate using the UI so configuration is refreshed.
|
||||
$message = $this->randomMachineName(20);
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $string->source,
|
||||
'langcode' => $this->langcode,
|
||||
'translation' => 'all',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$textareas = $this->xpath('//textarea');
|
||||
$textarea = current($textareas);
|
||||
$lid = (string) $textarea[0]['name'];
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$lid => $message,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
|
||||
|
||||
// Get translation and check we've only got the message.
|
||||
|
@ -88,22 +88,22 @@ class LocaleConfigTranslationTest extends WebTestBase {
|
|||
$this->assertEqual($translation['message'], $message);
|
||||
|
||||
// Check default medium date format exists and create a translation for it.
|
||||
$string = $this->storage->findString(array('source' => 'D, m/d/Y - H:i', 'context' => 'PHP date format', 'type' => 'configuration'));
|
||||
$string = $this->storage->findString(['source' => 'D, m/d/Y - H:i', 'context' => 'PHP date format', 'type' => 'configuration']);
|
||||
$this->assertTrue($string, 'Configuration date formats have been created upon installation.');
|
||||
|
||||
// Translate using the UI so configuration is refreshed.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $string->source,
|
||||
'langcode' => $this->langcode,
|
||||
'translation' => 'all',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$textareas = $this->xpath('//textarea');
|
||||
$textarea = current($textareas);
|
||||
$lid = (string) $textarea[0]['name'];
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$lid => 'D',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
|
||||
|
||||
$translation = \Drupal::languageManager()->getLanguageConfigOverride($this->langcode, 'core.date_format.medium')->get();
|
||||
|
@ -115,14 +115,14 @@ class LocaleConfigTranslationTest extends WebTestBase {
|
|||
$this->assertEqual($formatted_date, 'Tue', 'Got the right formatted date using the date format translation pattern.');
|
||||
|
||||
// Assert strings from image module config are not available.
|
||||
$string = $this->storage->findString(array('source' => 'Medium (220×220)', 'context' => '', 'type' => 'configuration'));
|
||||
$string = $this->storage->findString(['source' => 'Medium (220×220)', 'context' => '', 'type' => 'configuration']);
|
||||
$this->assertFalse($string, 'Configuration strings have been created upon installation.');
|
||||
|
||||
// Enable the image module.
|
||||
$this->drupalPostForm('admin/modules', array('modules[Field types][image][enable]' => "1"), t('Install'));
|
||||
$this->drupalPostForm('admin/modules', ['modules[image][enable]' => "1"], t('Install'));
|
||||
$this->rebuildContainer();
|
||||
|
||||
$string = $this->storage->findString(array('source' => 'Medium (220×220)', 'context' => '', 'type' => 'configuration'));
|
||||
$string = $this->storage->findString(['source' => 'Medium (220×220)', 'context' => '', 'type' => 'configuration']);
|
||||
$this->assertTrue($string, 'Configuration strings have been created upon installation.');
|
||||
$locations = $string->getLocations();
|
||||
$this->assertTrue(isset($locations['configuration']) && isset($locations['configuration']['image.style.medium']), 'Configuration string has been created with the right location');
|
||||
|
@ -136,17 +136,17 @@ class LocaleConfigTranslationTest extends WebTestBase {
|
|||
|
||||
// Translate using the UI so configuration is refreshed.
|
||||
$image_style_label = $this->randomMachineName(20);
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $string->source,
|
||||
'langcode' => $this->langcode,
|
||||
'translation' => 'all',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$textarea = current($this->xpath('//textarea'));
|
||||
$lid = (string) $textarea[0]['name'];
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$lid => $image_style_label,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
|
||||
|
||||
// Check the right single translation has been created.
|
||||
|
@ -159,8 +159,8 @@ class LocaleConfigTranslationTest extends WebTestBase {
|
|||
$this->assertEqual($translation['label'], $image_style_label, 'Got the right translation for image style name after translation');
|
||||
|
||||
// Uninstall the module.
|
||||
$this->drupalPostForm('admin/modules/uninstall', array('uninstall[image]' => "image"), t('Uninstall'));
|
||||
$this->drupalPostForm(NULL, array(), t('Uninstall'));
|
||||
$this->drupalPostForm('admin/modules/uninstall', ['uninstall[image]' => "image"], t('Uninstall'));
|
||||
$this->drupalPostForm(NULL, [], t('Uninstall'));
|
||||
|
||||
// Ensure that the translated configuration has been removed.
|
||||
$override = \Drupal::languageManager()->getLanguageConfigOverride('xx', 'image.style.medium');
|
||||
|
@ -168,17 +168,17 @@ class LocaleConfigTranslationTest extends WebTestBase {
|
|||
|
||||
// Translate default category using the UI so configuration is refreshed.
|
||||
$category_label = $this->randomMachineName(20);
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => 'Website feedback',
|
||||
'langcode' => $this->langcode,
|
||||
'translation' => 'all',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$textarea = current($this->xpath('//textarea'));
|
||||
$lid = (string) $textarea[0]['name'];
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$lid => $category_label,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
|
||||
|
||||
// Check if this category displayed in this language will use the
|
||||
|
@ -198,12 +198,12 @@ class LocaleConfigTranslationTest extends WebTestBase {
|
|||
public function testOptionalConfiguration() {
|
||||
$this->assertNodeConfig(FALSE, FALSE);
|
||||
// Enable the node module.
|
||||
$this->drupalPostForm('admin/modules', ['modules[Core][node][enable]' => "1"], t('Install'));
|
||||
$this->drupalPostForm('admin/modules', ['modules[node][enable]' => "1"], t('Install'));
|
||||
$this->drupalPostForm(NULL, [], t('Continue'));
|
||||
$this->rebuildContainer();
|
||||
$this->assertNodeConfig(TRUE, FALSE);
|
||||
// Enable the views module (which node provides some optional config for).
|
||||
$this->drupalPostForm('admin/modules', ['modules[Core][views][enable]' => "1"], t('Install'));
|
||||
$this->drupalPostForm('admin/modules', ['modules[views][enable]' => "1"], t('Install'));
|
||||
$this->rebuildContainer();
|
||||
$this->assertNodeConfig(TRUE, TRUE);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class LocaleExportTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('locale');
|
||||
public static $modules = ['locale'];
|
||||
|
||||
/**
|
||||
* A user able to create languages and export translations.
|
||||
|
@ -29,7 +29,7 @@ class LocaleExportTest extends WebTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages'));
|
||||
$this->adminUser = $this->drupalCreateUser(['administer languages', 'translate interface', 'access administration pages']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Copy test po files to the translations directory.
|
||||
|
@ -45,16 +45,16 @@ class LocaleExportTest extends WebTestBase {
|
|||
// This will also automatically add the 'fr' language.
|
||||
$name = \Drupal::service('file_system')->tempnam('temporary://', "po_") . '.po';
|
||||
file_put_contents($name, $this->getPoFile());
|
||||
$this->drupalPostForm('admin/config/regional/translate/import', array(
|
||||
$this->drupalPostForm('admin/config/regional/translate/import', [
|
||||
'langcode' => 'fr',
|
||||
'files[file]' => $name,
|
||||
), t('Import'));
|
||||
], t('Import'));
|
||||
drupal_unlink($name);
|
||||
|
||||
// Get the French translations.
|
||||
$this->drupalPostForm('admin/config/regional/translate/export', array(
|
||||
$this->drupalPostForm('admin/config/regional/translate/export', [
|
||||
'langcode' => 'fr',
|
||||
), t('Export'));
|
||||
], t('Export'));
|
||||
|
||||
// Ensure we have a translation file.
|
||||
$this->assertRaw('# French translation of Drupal', 'Exported French translation file.');
|
||||
|
@ -64,11 +64,11 @@ class LocaleExportTest extends WebTestBase {
|
|||
// Import some more French translations which will be marked as customized.
|
||||
$name = \Drupal::service('file_system')->tempnam('temporary://', "po2_") . '.po';
|
||||
file_put_contents($name, $this->getCustomPoFile());
|
||||
$this->drupalPostForm('admin/config/regional/translate/import', array(
|
||||
$this->drupalPostForm('admin/config/regional/translate/import', [
|
||||
'langcode' => 'fr',
|
||||
'files[file]' => $name,
|
||||
'customized' => 1,
|
||||
), t('Import'));
|
||||
], t('Import'));
|
||||
drupal_unlink($name);
|
||||
|
||||
// Create string without translation in the locales_source table.
|
||||
|
@ -79,12 +79,12 @@ class LocaleExportTest extends WebTestBase {
|
|||
->save();
|
||||
|
||||
// Export only customized French translations.
|
||||
$this->drupalPostForm('admin/config/regional/translate/export', array(
|
||||
$this->drupalPostForm('admin/config/regional/translate/export', [
|
||||
'langcode' => 'fr',
|
||||
'content_options[not_customized]' => FALSE,
|
||||
'content_options[customized]' => TRUE,
|
||||
'content_options[not_translated]' => FALSE,
|
||||
), t('Export'));
|
||||
], t('Export'));
|
||||
|
||||
// Ensure we have a translation file.
|
||||
$this->assertRaw('# French translation of Drupal', 'Exported French translation file with only customized strings.');
|
||||
|
@ -94,12 +94,12 @@ class LocaleExportTest extends WebTestBase {
|
|||
$this->assertNoRaw('msgid "February"', 'Untranslated string not present in exported file.');
|
||||
|
||||
// Export only untranslated French translations.
|
||||
$this->drupalPostForm('admin/config/regional/translate/export', array(
|
||||
$this->drupalPostForm('admin/config/regional/translate/export', [
|
||||
'langcode' => 'fr',
|
||||
'content_options[not_customized]' => FALSE,
|
||||
'content_options[customized]' => FALSE,
|
||||
'content_options[not_translated]' => TRUE,
|
||||
), t('Export'));
|
||||
], t('Export'));
|
||||
|
||||
// Ensure we have a translation file.
|
||||
$this->assertRaw('# French translation of Drupal', 'Exported French translation file with only untranslated strings.');
|
||||
|
@ -118,7 +118,7 @@ class LocaleExportTest extends WebTestBase {
|
|||
// the locales_source table gets populated with something.
|
||||
$this->drupalGet('admin/config/regional/language');
|
||||
// Get the translation template file.
|
||||
$this->drupalPostForm('admin/config/regional/translate/export', array(), t('Export'));
|
||||
$this->drupalPostForm('admin/config/regional/translate/export', [], t('Export'));
|
||||
// Ensure we have a translation file.
|
||||
$this->assertRaw('# LANGUAGE translation of PROJECT', 'Exported translation template file.');
|
||||
}
|
||||
|
|
|
@ -16,21 +16,21 @@ class LocaleFileSystemFormTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('system');
|
||||
public static $modules = ['system'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp(){
|
||||
parent::setUp();
|
||||
$account = $this->drupalCreateUser(array('administer site configuration'));
|
||||
$account = $this->drupalCreateUser(['administer site configuration']);
|
||||
$this->drupalLogin($account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests translation directory settings on the file settings form.
|
||||
*/
|
||||
function testFileConfigurationPage() {
|
||||
public function testFileConfigurationPage() {
|
||||
// By default there should be no setting for the translation directory.
|
||||
$this->drupalGet('admin/config/media/file-system');
|
||||
$this->assertNoFieldByName('translation_path');
|
||||
|
@ -44,9 +44,9 @@ class LocaleFileSystemFormTest extends WebTestBase {
|
|||
|
||||
// The setting should persist.
|
||||
$translation_path = $this->publicFilesDirectory . '/translations_changed';
|
||||
$fields = array(
|
||||
$fields = [
|
||||
'translation_path' => $translation_path
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $fields, t('Save configuration'));
|
||||
$this->drupalGet('admin/config/media/file-system');
|
||||
$this->assertFieldByName('translation_path', $translation_path);
|
||||
|
|
|
@ -17,7 +17,7 @@ class LocaleImportFunctionalTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('locale', 'dblog');
|
||||
public static $modules = ['locale', 'dblog'];
|
||||
|
||||
/**
|
||||
* A user able to create languages and import translations.
|
||||
|
@ -44,8 +44,8 @@ class LocaleImportFunctionalTest extends WebTestBase {
|
|||
file_unmanaged_copy(__DIR__ . '/../../tests/test.de.po', 'translations://', FILE_EXISTS_REPLACE);
|
||||
file_unmanaged_copy(__DIR__ . '/../../tests/test.xx.po', 'translations://', FILE_EXISTS_REPLACE);
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages'));
|
||||
$this->adminUserAccessSiteReports = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages', 'access site reports'));
|
||||
$this->adminUser = $this->drupalCreateUser(['administer languages', 'translate interface', 'access administration pages']);
|
||||
$this->adminUserAccessSiteReports = $this->drupalCreateUser(['administer languages', 'translate interface', 'access administration pages', 'access site reports']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Enable import of translations. By default this is disabled for automated
|
||||
|
@ -60,15 +60,15 @@ class LocaleImportFunctionalTest extends WebTestBase {
|
|||
*/
|
||||
public function testStandalonePoFile() {
|
||||
// Try importing a .po file.
|
||||
$this->importPoFile($this->getPoFile(), array(
|
||||
$this->importPoFile($this->getPoFile(), [
|
||||
'langcode' => 'fr',
|
||||
));
|
||||
]);
|
||||
$this->config('locale.settings');
|
||||
// The import should automatically create the corresponding language.
|
||||
$this->assertRaw(t('The language %language has been created.', array('%language' => 'French')), 'The language has been automatically created.');
|
||||
$this->assertRaw(t('The language %language has been created.', ['%language' => 'French']), 'The language has been automatically created.');
|
||||
|
||||
// The import should have created 8 strings.
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', array('%number' => 8, '%update' => 0, '%delete' => 0)), 'The translation file was successfully imported.');
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', ['%number' => 8, '%update' => 0, '%delete' => 0]), 'The translation file was successfully imported.');
|
||||
|
||||
// This import should have saved plural forms to have 2 variants.
|
||||
$locale_plurals = \Drupal::service('locale.plural.formula')->getNumberOfPlurals('fr');
|
||||
|
@ -78,14 +78,14 @@ class LocaleImportFunctionalTest extends WebTestBase {
|
|||
$this->assertUrl(\Drupal::url('locale.translate_page', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
|
||||
|
||||
// Try importing a .po file with invalid tags.
|
||||
$this->importPoFile($this->getBadPoFile(), array(
|
||||
$this->importPoFile($this->getBadPoFile(), [
|
||||
'langcode' => 'fr',
|
||||
));
|
||||
]);
|
||||
|
||||
// The import should have created 1 string and rejected 2.
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', array('%number' => 1, '%update' => 0, '%delete' => 0)), 'The translation file was successfully imported.');
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', ['%number' => 1, '%update' => 0, '%delete' => 0]), 'The translation file was successfully imported.');
|
||||
|
||||
$skip_message = \Drupal::translation()->formatPlural(2, 'One translation string was skipped because of disallowed or malformed HTML. <a href=":url">See the log</a> for details.', '@count translation strings were skipped because of disallowed or malformed HTML. See the log for details.', array(':url' => \Drupal::url('dblog.overview')));
|
||||
$skip_message = \Drupal::translation()->formatPlural(2, 'One translation string was skipped because of disallowed or malformed HTML. <a href=":url">See the log</a> for details.', '@count translation strings were skipped because of disallowed or malformed HTML. See the log for details.', [':url' => \Drupal::url('dblog.overview')]);
|
||||
$this->assertRaw($skip_message, 'Unsafe strings were skipped.');
|
||||
|
||||
// Repeat the process with a user that can access site reports, and this
|
||||
|
@ -93,19 +93,19 @@ class LocaleImportFunctionalTest extends WebTestBase {
|
|||
$this->drupalLogin($this->adminUserAccessSiteReports);
|
||||
|
||||
// Try importing a .po file with invalid tags.
|
||||
$this->importPoFile($this->getBadPoFile(), array(
|
||||
$this->importPoFile($this->getBadPoFile(), [
|
||||
'langcode' => 'fr',
|
||||
));
|
||||
]);
|
||||
|
||||
$skip_message = \Drupal::translation()->formatPlural(2, 'One translation string was skipped because of disallowed or malformed HTML. <a href=":url">See the log</a> for details.', '@count translation strings were skipped because of disallowed or malformed HTML. <a href=":url">See the log</a> for details.', array(':url' => \Drupal::url('dblog.overview')));
|
||||
$skip_message = \Drupal::translation()->formatPlural(2, 'One translation string was skipped because of disallowed or malformed HTML. <a href=":url">See the log</a> for details.', '@count translation strings were skipped because of disallowed or malformed HTML. <a href=":url">See the log</a> for details.', [':url' => \Drupal::url('dblog.overview')]);
|
||||
$this->assertRaw($skip_message, 'Unsafe strings were skipped.');
|
||||
|
||||
// Check empty files import with a user that cannot access site reports..
|
||||
$this->drupalLogin($this->adminUser);
|
||||
// Try importing a zero byte sized .po file.
|
||||
$this->importPoFile($this->getEmptyPoFile(), array(
|
||||
$this->importPoFile($this->getEmptyPoFile(), [
|
||||
'langcode' => 'fr',
|
||||
));
|
||||
]);
|
||||
// The import should have created 0 string and rejected 0.
|
||||
$this->assertRaw(t('One translation file could not be imported. See the log for details.'), 'The empty translation file import reported no translations imported.');
|
||||
|
||||
|
@ -113,35 +113,35 @@ class LocaleImportFunctionalTest extends WebTestBase {
|
|||
// time the different warnings must contain links to the log.
|
||||
$this->drupalLogin($this->adminUserAccessSiteReports);
|
||||
// Try importing a zero byte sized .po file.
|
||||
$this->importPoFile($this->getEmptyPoFile(), array(
|
||||
$this->importPoFile($this->getEmptyPoFile(), [
|
||||
'langcode' => 'fr',
|
||||
));
|
||||
]);
|
||||
// The import should have created 0 string and rejected 0.
|
||||
$this->assertRaw(t('One translation file could not be imported. <a href=":url">See the log</a> for details.', array(':url' => \Drupal::url('dblog.overview'))), 'The empty translation file import reported no translations imported.');
|
||||
$this->assertRaw(t('One translation file could not be imported. <a href=":url">See the log</a> for details.', [':url' => \Drupal::url('dblog.overview')]), 'The empty translation file import reported no translations imported.');
|
||||
|
||||
// Try importing a .po file which doesn't exist.
|
||||
$name = $this->randomMachineName(16);
|
||||
$this->drupalPostForm('admin/config/regional/translate/import', array(
|
||||
$this->drupalPostForm('admin/config/regional/translate/import', [
|
||||
'langcode' => 'fr',
|
||||
'files[file]' => $name,
|
||||
), t('Import'));
|
||||
], t('Import'));
|
||||
$this->assertUrl(\Drupal::url('locale.translate_import', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
|
||||
$this->assertText(t('File to import not found.'), 'File to import not found message.');
|
||||
|
||||
// Try importing a .po file with overriding strings, and ensure existing
|
||||
// strings are kept.
|
||||
$this->importPoFile($this->getOverwritePoFile(), array(
|
||||
$this->importPoFile($this->getOverwritePoFile(), [
|
||||
'langcode' => 'fr',
|
||||
));
|
||||
]);
|
||||
|
||||
// The import should have created 1 string.
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', array('%number' => 1, '%update' => 0, '%delete' => 0)), 'The translation file was successfully imported.');
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', ['%number' => 1, '%update' => 0, '%delete' => 0]), 'The translation file was successfully imported.');
|
||||
// Ensure string wasn't overwritten.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => 'Montag',
|
||||
'langcode' => 'fr',
|
||||
'translation' => 'translated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertText(t('No strings available.'), 'String not overwritten by imported string.');
|
||||
|
||||
|
@ -151,19 +151,19 @@ class LocaleImportFunctionalTest extends WebTestBase {
|
|||
|
||||
// Try importing a .po file with overriding strings, and ensure existing
|
||||
// strings are overwritten.
|
||||
$this->importPoFile($this->getOverwritePoFile(), array(
|
||||
$this->importPoFile($this->getOverwritePoFile(), [
|
||||
'langcode' => 'fr',
|
||||
'overwrite_options[not_customized]' => TRUE,
|
||||
));
|
||||
]);
|
||||
|
||||
// The import should have updated 2 strings.
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', array('%number' => 0, '%update' => 2, '%delete' => 0)), 'The translation file was successfully imported.');
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', ['%number' => 0, '%update' => 2, '%delete' => 0]), 'The translation file was successfully imported.');
|
||||
// Ensure string was overwritten.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => 'Montag',
|
||||
'langcode' => 'fr',
|
||||
'translation' => 'translated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertNoText(t('No strings available.'), 'String overwritten by imported string.');
|
||||
// This import should have changed number of plural forms.
|
||||
|
@ -171,54 +171,54 @@ class LocaleImportFunctionalTest extends WebTestBase {
|
|||
$this->assertEqual(3, $locale_plurals, 'Plural numbers changed.');
|
||||
|
||||
// Importing a .po file and mark its strings as customized strings.
|
||||
$this->importPoFile($this->getCustomPoFile(), array(
|
||||
$this->importPoFile($this->getCustomPoFile(), [
|
||||
'langcode' => 'fr',
|
||||
'customized' => TRUE,
|
||||
));
|
||||
]);
|
||||
|
||||
// The import should have created 6 strings.
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', array('%number' => 6, '%update' => 0, '%delete' => 0)), 'The customized translation file was successfully imported.');
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', ['%number' => 6, '%update' => 0, '%delete' => 0]), 'The customized translation file was successfully imported.');
|
||||
|
||||
// The database should now contain 6 customized strings (two imported
|
||||
// strings are not translated).
|
||||
$count = db_query('SELECT COUNT(*) FROM {locales_target} WHERE customized = :custom', array(':custom' => 1))->fetchField();
|
||||
$count = db_query('SELECT COUNT(*) FROM {locales_target} WHERE customized = :custom', [':custom' => 1])->fetchField();
|
||||
$this->assertEqual($count, 6, 'Customized translations successfully imported.');
|
||||
|
||||
// Try importing a .po file with overriding strings, and ensure existing
|
||||
// customized strings are kept.
|
||||
$this->importPoFile($this->getCustomOverwritePoFile(), array(
|
||||
$this->importPoFile($this->getCustomOverwritePoFile(), [
|
||||
'langcode' => 'fr',
|
||||
'overwrite_options[not_customized]' => TRUE,
|
||||
'overwrite_options[customized]' => FALSE,
|
||||
));
|
||||
]);
|
||||
|
||||
// The import should have created 1 string.
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', array('%number' => 1, '%update' => 0, '%delete' => 0)), 'The customized translation file was successfully imported.');
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', ['%number' => 1, '%update' => 0, '%delete' => 0]), 'The customized translation file was successfully imported.');
|
||||
// Ensure string wasn't overwritten.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => 'januari',
|
||||
'langcode' => 'fr',
|
||||
'translation' => 'translated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertText(t('No strings available.'), 'Customized string not overwritten by imported string.');
|
||||
|
||||
// Try importing a .po file with overriding strings, and ensure existing
|
||||
// customized strings are overwritten.
|
||||
$this->importPoFile($this->getCustomOverwritePoFile(), array(
|
||||
$this->importPoFile($this->getCustomOverwritePoFile(), [
|
||||
'langcode' => 'fr',
|
||||
'overwrite_options[not_customized]' => FALSE,
|
||||
'overwrite_options[customized]' => TRUE,
|
||||
));
|
||||
]);
|
||||
|
||||
// The import should have updated 2 strings.
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', array('%number' => 0, '%update' => 2, '%delete' => 0)), 'The customized translation file was successfully imported.');
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', ['%number' => 0, '%update' => 2, '%delete' => 0]), 'The customized translation file was successfully imported.');
|
||||
// Ensure string was overwritten.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => 'januari',
|
||||
'langcode' => 'fr',
|
||||
'translation' => 'translated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertNoText(t('No strings available.'), 'Customized string overwritten by imported string.');
|
||||
|
||||
|
@ -229,14 +229,14 @@ class LocaleImportFunctionalTest extends WebTestBase {
|
|||
*/
|
||||
public function testLanguageContext() {
|
||||
// Try importing a .po file.
|
||||
$this->importPoFile($this->getPoFileWithContext(), array(
|
||||
$this->importPoFile($this->getPoFileWithContext(), [
|
||||
'langcode' => 'hr',
|
||||
));
|
||||
]);
|
||||
|
||||
// We cast the return value of t() to string so as to retrieve the
|
||||
// translated value, rendered as a string.
|
||||
$this->assertIdentical((string) t('May', array(), array('langcode' => 'hr', 'context' => 'Long month name')), 'Svibanj', 'Long month name context is working.');
|
||||
$this->assertIdentical((string) t('May', array(), array('langcode' => 'hr')), 'Svi.', 'Default context is working.');
|
||||
$this->assertIdentical((string) t('May', [], ['langcode' => 'hr', 'context' => 'Long month name']), 'Svibanj', 'Long month name context is working.');
|
||||
$this->assertIdentical((string) t('May', [], ['langcode' => 'hr']), 'Svi.', 'Default context is working.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -246,26 +246,26 @@ class LocaleImportFunctionalTest extends WebTestBase {
|
|||
$langcode = 'hu';
|
||||
|
||||
// Try importing a .po file.
|
||||
$this->importPoFile($this->getPoFileWithMsgstr(), array(
|
||||
$this->importPoFile($this->getPoFileWithMsgstr(), [
|
||||
'langcode' => $langcode,
|
||||
));
|
||||
]);
|
||||
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', array('%number' => 1, '%update' => 0, '%delete' => 0)), 'The translation file was successfully imported.');
|
||||
$this->assertIdentical((string) t('Operations', array(), array('langcode' => $langcode)), 'Műveletek', 'String imported and translated.');
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', ['%number' => 1, '%update' => 0, '%delete' => 0]), 'The translation file was successfully imported.');
|
||||
$this->assertIdentical((string) t('Operations', [], ['langcode' => $langcode]), 'Műveletek', 'String imported and translated.');
|
||||
|
||||
// Try importing a .po file.
|
||||
$this->importPoFile($this->getPoFileWithEmptyMsgstr(), array(
|
||||
$this->importPoFile($this->getPoFileWithEmptyMsgstr(), [
|
||||
'langcode' => $langcode,
|
||||
'overwrite_options[not_customized]' => TRUE,
|
||||
));
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', array('%number' => 0, '%update' => 0, '%delete' => 1)), 'The translation file was successfully imported.');
|
||||
]);
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', ['%number' => 0, '%update' => 0, '%delete' => 1]), 'The translation file was successfully imported.');
|
||||
|
||||
$str = "Operations";
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $str,
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'untranslated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertText($str, 'Search found the string as untranslated.');
|
||||
}
|
||||
|
@ -276,27 +276,27 @@ class LocaleImportFunctionalTest extends WebTestBase {
|
|||
public function testConfigPoFile() {
|
||||
// Values for translations to assert. Config key, original string,
|
||||
// translation and config property name.
|
||||
$config_strings = array(
|
||||
'system.maintenance' => array(
|
||||
$config_strings = [
|
||||
'system.maintenance' => [
|
||||
'@site is currently under maintenance. We should be back shortly. Thank you for your patience.',
|
||||
'@site karbantartás alatt áll. Rövidesen visszatérünk. Köszönjük a türelmet.',
|
||||
'message',
|
||||
),
|
||||
'user.role.anonymous' => array(
|
||||
],
|
||||
'user.role.anonymous' => [
|
||||
'Anonymous user',
|
||||
'Névtelen felhasználó',
|
||||
'label',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
// Add custom language for testing.
|
||||
$langcode = 'xx';
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => $langcode,
|
||||
'label' => $this->randomMachineName(16),
|
||||
'direction' => LanguageInterface::DIRECTION_LTR,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
|
||||
// Check for the source strings we are going to translate. Adding the
|
||||
|
@ -304,24 +304,24 @@ class LocaleImportFunctionalTest extends WebTestBase {
|
|||
// strings to interface translation executed.
|
||||
$locale_storage = $this->container->get('locale.storage');
|
||||
foreach ($config_strings as $config_string) {
|
||||
$string = $locale_storage->findString(array('source' => $config_string[0], 'context' => '', 'type' => 'configuration'));
|
||||
$string = $locale_storage->findString(['source' => $config_string[0], 'context' => '', 'type' => 'configuration']);
|
||||
$this->assertTrue($string, 'Configuration strings have been created upon installation.');
|
||||
}
|
||||
|
||||
// Import a .po file to translate.
|
||||
$this->importPoFile($this->getPoFileWithConfig(), array(
|
||||
$this->importPoFile($this->getPoFileWithConfig(), [
|
||||
'langcode' => $langcode,
|
||||
));
|
||||
]);
|
||||
|
||||
// Translations got recorded in the interface translation system.
|
||||
foreach ($config_strings as $config_string) {
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $config_string[0],
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'all',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertText($config_string[1], format_string('Translation of @string found.', array('@string' => $config_string[0])));
|
||||
$this->assertText($config_string[1], format_string('Translation of @string found.', ['@string' => $config_string[0]]));
|
||||
}
|
||||
|
||||
// Test that translations got recorded in the config system.
|
||||
|
@ -340,8 +340,8 @@ class LocaleImportFunctionalTest extends WebTestBase {
|
|||
$langcode = 'de';
|
||||
|
||||
// Import a .po file to translate.
|
||||
$this->importPoFile($this->getPoFileWithConfigDe(), array(
|
||||
'langcode' => $langcode));
|
||||
$this->importPoFile($this->getPoFileWithConfigDe(), [
|
||||
'langcode' => $langcode]);
|
||||
|
||||
// Check that the 'Anonymous' string is translated.
|
||||
$config = \Drupal::languageManager()->getLanguageConfigOverride($langcode, 'user.settings');
|
||||
|
@ -353,7 +353,7 @@ class LocaleImportFunctionalTest extends WebTestBase {
|
|||
*/
|
||||
public function testCreatedLanguageTranslation() {
|
||||
// Import a .po file to add de language.
|
||||
$this->importPoFile($this->getPoFileWithConfigDe(), array('langcode' => 'de'));
|
||||
$this->importPoFile($this->getPoFileWithConfigDe(), ['langcode' => 'de']);
|
||||
|
||||
// Get the language.entity.de label and check it's been translated.
|
||||
$override = \Drupal::languageManager()->getLanguageConfigOverride('de', 'language.entity.de');
|
||||
|
@ -368,7 +368,7 @@ class LocaleImportFunctionalTest extends WebTestBase {
|
|||
* @param array $options
|
||||
* (optional) Additional options to pass to the translation import form.
|
||||
*/
|
||||
public function importPoFile($contents, array $options = array()) {
|
||||
public function importPoFile($contents, array $options = []) {
|
||||
$name = \Drupal::service('file_system')->tempnam('temporary://', "po_") . '.po';
|
||||
file_put_contents($name, $contents);
|
||||
$options['files[file]'] = $name;
|
||||
|
|
|
@ -18,7 +18,7 @@ class LocaleJavascriptTranslationTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('locale', 'locale_test');
|
||||
public static $modules = ['locale', 'locale_test'];
|
||||
|
||||
public function testFileParsing() {
|
||||
$filename = __DIR__ . '/../../tests/locale_test.js';
|
||||
|
@ -29,19 +29,19 @@ class LocaleJavascriptTranslationTest extends WebTestBase {
|
|||
// Get all of the source strings that were found.
|
||||
$strings = $this->container
|
||||
->get('locale.storage')
|
||||
->getStrings(array(
|
||||
->getStrings([
|
||||
'type' => 'javascript',
|
||||
'name' => $filename,
|
||||
));
|
||||
]);
|
||||
|
||||
$source_strings = array();
|
||||
$source_strings = [];
|
||||
foreach ($strings as $string) {
|
||||
$source_strings[$string->source] = $string->context;
|
||||
}
|
||||
|
||||
$etx = LOCALE_PLURAL_DELIMITER;
|
||||
// List of all strings that should be in the file.
|
||||
$test_strings = array(
|
||||
$test_strings = [
|
||||
'Standard Call t' => '',
|
||||
'Whitespace Call t' => '',
|
||||
|
||||
|
@ -73,11 +73,11 @@ class LocaleJavascriptTranslationTest extends WebTestBase {
|
|||
"Context Unquoted plural{$etx}Context Unquoted @count plural" => 'Context string unquoted',
|
||||
"Context Single Quoted plural{$etx}Context Single Quoted @count plural" => 'Context string single quoted',
|
||||
"Context Double Quoted plural{$etx}Context Double Quoted @count plural" => 'Context string double quoted',
|
||||
);
|
||||
];
|
||||
|
||||
// Assert that all strings were found properly.
|
||||
foreach ($test_strings as $str => $context) {
|
||||
$args = array('%source' => $str, '%context' => $context);
|
||||
$args = ['%source' => $str, '%context' => $context];
|
||||
|
||||
// Make sure that the string was found in the file.
|
||||
$this->assertTrue(isset($source_strings[$str]), SafeMarkup::format('Found source string: %source', $args));
|
||||
|
@ -95,7 +95,7 @@ class LocaleJavascriptTranslationTest extends WebTestBase {
|
|||
*/
|
||||
public function testLocaleTranslationJsDependencies() {
|
||||
// User to add and remove language.
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'translate interface'));
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages', 'translate interface']);
|
||||
|
||||
// Add custom language.
|
||||
$this->drupalLogin($admin_user);
|
||||
|
@ -105,16 +105,16 @@ class LocaleJavascriptTranslationTest extends WebTestBase {
|
|||
$name = $this->randomMachineName(16);
|
||||
// The domain prefix.
|
||||
$prefix = $langcode;
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => $langcode,
|
||||
'label' => $name,
|
||||
'direction' => LanguageInterface::DIRECTION_LTR,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
|
||||
// Set path prefix.
|
||||
$edit = array("prefix[$langcode]" => $prefix);
|
||||
$edit = ["prefix[$langcode]" => $prefix];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
|
||||
|
||||
// This forces locale.admin.js string sources to be imported, which contains
|
||||
|
@ -123,11 +123,11 @@ class LocaleJavascriptTranslationTest extends WebTestBase {
|
|||
|
||||
// Translate a string in locale.admin.js to our new language.
|
||||
$strings = \Drupal::service('locale.storage')
|
||||
->getStrings(array(
|
||||
->getStrings([
|
||||
'source' => 'Show description',
|
||||
'type' => 'javascript',
|
||||
'name' => 'core/modules/locale/locale.admin.js',
|
||||
));
|
||||
]);
|
||||
$string = $strings[0];
|
||||
|
||||
$this->drupalPostForm(NULL, ['string' => 'Show description'], t('Filter'));
|
||||
|
|
|
@ -19,7 +19,7 @@ class LocaleLibraryAlterTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('locale');
|
||||
public static $modules = ['locale'];
|
||||
|
||||
/**
|
||||
* Verifies that the datepicker can be localized.
|
||||
|
|
|
@ -24,7 +24,7 @@ class LocalePluralFormatTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('locale');
|
||||
public static $modules = ['locale'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -32,7 +32,7 @@ class LocalePluralFormatTest extends WebTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages'));
|
||||
$this->adminUser = $this->drupalCreateUser(['administer languages', 'translate interface', 'access administration pages']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
}
|
||||
|
||||
|
@ -43,23 +43,23 @@ class LocalePluralFormatTest extends WebTestBase {
|
|||
public function testGetPluralFormat() {
|
||||
// Import some .po files with formulas to set up the environment.
|
||||
// These will also add the languages to the system.
|
||||
$this->importPoFile($this->getPoFileWithSimplePlural(), array(
|
||||
$this->importPoFile($this->getPoFileWithSimplePlural(), [
|
||||
'langcode' => 'fr',
|
||||
));
|
||||
$this->importPoFile($this->getPoFileWithComplexPlural(), array(
|
||||
]);
|
||||
$this->importPoFile($this->getPoFileWithComplexPlural(), [
|
||||
'langcode' => 'hr',
|
||||
));
|
||||
]);
|
||||
|
||||
// Attempt to import some broken .po files as well to prove that these
|
||||
// will not overwrite the proper plural formula imported above.
|
||||
$this->importPoFile($this->getPoFileWithMissingPlural(), array(
|
||||
$this->importPoFile($this->getPoFileWithMissingPlural(), [
|
||||
'langcode' => 'fr',
|
||||
'overwrite_options[not_customized]' => TRUE,
|
||||
));
|
||||
$this->importPoFile($this->getPoFileWithBrokenPlural(), array(
|
||||
]);
|
||||
$this->importPoFile($this->getPoFileWithBrokenPlural(), [
|
||||
'langcode' => 'hr',
|
||||
'overwrite_options[not_customized]' => TRUE,
|
||||
));
|
||||
]);
|
||||
|
||||
// Reset static caches from locale_get_plural() to ensure we get fresh data.
|
||||
drupal_static_reset('locale_get_plural');
|
||||
|
@ -67,49 +67,49 @@ class LocalePluralFormatTest extends WebTestBase {
|
|||
drupal_static_reset('locale');
|
||||
|
||||
// Expected plural translation strings for each plural index.
|
||||
$plural_strings = array(
|
||||
$plural_strings = [
|
||||
// English is not imported in this case, so we assume built-in text
|
||||
// and formulas.
|
||||
'en' => array(
|
||||
'en' => [
|
||||
0 => '1 hour',
|
||||
1 => '@count hours',
|
||||
),
|
||||
'fr' => array(
|
||||
],
|
||||
'fr' => [
|
||||
0 => '@count heure',
|
||||
1 => '@count heures',
|
||||
),
|
||||
'hr' => array(
|
||||
],
|
||||
'hr' => [
|
||||
0 => '@count sat',
|
||||
1 => '@count sata',
|
||||
2 => '@count sati',
|
||||
),
|
||||
],
|
||||
// Hungarian is not imported, so it should assume the same text as
|
||||
// English, but it will always pick the plural form as per the built-in
|
||||
// logic, so only index -1 is relevant with the plural value.
|
||||
'hu' => array(
|
||||
'hu' => [
|
||||
0 => '1 hour',
|
||||
-1 => '@count hours',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
// Expected plural indexes precomputed base on the plural formulas with
|
||||
// given $count value.
|
||||
$plural_tests = array(
|
||||
'en' => array(
|
||||
$plural_tests = [
|
||||
'en' => [
|
||||
1 => 0,
|
||||
0 => 1,
|
||||
5 => 1,
|
||||
123 => 1,
|
||||
235 => 1,
|
||||
),
|
||||
'fr' => array(
|
||||
],
|
||||
'fr' => [
|
||||
1 => 0,
|
||||
0 => 0,
|
||||
5 => 1,
|
||||
123 => 1,
|
||||
235 => 1,
|
||||
),
|
||||
'hr' => array(
|
||||
],
|
||||
'hr' => [
|
||||
1 => 0,
|
||||
21 => 0,
|
||||
0 => 2,
|
||||
|
@ -117,13 +117,13 @@ class LocalePluralFormatTest extends WebTestBase {
|
|||
8 => 2,
|
||||
123 => 1,
|
||||
235 => 2,
|
||||
),
|
||||
'hu' => array(
|
||||
],
|
||||
'hu' => [
|
||||
1 => -1,
|
||||
21 => -1,
|
||||
0 => -1,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($plural_tests as $langcode => $tests) {
|
||||
foreach ($tests as $count => $expected_plural_index) {
|
||||
|
@ -133,14 +133,14 @@ class LocalePluralFormatTest extends WebTestBase {
|
|||
// expected index as per the logic for translation lookups.
|
||||
$expected_plural_index = ($count == 1) ? 0 : $expected_plural_index;
|
||||
$expected_plural_string = str_replace('@count', $count, $plural_strings[$langcode][$expected_plural_index]);
|
||||
$this->assertIdentical(\Drupal::translation()->formatPlural($count, '1 hour', '@count hours', array(), array('langcode' => $langcode))->render(), $expected_plural_string, 'Plural translation of 1 hours / @count hours for count ' . $count . ' in ' . $langcode . ' is ' . $expected_plural_string);
|
||||
$this->assertIdentical(\Drupal::translation()->formatPlural($count, '1 hour', '@count hours', [], ['langcode' => $langcode])->render(), $expected_plural_string, 'Plural translation of 1 hours / @count hours for count ' . $count . ' in ' . $langcode . ' is ' . $expected_plural_string);
|
||||
// DO NOT use translation to pass translated strings into
|
||||
// PluralTranslatableMarkup::createFromTranslatedString() this way. It
|
||||
// is designed to be used with *already* translated text like settings
|
||||
// from configuration. We use PHP translation here just because we have
|
||||
// the expected result data in that format.
|
||||
$translated_string = \Drupal::translation()->translate('1 hour' . PluralTranslatableMarkup::DELIMITER . '@count hours', array(), array('langcode' => $langcode));
|
||||
$plural = PluralTranslatableMarkup::createFromTranslatedString($count, $translated_string, array(), array('langcode' => $langcode));
|
||||
$translated_string = \Drupal::translation()->translate('1 hour' . PluralTranslatableMarkup::DELIMITER . '@count hours', [], ['langcode' => $langcode]);
|
||||
$plural = PluralTranslatableMarkup::createFromTranslatedString($count, $translated_string, [], ['langcode' => $langcode]);
|
||||
$this->assertIdentical($plural->render(), $expected_plural_string);
|
||||
}
|
||||
}
|
||||
|
@ -153,9 +153,9 @@ class LocalePluralFormatTest extends WebTestBase {
|
|||
|
||||
// Import some .po files with formulas to set up the environment.
|
||||
// These will also add the languages to the system.
|
||||
$this->importPoFile($this->getPoFileWithSimplePlural(), array(
|
||||
$this->importPoFile($this->getPoFileWithSimplePlural(), [
|
||||
'langcode' => 'fr',
|
||||
));
|
||||
]);
|
||||
|
||||
// Set French as the site default language.
|
||||
$this->config('system.site')->set('default_langcode', 'fr')->save();
|
||||
|
@ -170,12 +170,12 @@ class LocalePluralFormatTest extends WebTestBase {
|
|||
$this->assertText("seconde", "'Member for' text is translated.");
|
||||
|
||||
$path = 'admin/config/regional/translate/';
|
||||
$search = array(
|
||||
$search = [
|
||||
'langcode' => 'fr',
|
||||
// Limit to only translated strings to ensure that database ordering does
|
||||
// not break the test.
|
||||
'translation' => 'translated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm($path, $search, t('Filter'));
|
||||
// Plural values for the langcode fr.
|
||||
$this->assertText('@count seconde');
|
||||
|
@ -185,20 +185,20 @@ class LocalePluralFormatTest extends WebTestBase {
|
|||
// langcode here because the language will be English by default and will
|
||||
// not save our source string for performance optimization if we do not ask
|
||||
// specifically for a language.
|
||||
\Drupal::translation()->formatPlural(1, '1 second', '@count seconds', array(), array('langcode' => 'fr'))->render();
|
||||
$lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = ''", array(':source' => "1 second" . LOCALE_PLURAL_DELIMITER . "@count seconds"))->fetchField();
|
||||
\Drupal::translation()->formatPlural(1, '1 second', '@count seconds', [], ['langcode' => 'fr'])->render();
|
||||
$lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = ''", [':source' => "1 second" . LOCALE_PLURAL_DELIMITER . "@count seconds"])->fetchField();
|
||||
// Look up editing page for this plural string and check fields.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => '1 second',
|
||||
'langcode' => 'fr',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
|
||||
// Save complete translations for the string in langcode fr.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
"strings[$lid][translations][0]" => '1 seconde updated',
|
||||
"strings[$lid][translations][1]" => '@count secondes updated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm($path, $edit, t('Save translations'));
|
||||
|
||||
// User interface input for translating seconds should not be duplicated
|
||||
|
@ -218,17 +218,17 @@ class LocalePluralFormatTest extends WebTestBase {
|
|||
public function testPluralEditExport() {
|
||||
// Import some .po files with formulas to set up the environment.
|
||||
// These will also add the languages to the system.
|
||||
$this->importPoFile($this->getPoFileWithSimplePlural(), array(
|
||||
$this->importPoFile($this->getPoFileWithSimplePlural(), [
|
||||
'langcode' => 'fr',
|
||||
));
|
||||
$this->importPoFile($this->getPoFileWithComplexPlural(), array(
|
||||
]);
|
||||
$this->importPoFile($this->getPoFileWithComplexPlural(), [
|
||||
'langcode' => 'hr',
|
||||
));
|
||||
]);
|
||||
|
||||
// Get the French translations.
|
||||
$this->drupalPostForm('admin/config/regional/translate/export', array(
|
||||
$this->drupalPostForm('admin/config/regional/translate/export', [
|
||||
'langcode' => 'fr',
|
||||
), t('Export'));
|
||||
], t('Export'));
|
||||
// Ensure we have a translation file.
|
||||
$this->assertRaw('# French translation of Drupal', 'Exported French translation file.');
|
||||
// Ensure our imported translations exist in the file.
|
||||
|
@ -237,9 +237,9 @@ class LocalePluralFormatTest extends WebTestBase {
|
|||
$this->assertRaw("msgid \"1 hour\"\nmsgid_plural \"@count hours\"\nmsgstr[0] \"@count heure\"\nmsgstr[1] \"@count heures\"", 'Plural translations exported properly.');
|
||||
|
||||
// Get the Croatian translations.
|
||||
$this->drupalPostForm('admin/config/regional/translate/export', array(
|
||||
$this->drupalPostForm('admin/config/regional/translate/export', [
|
||||
'langcode' => 'hr',
|
||||
), t('Export'));
|
||||
], t('Export'));
|
||||
// Ensure we have a translation file.
|
||||
$this->assertRaw('# Croatian translation of Drupal', 'Exported Croatian translation file.');
|
||||
// Ensure our imported translations exist in the file.
|
||||
|
@ -254,9 +254,9 @@ class LocalePluralFormatTest extends WebTestBase {
|
|||
|
||||
// Look up editing page for this plural string and check fields.
|
||||
$path = 'admin/config/regional/translate/';
|
||||
$search = array(
|
||||
$search = [
|
||||
'langcode' => 'hr',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm($path, $search, t('Filter'));
|
||||
// Labels for plural editing elements.
|
||||
$this->assertText('Singular form');
|
||||
|
@ -270,15 +270,15 @@ class LocalePluralFormatTest extends WebTestBase {
|
|||
$this->assertText('@count sati');
|
||||
|
||||
// Edit langcode hr translations and see if that took effect.
|
||||
$lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = ''", array(':source' => "1 hour" . LOCALE_PLURAL_DELIMITER . "@count hours"))->fetchField();
|
||||
$edit = array(
|
||||
$lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = ''", [':source' => "1 hour" . LOCALE_PLURAL_DELIMITER . "@count hours"])->fetchField();
|
||||
$edit = [
|
||||
"strings[$lid][translations][1]" => '@count sata edited',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm($path, $edit, t('Save translations'));
|
||||
|
||||
$search = array(
|
||||
$search = [
|
||||
'langcode' => 'fr',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
// Plural values for the langcode fr.
|
||||
$this->assertText('@count heure');
|
||||
|
@ -286,57 +286,57 @@ class LocalePluralFormatTest extends WebTestBase {
|
|||
$this->assertNoText('2. plural form');
|
||||
|
||||
// Edit langcode fr translations and see if that took effect.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
"strings[$lid][translations][0]" => '@count heure edited',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm($path, $edit, t('Save translations'));
|
||||
|
||||
// Inject a plural source string to the database. We need to use a specific
|
||||
// langcode here because the language will be English by default and will
|
||||
// not save our source string for performance optimization if we do not ask
|
||||
// specifically for a language.
|
||||
\Drupal::translation()->formatPlural(1, '1 day', '@count days', array(), array('langcode' => 'fr'))->render();
|
||||
$lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = ''", array(':source' => "1 day" . LOCALE_PLURAL_DELIMITER . "@count days"))->fetchField();
|
||||
\Drupal::translation()->formatPlural(1, '1 day', '@count days', [], ['langcode' => 'fr'])->render();
|
||||
$lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = ''", [':source' => "1 day" . LOCALE_PLURAL_DELIMITER . "@count days"])->fetchField();
|
||||
// Look up editing page for this plural string and check fields.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => '1 day',
|
||||
'langcode' => 'fr',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
|
||||
// Save complete translations for the string in langcode fr.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
"strings[$lid][translations][0]" => '1 jour',
|
||||
"strings[$lid][translations][1]" => '@count jours',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm($path, $edit, t('Save translations'));
|
||||
|
||||
// Save complete translations for the string in langcode hr.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => '1 day',
|
||||
'langcode' => 'hr',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
|
||||
$edit = array(
|
||||
$edit = [
|
||||
"strings[$lid][translations][0]" => '@count dan',
|
||||
"strings[$lid][translations][1]" => '@count dana',
|
||||
"strings[$lid][translations][2]" => '@count dana',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm($path, $edit, t('Save translations'));
|
||||
|
||||
// Get the French translations.
|
||||
$this->drupalPostForm('admin/config/regional/translate/export', array(
|
||||
$this->drupalPostForm('admin/config/regional/translate/export', [
|
||||
'langcode' => 'fr',
|
||||
), t('Export'));
|
||||
], t('Export'));
|
||||
// Check for plural export specifically.
|
||||
$this->assertRaw("msgid \"1 hour\"\nmsgid_plural \"@count hours\"\nmsgstr[0] \"@count heure edited\"\nmsgstr[1] \"@count heures\"", 'Edited French plural translations for hours exported properly.');
|
||||
$this->assertRaw("msgid \"1 day\"\nmsgid_plural \"@count days\"\nmsgstr[0] \"1 jour\"\nmsgstr[1] \"@count jours\"", 'Added French plural translations for days exported properly.');
|
||||
|
||||
// Get the Croatian translations.
|
||||
$this->drupalPostForm('admin/config/regional/translate/export', array(
|
||||
$this->drupalPostForm('admin/config/regional/translate/export', [
|
||||
'langcode' => 'hr',
|
||||
), t('Export'));
|
||||
], t('Export'));
|
||||
// Check for plural export specifically.
|
||||
$this->assertRaw("msgid \"1 hour\"\nmsgid_plural \"@count hours\"\nmsgstr[0] \"@count sat\"\nmsgstr[1] \"@count sata edited\"\nmsgstr[2] \"@count sati\"", 'Edited Croatian plural translations exported properly.');
|
||||
$this->assertRaw("msgid \"1 day\"\nmsgid_plural \"@count days\"\nmsgstr[0] \"@count dan\"\nmsgstr[1] \"@count dana\"\nmsgstr[2] \"@count dana\"", 'Added Croatian plural translations exported properly.');
|
||||
|
@ -350,7 +350,7 @@ class LocalePluralFormatTest extends WebTestBase {
|
|||
* @param array $options
|
||||
* Additional options to pass to the translation import form.
|
||||
*/
|
||||
public function importPoFile($contents, array $options = array()) {
|
||||
public function importPoFile($contents, array $options = []) {
|
||||
$name = \Drupal::service('file_system')->tempnam('temporary://', "po_") . '.po';
|
||||
file_put_contents($name, $contents);
|
||||
$options['files[file]'] = $name;
|
||||
|
|
|
@ -23,14 +23,14 @@ class LocaleTranslateStringTourTest extends TourTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('locale', 'tour');
|
||||
public static $modules = ['locale', 'tour'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->adminUser = $this->drupalCreateUser(array('translate interface', 'access tour', 'administer languages'));
|
||||
$this->adminUser = $this->drupalCreateUser(['translate interface', 'access tour', 'administer languages']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ class LocaleTranslateStringTourTest extends TourTestBase {
|
|||
*/
|
||||
public function testTranslateStringTourTips() {
|
||||
// Add another language so there are no missing form items.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['predefined_langcode'] = 'es';
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
|
||||
|
|
|
@ -20,16 +20,16 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('locale');
|
||||
public static $modules = ['locale'];
|
||||
|
||||
/**
|
||||
* Enable interface translation to English.
|
||||
*/
|
||||
public function testEnglishTranslation() {
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
$this->drupalPostForm('admin/config/regional/language/edit/en', array('locale_translate_english' => TRUE), t('Save language'));
|
||||
$this->drupalPostForm('admin/config/regional/language/edit/en', ['locale_translate_english' => TRUE], t('Save language'));
|
||||
$this->assertLinkByHref('/admin/config/regional/translate?langcode=en', 0, 'Enabled interface translation to English.');
|
||||
}
|
||||
|
||||
|
@ -38,9 +38,9 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
*/
|
||||
public function testStringTranslation() {
|
||||
// User to add and remove language.
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages']);
|
||||
// User to translate and delete string.
|
||||
$translate_user = $this->drupalCreateUser(array('translate interface', 'access administration pages'));
|
||||
$translate_user = $this->drupalCreateUser(['translate interface', 'access administration pages']);
|
||||
// Code for the language.
|
||||
$langcode = 'xx';
|
||||
// The English name for the language. This will be translated.
|
||||
|
@ -51,15 +51,15 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
|
||||
// Add custom language.
|
||||
$this->drupalLogin($admin_user);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => $langcode,
|
||||
'label' => $name,
|
||||
'direction' => LanguageInterface::DIRECTION_LTR,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
// Add string.
|
||||
t($name, array(), array('langcode' => $langcode))->render();
|
||||
t($name, [], ['langcode' => $langcode])->render();
|
||||
// Reset locale cache.
|
||||
$this->container->get('string_translation')->reset();
|
||||
$this->assertRaw('"edit-languages-' . $langcode . '-weight"', 'Language code found.');
|
||||
|
@ -68,11 +68,11 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
|
||||
// Search for the name and translate it.
|
||||
$this->drupalLogin($translate_user);
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $name,
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'untranslated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertText($name, 'Search found the string as untranslated.');
|
||||
|
||||
|
@ -81,7 +81,7 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
$this->assertNoOption('edit-langcode', 'en', 'No way to translate the string to English.');
|
||||
$this->drupalLogout();
|
||||
$this->drupalLogin($admin_user);
|
||||
$this->drupalPostForm('admin/config/regional/language/edit/en', array('locale_translate_english' => TRUE), t('Save language'));
|
||||
$this->drupalPostForm('admin/config/regional/language/edit/en', ['locale_translate_english' => TRUE], t('Save language'));
|
||||
$this->drupalLogout();
|
||||
$this->drupalLogin($translate_user);
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
|
@ -90,55 +90,55 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
// Assume this is the only result, given the random name.
|
||||
$textarea = current($this->xpath('//textarea'));
|
||||
$lid = (string) $textarea[0]['name'];
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$lid => $translation,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
|
||||
$this->assertText(t('The strings have been saved.'), 'The strings have been saved.');
|
||||
$url_bits = explode('?', $this->getUrl());
|
||||
$this->assertEqual($url_bits[0], \Drupal::url('locale.translate_page', array(), array('absolute' => TRUE)), 'Correct page redirection.');
|
||||
$search = array(
|
||||
$this->assertEqual($url_bits[0], \Drupal::url('locale.translate_page', [], ['absolute' => TRUE]), 'Correct page redirection.');
|
||||
$search = [
|
||||
'string' => $name,
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'translated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertRaw($translation, 'Non-English translation properly saved.');
|
||||
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $name,
|
||||
'langcode' => 'en',
|
||||
'translation' => 'untranslated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$textarea = current($this->xpath('//textarea'));
|
||||
$lid = (string) $textarea[0]['name'];
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$lid => $translation_to_en,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $name,
|
||||
'langcode' => 'en',
|
||||
'translation' => 'translated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertRaw($translation_to_en, 'English translation properly saved.');
|
||||
|
||||
$this->assertTrue($name != $translation && t($name, array(), array('langcode' => $langcode)) == $translation, 't() works for non-English.');
|
||||
$this->assertTrue($name != $translation && t($name, [], ['langcode' => $langcode]) == $translation, 't() works for non-English.');
|
||||
// Refresh the locale() cache to get fresh data from t() below. We are in
|
||||
// the same HTTP request and therefore t() is not refreshed by saving the
|
||||
// translation above.
|
||||
$this->container->get('string_translation')->reset();
|
||||
// Now we should get the proper fresh translation from t().
|
||||
$this->assertTrue($name != $translation_to_en && t($name, array(), array('langcode' => 'en')) == $translation_to_en, 't() works for English.');
|
||||
$this->assertTrue(t($name, array(), array('langcode' => LanguageInterface::LANGCODE_SYSTEM)) == $name, 't() works for LanguageInterface::LANGCODE_SYSTEM.');
|
||||
$this->assertTrue($name != $translation_to_en && t($name, [], ['langcode' => 'en']) == $translation_to_en, 't() works for English.');
|
||||
$this->assertTrue(t($name, [], ['langcode' => LanguageInterface::LANGCODE_SYSTEM]) == $name, 't() works for LanguageInterface::LANGCODE_SYSTEM.');
|
||||
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $name,
|
||||
'langcode' => 'en',
|
||||
'translation' => 'untranslated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertText(t('No strings available.'), 'String is translated.');
|
||||
|
||||
|
@ -148,17 +148,17 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
$this->assertText('Enter the password that accompanies your username.');
|
||||
|
||||
$this->drupalLogin($translate_user);
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => 'accompanies your username',
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'untranslated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$textarea = current($this->xpath('//textarea'));
|
||||
$lid = (string) $textarea[0]['name'];
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$lid => 'Please enter your Llama username.',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
|
||||
|
||||
$this->drupalLogout();
|
||||
|
@ -169,9 +169,9 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
$this->drupalLogin($admin_user);
|
||||
$path = 'admin/config/regional/language/delete/' . $langcode;
|
||||
// This a confirm form, we do not need any fields changed.
|
||||
$this->drupalPostForm($path, array(), t('Delete'));
|
||||
$this->drupalPostForm($path, [], t('Delete'));
|
||||
// We need raw here because %language and %langcode will add HTML.
|
||||
$t_args = array('%language' => $name, '%langcode' => $langcode);
|
||||
$t_args = ['%language' => $name, '%langcode' => $langcode];
|
||||
$this->assertRaw(t('The %language (%langcode) language has been removed.', $t_args), 'The test language has been removed.');
|
||||
// Reload to remove $name.
|
||||
$this->drupalGet($path);
|
||||
|
@ -181,26 +181,26 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
|
||||
// Delete the string.
|
||||
$this->drupalLogin($translate_user);
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $name,
|
||||
'langcode' => 'en',
|
||||
'translation' => 'translated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
// Assume this is the only result, given the random name.
|
||||
$textarea = current($this->xpath('//textarea'));
|
||||
$lid = (string) $textarea[0]['name'];
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$lid => '',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
|
||||
$this->assertRaw($name, 'The strings have been saved.');
|
||||
$this->drupalLogin($translate_user);
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $name,
|
||||
'langcode' => 'en',
|
||||
'translation' => 'untranslated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertNoText(t('No strings available.'), 'The translation has been removed');
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
* properly created and rebuilt on deletion.
|
||||
*/
|
||||
public function testJavaScriptTranslation() {
|
||||
$user = $this->drupalCreateUser(array('translate interface', 'administer languages', 'access administration pages'));
|
||||
$user = $this->drupalCreateUser(['translate interface', 'administer languages', 'access administration pages']);
|
||||
$this->drupalLogin($user);
|
||||
$config = $this->config('locale.settings');
|
||||
|
||||
|
@ -219,12 +219,12 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
$name = $this->randomMachineName(16);
|
||||
|
||||
// Add custom language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => $langcode,
|
||||
'label' => $name,
|
||||
'direction' => LanguageInterface::DIRECTION_LTR,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
$this->container->get('language_manager')->reset();
|
||||
|
||||
|
@ -234,38 +234,38 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
// {locales_source} table and translate it.
|
||||
$query = db_select('locales_source', 's');
|
||||
$query->addJoin('INNER', 'locales_location', 'l', 's.lid = l.lid');
|
||||
$source = $query->fields('s', array('source'))
|
||||
$source = $query->fields('s', ['source'])
|
||||
->condition('l.type', 'javascript')
|
||||
->range(0, 1)
|
||||
->execute()
|
||||
->fetchField();
|
||||
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $source,
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'all',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
|
||||
$textarea = current($this->xpath('//textarea'));
|
||||
$lid = (string) $textarea[0]['name'];
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$lid => $this->randomMachineName(),
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
|
||||
|
||||
// Trigger JavaScript translation parsing and building.
|
||||
_locale_rebuild_js($langcode);
|
||||
|
||||
$locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: array();
|
||||
$locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: [];
|
||||
$js_file = 'public://' . $config->get('javascript.directory') . '/' . $langcode . '_' . $locale_javascripts[$langcode] . '.js';
|
||||
$this->assertTrue($result = file_exists($js_file), SafeMarkup::format('JavaScript file created: %file', array('%file' => $result ? $js_file : 'not found')));
|
||||
$this->assertTrue($result = file_exists($js_file), SafeMarkup::format('JavaScript file created: %file', ['%file' => $result ? $js_file : 'not found']));
|
||||
|
||||
// Test JavaScript translation rebuilding.
|
||||
file_unmanaged_delete($js_file);
|
||||
$this->assertTrue($result = !file_exists($js_file), SafeMarkup::format('JavaScript file deleted: %file', array('%file' => $result ? $js_file : 'found')));
|
||||
$this->assertTrue($result = !file_exists($js_file), SafeMarkup::format('JavaScript file deleted: %file', ['%file' => $result ? $js_file : 'found']));
|
||||
_locale_rebuild_js($langcode);
|
||||
$this->assertTrue($result = file_exists($js_file), SafeMarkup::format('JavaScript file rebuilt: %file', array('%file' => $result ? $js_file : 'not found')));
|
||||
$this->assertTrue($result = file_exists($js_file), SafeMarkup::format('JavaScript file rebuilt: %file', ['%file' => $result ? $js_file : 'not found']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -273,7 +273,7 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
*/
|
||||
public function testStringValidation() {
|
||||
// User to add language and strings.
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'translate interface'));
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages', 'translate interface']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$langcode = 'xx';
|
||||
// The English name for the language. This will be translated.
|
||||
|
@ -290,30 +290,30 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
$bad_translations[$key] = "<BODY ONLOAD=alert('xss')>" . $key;
|
||||
|
||||
// Add custom language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => $langcode,
|
||||
'label' => $name,
|
||||
'direction' => LanguageInterface::DIRECTION_LTR,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
// Add string.
|
||||
t($name, array(), array('langcode' => $langcode))->render();
|
||||
t($name, [], ['langcode' => $langcode])->render();
|
||||
// Reset locale cache.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $name,
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'all',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
// Find the edit path.
|
||||
|
||||
$textarea = current($this->xpath('//textarea'));
|
||||
$lid = (string) $textarea[0]['name'];
|
||||
foreach ($bad_translations as $translation) {
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$lid => $translation,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
|
||||
// Check for a form error on the textarea.
|
||||
$form_class = $this->xpath('//form[@id="locale-translate-edit-form"]//textarea/@class');
|
||||
|
@ -327,9 +327,9 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
*/
|
||||
public function testStringSearch() {
|
||||
// User to add and remove language.
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages']);
|
||||
// User to translate and delete string.
|
||||
$translate_user = $this->drupalCreateUser(array('translate interface', 'access administration pages'));
|
||||
$translate_user = $this->drupalCreateUser(['translate interface', 'access administration pages']);
|
||||
|
||||
// Code for the language.
|
||||
$langcode = 'xx';
|
||||
|
@ -340,35 +340,35 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
|
||||
// Add custom language.
|
||||
$this->drupalLogin($admin_user);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => $langcode,
|
||||
'label' => $name,
|
||||
'direction' => LanguageInterface::DIRECTION_LTR,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => 'yy',
|
||||
'label' => $this->randomMachineName(16),
|
||||
'direction' => LanguageInterface::DIRECTION_LTR,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
|
||||
// Add string.
|
||||
t($name, array(), array('langcode' => $langcode))->render();
|
||||
t($name, [], ['langcode' => $langcode])->render();
|
||||
// Reset locale cache.
|
||||
$this->container->get('string_translation')->reset();
|
||||
$this->drupalLogout();
|
||||
|
||||
// Search for the name.
|
||||
$this->drupalLogin($translate_user);
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $name,
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'all',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
// assertText() seems to remove the input field where $name always could be
|
||||
// found, so this is not a false assert. See how assertNoText succeeds
|
||||
|
@ -377,21 +377,21 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
|
||||
// Ensure untranslated string doesn't appear if searching on 'only
|
||||
// translated strings'.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $name,
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'translated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertText(t('No strings available.'), "Search didn't find the string.");
|
||||
|
||||
// Ensure untranslated string appears if searching on 'only untranslated
|
||||
// strings'.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $name,
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'untranslated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertNoText(t('No strings available.'), 'Search found the string.');
|
||||
|
||||
|
@ -400,66 +400,66 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
// We save the lid from the path.
|
||||
$textarea = current($this->xpath('//textarea'));
|
||||
$lid = (string) $textarea[0]['name'];
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$lid => $translation,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
|
||||
|
||||
// Ensure translated string does appear if searching on 'only
|
||||
// translated strings'.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $translation,
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'translated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertNoText(t('No strings available.'), 'Search found the translation.');
|
||||
|
||||
// Ensure translated source string doesn't appear if searching on 'only
|
||||
// untranslated strings'.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $name,
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'untranslated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertText(t('No strings available.'), "Search didn't find the source string.");
|
||||
|
||||
// Ensure translated string doesn't appear if searching on 'only
|
||||
// untranslated strings'.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $translation,
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'untranslated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertText(t('No strings available.'), "Search didn't find the translation.");
|
||||
|
||||
// Ensure translated string does appear if searching on the custom language.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $translation,
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'all',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertNoText(t('No strings available.'), 'Search found the translation.');
|
||||
|
||||
// Ensure translated string doesn't appear if searching in System (English).
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $translation,
|
||||
'langcode' => 'yy',
|
||||
'translation' => 'all',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertText(t('No strings available.'), "Search didn't find the translation.");
|
||||
|
||||
// Search for a string that isn't in the system.
|
||||
$unavailable_string = $this->randomMachineName(16);
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $unavailable_string,
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'all',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertText(t('No strings available.'), "Search didn't find the invalid string.");
|
||||
}
|
||||
|
@ -468,35 +468,35 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
* Tests that only changed strings are saved customized when edited.
|
||||
*/
|
||||
public function testUICustomizedStrings() {
|
||||
$user = $this->drupalCreateUser(array('translate interface', 'administer languages', 'access administration pages'));
|
||||
$user = $this->drupalCreateUser(['translate interface', 'administer languages', 'access administration pages']);
|
||||
$this->drupalLogin($user);
|
||||
ConfigurableLanguage::createFromLangcode('de')->save();
|
||||
|
||||
// Create test source string.
|
||||
$string = $this->container->get('locale.storage')->createString(array(
|
||||
$string = $this->container->get('locale.storage')->createString([
|
||||
'source' => $this->randomMachineName(100),
|
||||
'context' => $this->randomMachineName(20),
|
||||
))->save();
|
||||
])->save();
|
||||
|
||||
// Create translation for new string and save it as non-customized.
|
||||
$translation = $this->container->get('locale.storage')->createTranslation(array(
|
||||
$translation = $this->container->get('locale.storage')->createTranslation([
|
||||
'lid' => $string->lid,
|
||||
'language' => 'de',
|
||||
'translation' => $this->randomMachineName(100),
|
||||
'customized' => 0,
|
||||
))->save();
|
||||
])->save();
|
||||
|
||||
// Reset locale cache.
|
||||
$this->container->get('string_translation')->reset();
|
||||
|
||||
// Ensure non-customized translation string does appear if searching
|
||||
// non-customized translation.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $string->getString(),
|
||||
'langcode' => 'de',
|
||||
'translation' => 'translated',
|
||||
'customized' => '0',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
|
||||
$this->assertText($translation->getString(), 'Translation is found in search result.');
|
||||
|
@ -504,38 +504,38 @@ class LocaleTranslationUiTest extends WebTestBase {
|
|||
// Submit the translations without changing the translation.
|
||||
$textarea = current($this->xpath('//textarea'));
|
||||
$lid = (string) $textarea[0]['name'];
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$lid => $translation->getString(),
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
|
||||
|
||||
// Ensure unchanged translation string does appear if searching
|
||||
// non-customized translation.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $string->getString(),
|
||||
'langcode' => 'de',
|
||||
'translation' => 'translated',
|
||||
'customized' => '0',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertText($string->getString(), 'Translation is not marked as customized.');
|
||||
|
||||
// Submit the translations with a new translation.
|
||||
$textarea = current($this->xpath('//textarea'));
|
||||
$lid = (string) $textarea[0]['name'];
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$lid => $this->randomMachineName(100),
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
|
||||
|
||||
// Ensure changed translation string does appear if searching customized
|
||||
// translation.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => $string->getString(),
|
||||
'langcode' => 'de',
|
||||
'translation' => 'translated',
|
||||
'customized' => '1',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertText($string->getString(), "Translation is marked as customized.");
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ abstract class LocaleUpdateBase extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('locale', 'locale_test');
|
||||
public static $modules = ['locale', 'locale_test'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -85,10 +85,10 @@ abstract class LocaleUpdateBase extends WebTestBase {
|
|||
* The language code of the language to add.
|
||||
*/
|
||||
protected function addLanguage($langcode) {
|
||||
$edit = array('predefined_langcode' => $langcode);
|
||||
$edit = ['predefined_langcode' => $langcode];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
$this->container->get('language_manager')->reset();
|
||||
$this->assertTrue(\Drupal::languageManager()->getLanguage($langcode), SafeMarkup::format('Language %langcode added.', array('%langcode' => $langcode)));
|
||||
$this->assertTrue(\Drupal::languageManager()->getLanguage($langcode), SafeMarkup::format('Language %langcode added.', ['%langcode' => $langcode]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,7 +105,7 @@ abstract class LocaleUpdateBase extends WebTestBase {
|
|||
* singular strings are supported, no plurals. No double quotes are allowed
|
||||
* in source and translations strings.
|
||||
*/
|
||||
protected function makePoFile($path, $filename, $timestamp = NULL, array $translations = array()) {
|
||||
protected function makePoFile($path, $filename, $timestamp = NULL, array $translations = []) {
|
||||
$timestamp = $timestamp ? $timestamp : REQUEST_TIME;
|
||||
$path = 'public://' . $path;
|
||||
$text = '';
|
||||
|
@ -184,9 +184,9 @@ EOF;
|
|||
$config->set('translation.default_filename', '%project-%version.%language._po')->save();
|
||||
|
||||
// Setting up sets of translations for the translation files.
|
||||
$translations_one = array('January' => 'Januar_1', 'February' => 'Februar_1', 'March' => 'Marz_1');
|
||||
$translations_two = array('February' => 'Februar_2', 'March' => 'Marz_2', 'April' => 'April_2');
|
||||
$translations_three = array('April' => 'April_3', 'May' => 'Mai_3', 'June' => 'Juni_3');
|
||||
$translations_one = ['January' => 'Januar_1', 'February' => 'Februar_1', 'March' => 'Marz_1'];
|
||||
$translations_two = ['February' => 'Februar_2', 'March' => 'Marz_2', 'April' => 'April_2'];
|
||||
$translations_three = ['April' => 'April_3', 'May' => 'Mai_3', 'June' => 'Juni_3'];
|
||||
|
||||
// Add a number of files to the local file system to serve as remote
|
||||
// translation server and match the project definitions set in
|
||||
|
@ -212,71 +212,71 @@ EOF;
|
|||
// Add non customized translations to the database.
|
||||
$langcode = 'de';
|
||||
$context = '';
|
||||
$non_customized_translations = array(
|
||||
$non_customized_translations = [
|
||||
'March' => 'Marz',
|
||||
'June' => 'Juni',
|
||||
);
|
||||
];
|
||||
foreach ($non_customized_translations as $source => $translation) {
|
||||
$string = $this->container->get('locale.storage')->createString(array(
|
||||
$string = $this->container->get('locale.storage')->createString([
|
||||
'source' => $source,
|
||||
'context' => $context,
|
||||
))
|
||||
])
|
||||
->save();
|
||||
$this->container->get('locale.storage')->createTranslation(array(
|
||||
$this->container->get('locale.storage')->createTranslation([
|
||||
'lid' => $string->getId(),
|
||||
'language' => $langcode,
|
||||
'translation' => $translation,
|
||||
'customized' => LOCALE_NOT_CUSTOMIZED,
|
||||
))->save();
|
||||
])->save();
|
||||
}
|
||||
|
||||
// Add customized translations to the database.
|
||||
$customized_translations = array(
|
||||
$customized_translations = [
|
||||
'January' => 'Januar_customized',
|
||||
'February' => 'Februar_customized',
|
||||
'May' => 'Mai_customized',
|
||||
);
|
||||
];
|
||||
foreach ($customized_translations as $source => $translation) {
|
||||
$string = $this->container->get('locale.storage')->createString(array(
|
||||
$string = $this->container->get('locale.storage')->createString([
|
||||
'source' => $source,
|
||||
'context' => $context,
|
||||
))
|
||||
])
|
||||
->save();
|
||||
$this->container->get('locale.storage')->createTranslation(array(
|
||||
$this->container->get('locale.storage')->createTranslation([
|
||||
'lid' => $string->getId(),
|
||||
'language' => $langcode,
|
||||
'translation' => $translation,
|
||||
'customized' => LOCALE_CUSTOMIZED,
|
||||
))->save();
|
||||
])->save();
|
||||
}
|
||||
|
||||
// Add a state of current translations in locale_files.
|
||||
$default = array(
|
||||
$default = [
|
||||
'langcode' => $langcode,
|
||||
'uri' => '',
|
||||
'timestamp' => $this->timestampMedium,
|
||||
'last_checked' => $this->timestampMedium,
|
||||
);
|
||||
$data[] = array(
|
||||
];
|
||||
$data[] = [
|
||||
'project' => 'contrib_module_one',
|
||||
'filename' => 'contrib_module_one-8.x-1.1.de._po',
|
||||
'version' => '8.x-1.1',
|
||||
);
|
||||
$data[] = array(
|
||||
];
|
||||
$data[] = [
|
||||
'project' => 'contrib_module_two',
|
||||
'filename' => 'contrib_module_two-8.x-2.0-beta4.de._po',
|
||||
'version' => '8.x-2.0-beta4',
|
||||
);
|
||||
$data[] = array(
|
||||
];
|
||||
$data[] = [
|
||||
'project' => 'contrib_module_three',
|
||||
'filename' => 'contrib_module_three-8.x-1.0.de._po',
|
||||
'version' => '8.x-1.0',
|
||||
);
|
||||
$data[] = array(
|
||||
];
|
||||
$data[] = [
|
||||
'project' => 'custom_module_one',
|
||||
'filename' => 'custom_module_one.de.po',
|
||||
'version' => '',
|
||||
);
|
||||
];
|
||||
foreach ($data as $file) {
|
||||
$file = array_merge($default, $file);
|
||||
db_insert('locale_file')->fields($file)->execute();
|
||||
|
@ -297,9 +297,9 @@ EOF;
|
|||
* (optional) A message to display with the assertion.
|
||||
*/
|
||||
protected function assertTranslation($source, $translation, $langcode, $message = '') {
|
||||
$db_translation = db_query('SELECT translation FROM {locales_target} lt INNER JOIN {locales_source} ls ON ls.lid = lt.lid WHERE ls.source = :source AND lt.language = :langcode', array(':source' => $source, ':langcode' => $langcode))->fetchField();
|
||||
$db_translation = db_query('SELECT translation FROM {locales_target} lt INNER JOIN {locales_source} ls ON ls.lid = lt.lid WHERE ls.source = :source AND lt.language = :langcode', [':source' => $source, ':langcode' => $langcode])->fetchField();
|
||||
$db_translation = $db_translation == FALSE ? '' : $db_translation;
|
||||
$this->assertEqual($translation, $db_translation, $message ? $message : format_string('Correct translation of %source (%language)', array('%source' => $source, '%language' => $langcode)));
|
||||
$this->assertEqual($translation, $db_translation, $message ? $message : format_string('Correct translation of %source (%language)', ['%source' => $source, '%language' => $langcode]));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,14 +9,14 @@ namespace Drupal\locale\Tests;
|
|||
*/
|
||||
class LocaleUpdateCronTest extends LocaleUpdateBase {
|
||||
|
||||
protected $batchOutput = array();
|
||||
protected $batchOutput = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$admin_user = $this->drupalCreateUser(array('administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'translate interface'));
|
||||
$admin_user = $this->drupalCreateUser(['administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'translate interface']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$this->addLanguage('de');
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class LocaleUpdateCronTest extends LocaleUpdateBase {
|
|||
|
||||
// Update translations using batch to ensure a clean test starting point.
|
||||
$this->drupalGet('admin/reports/translations/check');
|
||||
$this->drupalPostForm('admin/reports/translations', array(), t('Update translations'));
|
||||
$this->drupalPostForm('admin/reports/translations', [], t('Update translations'));
|
||||
|
||||
// Store translation status for comparison.
|
||||
$initial_history = locale_translation_get_file_history();
|
||||
|
@ -48,16 +48,16 @@ class LocaleUpdateCronTest extends LocaleUpdateBase {
|
|||
// Prepare for test: Simulate that the file has not been checked for a long
|
||||
// time. Set the last_check timestamp to zero.
|
||||
$query = db_update('locale_file');
|
||||
$query->fields(array('last_checked' => 0));
|
||||
$query->fields(['last_checked' => 0]);
|
||||
$query->condition('project', 'contrib_module_two');
|
||||
$query->condition('langcode', 'de');
|
||||
$query->execute();
|
||||
|
||||
// Test: Disable cron update and verify that no tasks are added to the
|
||||
// queue.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'update_interval_days' => 0,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate/settings', $edit, t('Save configuration'));
|
||||
|
||||
// Execute locale cron tasks to add tasks to the queue.
|
||||
|
@ -70,9 +70,9 @@ class LocaleUpdateCronTest extends LocaleUpdateBase {
|
|||
// Test: Enable cron update and check if update tasks are added to the
|
||||
// queue.
|
||||
// Set cron update to Weekly.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'update_interval_days' => 7,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate/settings', $edit, t('Save configuration'));
|
||||
|
||||
// Execute locale cron tasks to add tasks to the queue.
|
||||
|
|
|
@ -11,14 +11,14 @@ use Drupal\simpletest\WebTestBase;
|
|||
*/
|
||||
class LocaleUpdateDevelopmentReleaseTest extends WebTestBase {
|
||||
|
||||
public static $modules = array('locale', 'locale_test_development_release');
|
||||
public static $modules = ['locale', 'locale_test_development_release'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
module_load_include('compare.inc', 'locale');
|
||||
$admin_user = $this->drupalCreateUser(array('administer modules', 'administer languages', 'access administration pages', 'translate interface'));
|
||||
$admin_user = $this->drupalCreateUser(['administer modules', 'administer languages', 'access administration pages', 'translate interface']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$this->drupalPostForm('admin/config/regional/language/add', array('predefined_langcode' => 'hu'), t('Add language'));
|
||||
$this->drupalPostForm('admin/config/regional/language/add', ['predefined_langcode' => 'hu'], t('Add language'));
|
||||
}
|
||||
|
||||
public function testLocaleUpdateDevelopmentRelease() {
|
||||
|
|
|
@ -17,14 +17,14 @@ class LocaleUpdateInterfaceTest extends LocaleUpdateBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('locale_test_translate');
|
||||
public static $modules = ['locale_test_translate'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$admin_user = $this->drupalCreateUser(array('administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'translate interface'));
|
||||
$admin_user = $this->drupalCreateUser(['administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'translate interface']);
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ class LocaleUpdateInterfaceTest extends LocaleUpdateBase {
|
|||
$this->assertNoText(t('Translation update status'), 'No status message');
|
||||
|
||||
$this->drupalGet('admin/reports/translations');
|
||||
$this->assertRaw(t('No translatable languages available. <a href=":add_language">Add a language</a> first.', array(':add_language' => \Drupal::url('entity.configurable_language.collection'))), 'Language message');
|
||||
$this->assertRaw(t('No translatable languages available. <a href=":add_language">Add a language</a> first.', [':add_language' => \Drupal::url('entity.configurable_language.collection')]), 'Language message');
|
||||
|
||||
// Add German language.
|
||||
$this->addLanguage('de');
|
||||
|
@ -49,7 +49,7 @@ class LocaleUpdateInterfaceTest extends LocaleUpdateBase {
|
|||
// Override Drupal core translation status as 'up-to-date'.
|
||||
$status = locale_translation_get_status();
|
||||
$status['drupal']['de']->type = 'current';
|
||||
\Drupal::state()->set('locale.translation_status', $status);
|
||||
\Drupal::keyValue('locale.translation_status')->set('drupal', $status['drupal']);
|
||||
|
||||
// One language added, all translations up to date.
|
||||
$this->drupalGet('admin/reports/status');
|
||||
|
@ -61,32 +61,32 @@ class LocaleUpdateInterfaceTest extends LocaleUpdateBase {
|
|||
// Set locale_test_translate module to have a local translation available.
|
||||
$status = locale_translation_get_status();
|
||||
$status['locale_test_translate']['de']->type = 'local';
|
||||
\Drupal::state()->set('locale.translation_status', $status);
|
||||
\Drupal::keyValue('locale.translation_status')->set('locale_test_translate', $status['locale_test_translate']);
|
||||
|
||||
// Check if updates are available for German.
|
||||
$this->drupalGet('admin/reports/status');
|
||||
$this->assertText(t('Translation update status'), 'Status message');
|
||||
$this->assertRaw(t('Updates available for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', array('@languages' => t('German'), ':updates' => \Drupal::url('locale.translate_status'))), 'Updates available message');
|
||||
$this->assertRaw(t('Updates available for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', ['@languages' => t('German'), ':updates' => \Drupal::url('locale.translate_status')]), 'Updates available message');
|
||||
$this->drupalGet('admin/reports/translations');
|
||||
$this->assertText(t('Updates for: @modules', array('@modules' => 'Locale test translate')), 'Translations available');
|
||||
$this->assertText(t('Updates for: @modules', ['@modules' => 'Locale test translate']), 'Translations available');
|
||||
|
||||
// Set locale_test_translate module to have a dev release and no
|
||||
// translation found.
|
||||
$status = locale_translation_get_status();
|
||||
$status['locale_test_translate']['de']->version = '1.3-dev';
|
||||
$status['locale_test_translate']['de']->type = '';
|
||||
\Drupal::state()->set('locale.translation_status', $status);
|
||||
\Drupal::keyValue('locale.translation_status')->set('locale_test_translate', $status['locale_test_translate']);
|
||||
|
||||
// Check if no updates were found.
|
||||
$this->drupalGet('admin/reports/status');
|
||||
$this->assertText(t('Translation update status'), 'Status message');
|
||||
$this->assertRaw(t('Missing translations for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', array('@languages' => t('German'), ':updates' => \Drupal::url('locale.translate_status'))), 'Missing translations message');
|
||||
$this->assertRaw(t('Missing translations for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', ['@languages' => t('German'), ':updates' => \Drupal::url('locale.translate_status')]), 'Missing translations message');
|
||||
$this->drupalGet('admin/reports/translations');
|
||||
$this->assertText(t('Missing translations for one project'), 'No translations found');
|
||||
$release_details = new FormattableMarkup('@module (@version). @info', [
|
||||
'@module' => 'Locale test translate',
|
||||
'@version' => '1.3-dev',
|
||||
'@info' => t('File not found at %local_path', array('%local_path' => 'core/modules/locale/tests/test.de.po'))
|
||||
'@info' => t('File not found at %local_path', ['%local_path' => 'core/modules/locale/tests/test.de.po'])
|
||||
]);
|
||||
$this->assertRaw($release_details->__toString(), 'Release details');
|
||||
|
||||
|
@ -95,24 +95,24 @@ class LocaleUpdateInterfaceTest extends LocaleUpdateBase {
|
|||
$status['drupal']['de']->type = '';
|
||||
$status['drupal']['de']->timestamp = 0;
|
||||
$status['drupal']['de']->version = '8.1.1';
|
||||
\Drupal::state()->set('locale.translation_status', $status);
|
||||
\Drupal::keyValue('locale.translation_status')->set('drupal', $status['drupal']);
|
||||
|
||||
// Check if Drupal core is not translated.
|
||||
$this->drupalGet('admin/reports/translations');
|
||||
$this->assertText(t('Missing translations for 2 projects'), 'No translations found');
|
||||
$this->assertText(t('@module (@version).', array('@module' => t('Drupal core'), '@version' => '8.1.1')), 'Release details');
|
||||
$this->assertText(t('@module (@version).', ['@module' => t('Drupal core'), '@version' => '8.1.1']), 'Release details');
|
||||
|
||||
// Override Drupal core translation status as 'translations available'.
|
||||
$status = locale_translation_get_status();
|
||||
$status['drupal']['de']->type = 'local';
|
||||
$status['drupal']['de']->files['local']->timestamp = REQUEST_TIME;
|
||||
$status['drupal']['de']->files['local']->info['version'] = '8.1.1';
|
||||
\Drupal::state()->set('locale.translation_status', $status);
|
||||
\Drupal::keyValue('locale.translation_status')->set('drupal', $status['drupal']);
|
||||
|
||||
// Check if translations are available for Drupal core.
|
||||
$this->drupalGet('admin/reports/translations');
|
||||
$this->assertText(t('Updates for: @project', array('@project' => t('Drupal core'))), 'Translations found');
|
||||
$this->assertText(SafeMarkup::format('@module (@date)', array('@module' => t('Drupal core'), '@date' => format_date(REQUEST_TIME, 'html_date'))), 'Core translation update');
|
||||
$this->assertText(t('Updates for: @project', ['@project' => t('Drupal core')]), 'Translations found');
|
||||
$this->assertText(SafeMarkup::format('@module (@date)', ['@module' => t('Drupal core'), '@date' => format_date(REQUEST_TIME, 'html_date')]), 'Core translation update');
|
||||
$update_button = $this->xpath('//input[@type="submit"][@value="' . t('Update translations') . '"]');
|
||||
$this->assertTrue($update_button, 'Update translations button');
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class LocaleUpdateTest extends LocaleUpdateBase {
|
|||
parent::setUp();
|
||||
module_load_include('compare.inc', 'locale');
|
||||
module_load_include('fetch.inc', 'locale');
|
||||
$admin_user = $this->drupalCreateUser(array('administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'translate interface'));
|
||||
$admin_user = $this->drupalCreateUser(['administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'translate interface']);
|
||||
$this->drupalLogin($admin_user);
|
||||
// We use German as test language. This language must match the translation
|
||||
// file that come with the locale_test module (test.de.po) and can therefore
|
||||
|
@ -42,7 +42,7 @@ class LocaleUpdateTest extends LocaleUpdateBase {
|
|||
$projects = locale_translation_project_list();
|
||||
$this->assertFalse(isset($projects['locale_test_translate']), 'Hidden module not found');
|
||||
$this->assertEqual($projects['locale_test']['info']['interface translation server pattern'], 'core/modules/locale/test/test.%language.po', 'Interface translation parameter found in project info.');
|
||||
$this->assertEqual($projects['locale_test']['name'], 'locale_test', format_string('%key found in project info.', array('%key' => 'interface translation project')));
|
||||
$this->assertEqual($projects['locale_test']['name'], 'locale_test', format_string('%key found in project info.', ['%key' => 'interface translation project']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,9 +74,9 @@ class LocaleUpdateTest extends LocaleUpdateBase {
|
|||
$config->set('translation.default_filename', '%project-%version.%language._po')->save();
|
||||
|
||||
// Set the test conditions.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'use_source' => LOCALE_TRANSLATION_USE_SOURCE_LOCAL,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate/settings', $edit, t('Save configuration'));
|
||||
|
||||
// Get status of translation sources at local file system.
|
||||
|
@ -90,9 +90,9 @@ class LocaleUpdateTest extends LocaleUpdateBase {
|
|||
$this->assertEqual($result['custom_module_one']['de']->type, LOCALE_TRANSLATION_LOCAL, 'Translation of custom_module_one found');
|
||||
|
||||
// Set the test conditions.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'use_source' => LOCALE_TRANSLATION_USE_SOURCE_REMOTE_AND_LOCAL,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate/settings', $edit, t('Save configuration'));
|
||||
|
||||
// Get status of translation sources at both local and remote locations.
|
||||
|
@ -124,10 +124,10 @@ class LocaleUpdateTest extends LocaleUpdateBase {
|
|||
$config->set('translation.default_filename', '%project-%version.%language._po');
|
||||
|
||||
// Set the update conditions for this test.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'use_source' => LOCALE_TRANSLATION_USE_SOURCE_REMOTE_AND_LOCAL,
|
||||
'overwrite' => LOCALE_TRANSLATION_OVERWRITE_ALL,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate/settings', $edit, t('Save configuration'));
|
||||
|
||||
// Get the translation status.
|
||||
|
@ -140,7 +140,7 @@ class LocaleUpdateTest extends LocaleUpdateBase {
|
|||
$this->assertText('Contributed module two (' . format_date($this->timestampNew, 'html_date') . ')', 'Updates for Contrib module two');
|
||||
|
||||
// Execute the translation update.
|
||||
$this->drupalPostForm('admin/reports/translations', array(), t('Update translations'));
|
||||
$this->drupalPostForm('admin/reports/translations', [], t('Update translations'));
|
||||
|
||||
// Check if the translation has been updated, using the status cache.
|
||||
$status = locale_translation_get_status();
|
||||
|
@ -161,13 +161,13 @@ class LocaleUpdateTest extends LocaleUpdateBase {
|
|||
$this->assertEqual($history['contrib_module_three']['de']->last_checked, $this->timestampMedium, 'Translation of contrib_module_three is not updated');
|
||||
|
||||
// Check whether existing translations have (not) been overwritten.
|
||||
$this->assertEqual(t('January', array(), array('langcode' => 'de')), 'Januar_1', 'Translation of January');
|
||||
$this->assertEqual(t('February', array(), array('langcode' => 'de')), 'Februar_2', 'Translation of February');
|
||||
$this->assertEqual(t('March', array(), array('langcode' => 'de')), 'Marz_2', 'Translation of March');
|
||||
$this->assertEqual(t('April', array(), array('langcode' => 'de')), 'April_2', 'Translation of April');
|
||||
$this->assertEqual(t('May', array(), array('langcode' => 'de')), 'Mai_customized', 'Translation of May');
|
||||
$this->assertEqual(t('June', array(), array('langcode' => 'de')), 'Juni', 'Translation of June');
|
||||
$this->assertEqual(t('Monday', array(), array('langcode' => 'de')), 'Montag', 'Translation of Monday');
|
||||
$this->assertEqual(t('January', [], ['langcode' => 'de']), 'Januar_1', 'Translation of January');
|
||||
$this->assertEqual(t('February', [], ['langcode' => 'de']), 'Februar_2', 'Translation of February');
|
||||
$this->assertEqual(t('March', [], ['langcode' => 'de']), 'Marz_2', 'Translation of March');
|
||||
$this->assertEqual(t('April', [], ['langcode' => 'de']), 'April_2', 'Translation of April');
|
||||
$this->assertEqual(t('May', [], ['langcode' => 'de']), 'Mai_customized', 'Translation of May');
|
||||
$this->assertEqual(t('June', [], ['langcode' => 'de']), 'Juni', 'Translation of June');
|
||||
$this->assertEqual(t('Monday', [], ['langcode' => 'de']), 'Montag', 'Translation of Monday');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -186,15 +186,15 @@ class LocaleUpdateTest extends LocaleUpdateBase {
|
|||
$config->set('translation.default_filename', '%project-%version.%language._po');
|
||||
|
||||
// Set the update conditions for this test.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'use_source' => LOCALE_TRANSLATION_USE_SOURCE_LOCAL,
|
||||
'overwrite' => LOCALE_TRANSLATION_OVERWRITE_ALL,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate/settings', $edit, t('Save configuration'));
|
||||
|
||||
// Execute the translation update.
|
||||
$this->drupalGet('admin/reports/translations/check');
|
||||
$this->drupalPostForm('admin/reports/translations', array(), t('Update translations'));
|
||||
$this->drupalPostForm('admin/reports/translations', [], t('Update translations'));
|
||||
|
||||
// Check if the translation has been updated, using the status cache.
|
||||
$status = locale_translation_get_status();
|
||||
|
@ -215,13 +215,13 @@ class LocaleUpdateTest extends LocaleUpdateBase {
|
|||
$this->assertEqual($history['contrib_module_three']['de']->last_checked, $this->timestampMedium, 'Translation of contrib_module_three is not updated');
|
||||
|
||||
// Check whether existing translations have (not) been overwritten.
|
||||
$this->assertEqual(t('January', array(), array('langcode' => 'de')), 'Januar_customized', 'Translation of January');
|
||||
$this->assertEqual(t('February', array(), array('langcode' => 'de')), 'Februar_2', 'Translation of February');
|
||||
$this->assertEqual(t('March', array(), array('langcode' => 'de')), 'Marz_2', 'Translation of March');
|
||||
$this->assertEqual(t('April', array(), array('langcode' => 'de')), 'April_2', 'Translation of April');
|
||||
$this->assertEqual(t('May', array(), array('langcode' => 'de')), 'Mai_customized', 'Translation of May');
|
||||
$this->assertEqual(t('June', array(), array('langcode' => 'de')), 'Juni', 'Translation of June');
|
||||
$this->assertEqual(t('Monday', array(), array('langcode' => 'de')), 'Montag', 'Translation of Monday');
|
||||
$this->assertEqual(t('January', [], ['langcode' => 'de']), 'Januar_customized', 'Translation of January');
|
||||
$this->assertEqual(t('February', [], ['langcode' => 'de']), 'Februar_2', 'Translation of February');
|
||||
$this->assertEqual(t('March', [], ['langcode' => 'de']), 'Marz_2', 'Translation of March');
|
||||
$this->assertEqual(t('April', [], ['langcode' => 'de']), 'April_2', 'Translation of April');
|
||||
$this->assertEqual(t('May', [], ['langcode' => 'de']), 'Mai_customized', 'Translation of May');
|
||||
$this->assertEqual(t('June', [], ['langcode' => 'de']), 'Juni', 'Translation of June');
|
||||
$this->assertEqual(t('Monday', [], ['langcode' => 'de']), 'Montag', 'Translation of Monday');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -240,24 +240,24 @@ class LocaleUpdateTest extends LocaleUpdateBase {
|
|||
$config->set('translation.default_filename', '%project-%version.%language._po');
|
||||
|
||||
// Set the test conditions.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'use_source' => LOCALE_TRANSLATION_USE_SOURCE_REMOTE_AND_LOCAL,
|
||||
'overwrite' => LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate/settings', $edit, t('Save configuration'));
|
||||
|
||||
// Execute translation update.
|
||||
$this->drupalGet('admin/reports/translations/check');
|
||||
$this->drupalPostForm('admin/reports/translations', array(), t('Update translations'));
|
||||
$this->drupalPostForm('admin/reports/translations', [], t('Update translations'));
|
||||
|
||||
// Check whether existing translations have (not) been overwritten.
|
||||
$this->assertEqual(t('January', array(), array('langcode' => 'de')), 'Januar_customized', 'Translation of January');
|
||||
$this->assertEqual(t('February', array(), array('langcode' => 'de')), 'Februar_customized', 'Translation of February');
|
||||
$this->assertEqual(t('March', array(), array('langcode' => 'de')), 'Marz_2', 'Translation of March');
|
||||
$this->assertEqual(t('April', array(), array('langcode' => 'de')), 'April_2', 'Translation of April');
|
||||
$this->assertEqual(t('May', array(), array('langcode' => 'de')), 'Mai_customized', 'Translation of May');
|
||||
$this->assertEqual(t('June', array(), array('langcode' => 'de')), 'Juni', 'Translation of June');
|
||||
$this->assertEqual(t('Monday', array(), array('langcode' => 'de')), 'Montag', 'Translation of Monday');
|
||||
$this->assertEqual(t('January', [], ['langcode' => 'de']), 'Januar_customized', 'Translation of January');
|
||||
$this->assertEqual(t('February', [], ['langcode' => 'de']), 'Februar_customized', 'Translation of February');
|
||||
$this->assertEqual(t('March', [], ['langcode' => 'de']), 'Marz_2', 'Translation of March');
|
||||
$this->assertEqual(t('April', [], ['langcode' => 'de']), 'April_2', 'Translation of April');
|
||||
$this->assertEqual(t('May', [], ['langcode' => 'de']), 'Mai_customized', 'Translation of May');
|
||||
$this->assertEqual(t('June', [], ['langcode' => 'de']), 'Juni', 'Translation of June');
|
||||
$this->assertEqual(t('Monday', [], ['langcode' => 'de']), 'Montag', 'Translation of Monday');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -276,15 +276,15 @@ class LocaleUpdateTest extends LocaleUpdateBase {
|
|||
$config->set('translation.default_filename', '%project-%version.%language._po');
|
||||
|
||||
// Set the test conditions.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'use_source' => LOCALE_TRANSLATION_USE_SOURCE_REMOTE_AND_LOCAL,
|
||||
'overwrite' => LOCALE_TRANSLATION_OVERWRITE_NONE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate/settings', $edit, t('Save configuration'));
|
||||
|
||||
// Execute translation update.
|
||||
$this->drupalGet('admin/reports/translations/check');
|
||||
$this->drupalPostForm('admin/reports/translations', array(), t('Update translations'));
|
||||
$this->drupalPostForm('admin/reports/translations', [], t('Update translations'));
|
||||
|
||||
// Check whether existing translations have (not) been overwritten.
|
||||
$this->assertTranslation('January', 'Januar_customized', 'de');
|
||||
|
@ -307,21 +307,21 @@ class LocaleUpdateTest extends LocaleUpdateBase {
|
|||
$this->assertTranslation('Tuesday', '', 'de');
|
||||
|
||||
// Enable a module.
|
||||
$edit = array(
|
||||
'modules[Testing][locale_test_translate][enable]' => 'locale_test_translate',
|
||||
);
|
||||
$edit = [
|
||||
'modules[locale_test_translate][enable]' => 'locale_test_translate',
|
||||
];
|
||||
$this->drupalPostForm('admin/modules', $edit, t('Install'));
|
||||
|
||||
// Check if translations have been imported.
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.',
|
||||
array('%number' => 7, '%update' => 0, '%delete' => 0)), 'One translation file imported.');
|
||||
['%number' => 7, '%update' => 0, '%delete' => 0]), 'One translation file imported.');
|
||||
$this->assertTranslation('Tuesday', 'Dienstag', 'de');
|
||||
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'uninstall[locale_test_translate]' => 1,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
|
||||
$this->drupalPostForm(NULL, array(), t('Uninstall'));
|
||||
$this->drupalPostForm(NULL, [], t('Uninstall'));
|
||||
|
||||
// Check if the file data is removed from the database.
|
||||
$history = locale_translation_get_file_history();
|
||||
|
@ -342,9 +342,9 @@ class LocaleUpdateTest extends LocaleUpdateBase {
|
|||
\Drupal::state()->set('locale.test_system_info_alter', TRUE);
|
||||
|
||||
// Enable a module.
|
||||
$edit = array(
|
||||
'modules[Testing][locale_test_translate][enable]' => 'locale_test_translate',
|
||||
);
|
||||
$edit = [
|
||||
'modules[locale_test_translate][enable]' => 'locale_test_translate',
|
||||
];
|
||||
$this->drupalPostForm('admin/modules', $edit, t('Install'));
|
||||
|
||||
// Check if there is no Dutch translation yet.
|
||||
|
@ -352,14 +352,14 @@ class LocaleUpdateTest extends LocaleUpdateBase {
|
|||
$this->assertTranslation('Tuesday', 'Dienstag', 'de');
|
||||
|
||||
// Add a language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'nl',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
|
||||
// Check if the right number of translations are added.
|
||||
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.',
|
||||
array('%number' => 8, '%update' => 0, '%delete' => 0)), 'One language added.');
|
||||
['%number' => 8, '%update' => 0, '%delete' => 0]), 'One language added.');
|
||||
$this->assertTranslation('Extraday', 'extra dag', 'nl');
|
||||
|
||||
// Check if the language data is added to the database.
|
||||
|
@ -367,7 +367,7 @@ class LocaleUpdateTest extends LocaleUpdateBase {
|
|||
$this->assertTrue($result, 'Files added to file history');
|
||||
|
||||
// Remove a language.
|
||||
$this->drupalPostForm('admin/config/regional/language/delete/nl', array(), t('Delete'));
|
||||
$this->drupalPostForm('admin/config/regional/language/delete/nl', [], t('Delete'));
|
||||
|
||||
// Check if the language data is removed from the database.
|
||||
$result = db_query("SELECT project FROM {locale_file} WHERE langcode='nl'")->fetchField();
|
||||
|
@ -386,21 +386,21 @@ class LocaleUpdateTest extends LocaleUpdateBase {
|
|||
\Drupal::state()->set('locale.test_system_info_alter', TRUE);
|
||||
|
||||
// Enable a module.
|
||||
$edit = array(
|
||||
'modules[Testing][locale_test_translate][enable]' => 'locale_test_translate',
|
||||
);
|
||||
$edit = [
|
||||
'modules[locale_test_translate][enable]' => 'locale_test_translate',
|
||||
];
|
||||
$this->drupalPostForm('admin/modules', $edit, t('Install'));
|
||||
|
||||
// Create a custom language with language code 'xx' and a random
|
||||
// name.
|
||||
$langcode = 'xx';
|
||||
$name = $this->randomMachineName(16);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => $langcode,
|
||||
'label' => $name,
|
||||
'direction' => LanguageInterface::DIRECTION_LTR,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
|
||||
// Ensure the translation file is automatically imported when the language
|
||||
|
@ -409,31 +409,31 @@ class LocaleUpdateTest extends LocaleUpdateBase {
|
|||
$this->assertText(t('One translation string was skipped because of disallowed or malformed HTML'), 'Language file automatically imported.');
|
||||
|
||||
// Ensure the strings were successfully imported.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => 'lundi',
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'translated',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertNoText(t('No strings available.'), 'String successfully imported.');
|
||||
|
||||
// Ensure the multiline string was imported.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => 'Source string for multiline translation',
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'all',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertText('Multiline translation string to make sure that import works with it.', 'String successfully imported.');
|
||||
|
||||
// Ensure 'Allowed HTML source string' was imported but the translation for
|
||||
// 'Another allowed HTML source string' was not because it contains invalid
|
||||
// HTML.
|
||||
$search = array(
|
||||
$search = [
|
||||
'string' => 'HTML source string',
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'all',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertText('Allowed HTML source string', 'String successfully imported.');
|
||||
$this->assertNoText('Another allowed HTML source string', 'String with disallowed translation not imported.');
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -57,10 +57,10 @@ function locale_test_locale_translation_projects_alter(&$projects) {
|
|||
$remote_url = $url . PublicStream::basePath() . '/remote/';
|
||||
|
||||
// Completely replace the project data with a set of test projects.
|
||||
$projects = array(
|
||||
'contrib_module_one' => array(
|
||||
$projects = [
|
||||
'contrib_module_one' => [
|
||||
'name' => 'contrib_module_one',
|
||||
'info' => array(
|
||||
'info' => [
|
||||
'name' => 'Contributed module one',
|
||||
'interface translation server pattern' => $remote_url . '%core/%project/%project-%version.%language._po',
|
||||
'package' => 'Other',
|
||||
|
@ -68,14 +68,14 @@ function locale_test_locale_translation_projects_alter(&$projects) {
|
|||
'project' => 'contrib_module_one',
|
||||
'datestamp' => '1344471537',
|
||||
'_info_file_ctime' => 1348767306,
|
||||
),
|
||||
],
|
||||
'datestamp' => '1344471537',
|
||||
'project_type' => 'module',
|
||||
'project_status' => TRUE,
|
||||
),
|
||||
'contrib_module_two' => array(
|
||||
],
|
||||
'contrib_module_two' => [
|
||||
'name' => 'contrib_module_two',
|
||||
'info' => array(
|
||||
'info' => [
|
||||
'name' => 'Contributed module two',
|
||||
'interface translation server pattern' => $remote_url . '%core/%project/%project-%version.%language._po',
|
||||
'package' => 'Other',
|
||||
|
@ -83,14 +83,14 @@ function locale_test_locale_translation_projects_alter(&$projects) {
|
|||
'project' => 'contrib_module_two',
|
||||
'datestamp' => '1344471537',
|
||||
'_info_file_ctime' => 1348767306,
|
||||
),
|
||||
],
|
||||
'datestamp' => '1344471537',
|
||||
'project_type' => 'module',
|
||||
'project_status' => TRUE,
|
||||
),
|
||||
'contrib_module_three' => array(
|
||||
],
|
||||
'contrib_module_three' => [
|
||||
'name' => 'contrib_module_three',
|
||||
'info' => array(
|
||||
'info' => [
|
||||
'name' => 'Contributed module three',
|
||||
'interface translation server pattern' => $remote_url . '%core/%project/%project-%version.%language._po',
|
||||
'package' => 'Other',
|
||||
|
@ -98,14 +98,14 @@ function locale_test_locale_translation_projects_alter(&$projects) {
|
|||
'project' => 'contrib_module_three',
|
||||
'datestamp' => '1344471537',
|
||||
'_info_file_ctime' => 1348767306,
|
||||
),
|
||||
],
|
||||
'datestamp' => '1344471537',
|
||||
'project_type' => 'module',
|
||||
'project_status' => TRUE,
|
||||
),
|
||||
'locale_test' => array(
|
||||
],
|
||||
'locale_test' => [
|
||||
'name' => 'locale_test',
|
||||
'info' => array(
|
||||
'info' => [
|
||||
'name' => 'Locale test',
|
||||
'interface translation project' => 'locale_test',
|
||||
'interface translation server pattern' => 'core/modules/locale/tests/test.%language.po',
|
||||
|
@ -114,14 +114,14 @@ function locale_test_locale_translation_projects_alter(&$projects) {
|
|||
'project' => 'locale_test',
|
||||
'_info_file_ctime' => 1348767306,
|
||||
'datestamp' => 0,
|
||||
),
|
||||
],
|
||||
'datestamp' => 0,
|
||||
'project_type' => 'module',
|
||||
'project_status' => TRUE,
|
||||
),
|
||||
'custom_module_one' => array(
|
||||
],
|
||||
'custom_module_one' => [
|
||||
'name' => 'custom_module_one',
|
||||
'info' => array(
|
||||
'info' => [
|
||||
'name' => 'Custom module one',
|
||||
'interface translation project' => 'custom_module_one',
|
||||
'interface translation server pattern' => 'translations://custom_module_one.%language.po',
|
||||
|
@ -130,12 +130,12 @@ function locale_test_locale_translation_projects_alter(&$projects) {
|
|||
'project' => 'custom_module_one',
|
||||
'_info_file_ctime' => 1348767306,
|
||||
'datestamp' => 0,
|
||||
),
|
||||
],
|
||||
'datestamp' => 0,
|
||||
'project_type' => 'module',
|
||||
'project_status' => TRUE,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,14 +27,14 @@ function locale_test_development_release_system_info_alter(&$info, Extension $fi
|
|||
function locale_test_development_release_locale_translation_projects_alter(&$projects) {
|
||||
$projects['contrib'] = [
|
||||
'name' => 'contrib',
|
||||
'info' => array(
|
||||
'info' => [
|
||||
'name' => 'Contributed module',
|
||||
'package' => 'Other',
|
||||
'version' => '12.x-10.4-unstable11+14-dev',
|
||||
'project' => 'contrib_module',
|
||||
'datestamp' => '0',
|
||||
'_info_file_ctime' => 1442933959,
|
||||
),
|
||||
],
|
||||
'datestamp' => '0',
|
||||
'project_type' => 'module',
|
||||
'project_status' => TRUE,
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\locale\Tests;
|
||||
namespace Drupal\Tests\locale\Functional;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\node\NodeInterface;
|
||||
|
||||
/**
|
||||
* Tests you can enable multilingual support on content types and configure a
|
||||
|
@ -11,21 +12,21 @@ use Drupal\Core\Language\LanguageInterface;
|
|||
*
|
||||
* @group locale
|
||||
*/
|
||||
class LocaleContentTest extends WebTestBase {
|
||||
class LocaleContentTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'locale');
|
||||
public static $modules = ['node', 'locale'];
|
||||
|
||||
/**
|
||||
* Verifies that machine name fields are always LTR.
|
||||
*/
|
||||
public function testMachineNameLTR() {
|
||||
// User to add and remove language.
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages', 'administer site configuration'));
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'administer content types', 'access administration pages', 'administer site configuration']);
|
||||
|
||||
// Log in as admin.
|
||||
$this->drupalLogin($admin_user);
|
||||
|
@ -35,13 +36,13 @@ class LocaleContentTest extends WebTestBase {
|
|||
$this->assertFieldByXpath('//input[@name="type" and @dir="ltr"]', NULL, 'The machine name field is LTR when no additional language is configured.');
|
||||
|
||||
// Install the Arabic language (which is RTL) and configure as the default.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['predefined_langcode'] = 'ar';
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'site_default_language' => 'ar',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration'));
|
||||
|
||||
// Verify that the machine name field is still LTR for a new content type.
|
||||
|
@ -57,9 +58,9 @@ class LocaleContentTest extends WebTestBase {
|
|||
$type2 = $this->drupalCreateContentType();
|
||||
|
||||
// User to add and remove language.
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages'));
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'administer content types', 'access administration pages']);
|
||||
// User to create a node.
|
||||
$web_user = $this->drupalCreateUser(array("create {$type1->id()} content", "create {$type2->id()} content", "edit any {$type2->id()} content"));
|
||||
$web_user = $this->drupalCreateUser(["create {$type1->id()} content", "create {$type2->id()} content", "edit any {$type2->id()} content"]);
|
||||
|
||||
// Add custom language.
|
||||
$this->drupalLogin($admin_user);
|
||||
|
@ -67,22 +68,22 @@ class LocaleContentTest extends WebTestBase {
|
|||
$langcode = 'xx';
|
||||
// The English name for the language.
|
||||
$name = $this->randomMachineName(16);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => $langcode,
|
||||
'label' => $name,
|
||||
'direction' => LanguageInterface::DIRECTION_LTR,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
|
||||
// Set the content type to use multilingual support.
|
||||
$this->drupalGet("admin/structure/types/manage/{$type2->id()}");
|
||||
$this->assertText(t('Language settings'), 'Multilingual support widget present on content type configuration form.');
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'language_configuration[language_alterable]' => TRUE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm("admin/structure/types/manage/{$type2->id()}", $edit, t('Save content type'));
|
||||
$this->assertRaw(t('The content type %type has been updated.', array('%type' => $type2->label())));
|
||||
$this->assertRaw(t('The content type %type has been updated.', ['%type' => $type2->label()]));
|
||||
$this->drupalLogout();
|
||||
\Drupal::languageManager()->reset();
|
||||
|
||||
|
@ -102,26 +103,26 @@ class LocaleContentTest extends WebTestBase {
|
|||
// Create a node.
|
||||
$node_title = $this->randomMachineName();
|
||||
$node_body = $this->randomMachineName();
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'type' => $type2->id(),
|
||||
'title' => $node_title,
|
||||
'body' => array(array('value' => $node_body)),
|
||||
'body' => [['value' => $node_body]],
|
||||
'langcode' => $langcode,
|
||||
);
|
||||
];
|
||||
$node = $this->drupalCreateNode($edit);
|
||||
// Edit the content and ensure correct language is selected.
|
||||
$path = 'node/' . $node->id() . '/edit';
|
||||
$this->drupalGet($path);
|
||||
$this->assertRaw('<option value="' . $langcode . '" selected="selected">' . $name . '</option>', 'Correct language selected.');
|
||||
// Ensure we can change the node language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'langcode[0][value]' => 'en',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm($path, $edit, t('Save'));
|
||||
$this->assertText(t('@title has been updated.', array('@title' => $node_title)));
|
||||
$this->assertText(t('@title has been updated.', ['@title' => $node_title]));
|
||||
|
||||
// Verify that the creation message contains a link to a node.
|
||||
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'node/' . $node->id()));
|
||||
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'node/' . $node->id()]);
|
||||
$this->assert(isset($view_link), 'The message area contains the link to the edited node');
|
||||
|
||||
$this->drupalLogout();
|
||||
|
@ -134,44 +135,44 @@ class LocaleContentTest extends WebTestBase {
|
|||
$type = $this->drupalCreateContentType();
|
||||
|
||||
// User to add and remove language.
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages'));
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'administer content types', 'access administration pages']);
|
||||
// User to create a node.
|
||||
$web_user = $this->drupalCreateUser(array("create {$type->id()} content", "edit own {$type->id()} content"));
|
||||
$web_user = $this->drupalCreateUser(["create {$type->id()} content", "edit own {$type->id()} content"]);
|
||||
|
||||
// Log in as admin.
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Install Arabic language.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['predefined_langcode'] = 'ar';
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
|
||||
// Install Spanish language.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['predefined_langcode'] = 'es';
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
\Drupal::languageManager()->reset();
|
||||
|
||||
// Set the content type to use multilingual support.
|
||||
$this->drupalGet("admin/structure/types/manage/{$type->id()}");
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'language_configuration[language_alterable]' => TRUE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm("admin/structure/types/manage/{$type->id()}", $edit, t('Save content type'));
|
||||
$this->assertRaw(t('The content type %type has been updated.', array('%type' => $type->label())));
|
||||
$this->assertRaw(t('The content type %type has been updated.', ['%type' => $type->label()]));
|
||||
$this->drupalLogout();
|
||||
|
||||
// Log in as web user to add new node.
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
// Create three nodes: English, Arabic and Spanish.
|
||||
$nodes = array();
|
||||
foreach (array('en', 'es', 'ar') as $langcode) {
|
||||
$nodes[$langcode] = $this->drupalCreateNode(array(
|
||||
$nodes = [];
|
||||
foreach (['en', 'es', 'ar'] as $langcode) {
|
||||
$nodes[$langcode] = $this->drupalCreateNode([
|
||||
'langcode' => $langcode,
|
||||
'type' => $type->id(),
|
||||
'promote' => NODE_PROMOTED,
|
||||
));
|
||||
'promote' => NodeInterface::PROMOTED,
|
||||
]);
|
||||
}
|
||||
|
||||
// Check if English node does not have lang tag.
|
|
@ -1,23 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\locale\Tests;
|
||||
namespace Drupal\Tests\locale\Functional;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests LocaleLookup.
|
||||
*
|
||||
* @group locale
|
||||
*/
|
||||
class LocaleLocaleLookupTest extends WebTestBase {
|
||||
class LocaleLocaleLookupTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('locale', 'locale_test');
|
||||
public static $modules = ['locale', 'locale_test'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -37,7 +37,7 @@ class LocaleLocaleLookupTest extends WebTestBase {
|
|||
*/
|
||||
public function testCircularDependency() {
|
||||
// Ensure that we can enable early_translation_test on a non-english site.
|
||||
$this->drupalPostForm('admin/modules', array('modules[Testing][early_translation_test][enable]' => TRUE), t('Install'));
|
||||
$this->drupalPostForm('admin/modules', ['modules[early_translation_test][enable]' => TRUE], t('Install'));
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ class LocaleLocaleLookupTest extends WebTestBase {
|
|||
$this->drupalGet('');
|
||||
// Ensure state of fallback languages persisted by
|
||||
// locale_test_language_fallback_candidates_locale_lookup_alter() is empty.
|
||||
$this->assertEqual(\Drupal::state()->get('locale.test_language_fallback_candidates_locale_lookup_alter_candidates'), array());
|
||||
$this->assertEqual(\Drupal::state()->get('locale.test_language_fallback_candidates_locale_lookup_alter_candidates'), []);
|
||||
// Make sure there is enough information provided for alter hooks.
|
||||
$context = \Drupal::state()->get('locale.test_language_fallback_candidates_locale_lookup_alter_context');
|
||||
$this->assertEqual($context['langcode'], 'fr');
|
|
@ -1,24 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\locale\Tests;
|
||||
namespace Drupal\Tests\locale\Functional;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests you can configure a language for individual URL aliases.
|
||||
*
|
||||
* @group locale
|
||||
*/
|
||||
class LocalePathTest extends WebTestBase {
|
||||
class LocalePathTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'locale', 'path', 'views');
|
||||
public static $modules = ['node', 'locale', 'path', 'views'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -26,7 +26,7 @@ class LocalePathTest extends WebTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
$this->config('system.site')->set('page.front', '/node')->save();
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ class LocalePathTest extends WebTestBase {
|
|||
*/
|
||||
public function testPathLanguageConfiguration() {
|
||||
// User to add and remove language.
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'create page content', 'administer url aliases', 'create url aliases', 'access administration pages', 'access content overview'));
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'create page content', 'administer url aliases', 'create url aliases', 'access administration pages', 'access content overview']);
|
||||
|
||||
// Add custom language.
|
||||
$this->drupalLogin($admin_user);
|
||||
|
@ -45,16 +45,16 @@ class LocalePathTest extends WebTestBase {
|
|||
$name = $this->randomMachineName(16);
|
||||
// The domain prefix.
|
||||
$prefix = $langcode;
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => $langcode,
|
||||
'label' => $name,
|
||||
'direction' => LanguageInterface::DIRECTION_LTR,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
|
||||
// Set path prefix.
|
||||
$edit = array("prefix[$langcode]" => $prefix);
|
||||
$edit = ["prefix[$langcode]" => $prefix];
|
||||
$this->drupalPostForm('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
|
||||
|
||||
// Check that the "xx" front page is readily available because path prefix
|
||||
|
@ -63,25 +63,25 @@ class LocalePathTest extends WebTestBase {
|
|||
$this->assertText(t('Welcome to Drupal'), 'The "xx" front page is readibly available.');
|
||||
|
||||
// Create a node.
|
||||
$node = $this->drupalCreateNode(array('type' => 'page'));
|
||||
$node = $this->drupalCreateNode(['type' => 'page']);
|
||||
|
||||
// Create a path alias in default language (English).
|
||||
$path = 'admin/config/search/path/add';
|
||||
$english_path = $this->randomMachineName(8);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'source' => '/node/' . $node->id(),
|
||||
'alias' => '/' . $english_path,
|
||||
'langcode' => 'en',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm($path, $edit, t('Save'));
|
||||
|
||||
// Create a path alias in new custom language.
|
||||
$custom_language_path = $this->randomMachineName(8);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'source' => '/node/' . $node->id(),
|
||||
'alias' => '/' . $custom_language_path,
|
||||
'langcode' => $langcode,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm($path, $edit, t('Save'));
|
||||
|
||||
// Confirm English language path alias works.
|
||||
|
@ -96,11 +96,11 @@ class LocalePathTest extends WebTestBase {
|
|||
$custom_path = $this->randomMachineName(8);
|
||||
|
||||
// Check priority of language for alias by source path.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'source' => '/node/' . $node->id(),
|
||||
'alias' => '/' . $custom_path,
|
||||
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
||||
);
|
||||
];
|
||||
$this->container->get('path.alias_storage')->save($edit['source'], $edit['alias'], $edit['langcode']);
|
||||
$lookup_path = $this->container->get('path.alias_manager')->getAliasByPath('/node/' . $node->id(), 'en');
|
||||
$this->assertEqual('/' . $english_path, $lookup_path, 'English language alias has priority.');
|
||||
|
@ -110,32 +110,32 @@ class LocalePathTest extends WebTestBase {
|
|||
$this->container->get('path.alias_storage')->delete($edit);
|
||||
|
||||
// Create language nodes to check priority of aliases.
|
||||
$first_node = $this->drupalCreateNode(array('type' => 'page', 'promote' => 1, 'langcode' => 'en'));
|
||||
$second_node = $this->drupalCreateNode(array('type' => 'page', 'promote' => 1, 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
|
||||
$first_node = $this->drupalCreateNode(['type' => 'page', 'promote' => 1, 'langcode' => 'en']);
|
||||
$second_node = $this->drupalCreateNode(['type' => 'page', 'promote' => 1, 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED]);
|
||||
|
||||
// Assign a custom path alias to the first node with the English language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'source' => '/node/' . $first_node->id(),
|
||||
'alias' => '/' . $custom_path,
|
||||
'langcode' => $first_node->language()->getId(),
|
||||
);
|
||||
];
|
||||
$this->container->get('path.alias_storage')->save($edit['source'], $edit['alias'], $edit['langcode']);
|
||||
|
||||
// Assign a custom path alias to second node with
|
||||
// LanguageInterface::LANGCODE_NOT_SPECIFIED.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'source' => '/node/' . $second_node->id(),
|
||||
'alias' => '/' . $custom_path,
|
||||
'langcode' => $second_node->language()->getId(),
|
||||
);
|
||||
];
|
||||
$this->container->get('path.alias_storage')->save($edit['source'], $edit['alias'], $edit['langcode']);
|
||||
|
||||
// Test that both node titles link to our path alias.
|
||||
$this->drupalGet('admin/content');
|
||||
$custom_path_url = Url::fromUserInput('/' . $custom_path)->toString();
|
||||
$elements = $this->xpath('//a[@href=:href and normalize-space(text())=:title]', array(':href' => $custom_path_url, ':title' => $first_node->label()));
|
||||
$elements = $this->xpath('//a[@href=:href and normalize-space(text())=:title]', [':href' => $custom_path_url, ':title' => $first_node->label()]);
|
||||
$this->assertTrue(!empty($elements), 'First node links to the path alias.');
|
||||
$elements = $this->xpath('//a[@href=:href and normalize-space(text())=:title]', array(':href' => $custom_path_url, ':title' => $second_node->label()));
|
||||
$elements = $this->xpath('//a[@href=:href and normalize-space(text())=:title]', [':href' => $custom_path_url, ':title' => $second_node->label()]);
|
||||
$this->assertTrue(!empty($elements), 'Second node links to the path alias.');
|
||||
|
||||
// Confirm that the custom path leads to the first node.
|
|
@ -1,23 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\locale\Tests;
|
||||
namespace Drupal\Tests\locale\Functional;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests the locale string storage, string objects and data API.
|
||||
*
|
||||
* @group locale
|
||||
*/
|
||||
class LocaleStringTest extends WebTestBase {
|
||||
class LocaleStringTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('locale');
|
||||
public static $modules = ['locale'];
|
||||
|
||||
/**
|
||||
* The locale storage.
|
||||
|
@ -34,7 +34,7 @@ class LocaleStringTest extends WebTestBase {
|
|||
// Add a default locale storage for all these tests.
|
||||
$this->storage = $this->container->get('locale.storage');
|
||||
// Create two languages: Spanish and German.
|
||||
foreach (array('es', 'de') as $langcode) {
|
||||
foreach (['es', 'de'] as $langcode) {
|
||||
ConfigurableLanguage::createFromLangcode($langcode)->save();
|
||||
}
|
||||
}
|
||||
|
@ -46,51 +46,51 @@ class LocaleStringTest extends WebTestBase {
|
|||
// Create source string.
|
||||
$source = $this->buildSourceString();
|
||||
$source->save();
|
||||
$this->assertTrue($source->lid, format_string('Successfully created string %string', array('%string' => $source->source)));
|
||||
$this->assertTrue($source->lid, format_string('Successfully created string %string', ['%string' => $source->source]));
|
||||
|
||||
// Load strings by lid and source.
|
||||
$string1 = $this->storage->findString(array('lid' => $source->lid));
|
||||
$string1 = $this->storage->findString(['lid' => $source->lid]);
|
||||
$this->assertEqual($source, $string1, 'Successfully retrieved string by identifier.');
|
||||
$string2 = $this->storage->findString(array('source' => $source->source, 'context' => $source->context));
|
||||
$string2 = $this->storage->findString(['source' => $source->source, 'context' => $source->context]);
|
||||
$this->assertEqual($source, $string2, 'Successfully retrieved string by source and context.');
|
||||
$string3 = $this->storage->findString(array('source' => $source->source, 'context' => ''));
|
||||
$string3 = $this->storage->findString(['source' => $source->source, 'context' => '']);
|
||||
$this->assertFalse($string3, 'Cannot retrieve string with wrong context.');
|
||||
|
||||
// Check version handling and updating.
|
||||
$this->assertEqual($source->version, 'none', 'String originally created without version.');
|
||||
$string = $this->storage->findTranslation(array('lid' => $source->lid));
|
||||
$string = $this->storage->findTranslation(['lid' => $source->lid]);
|
||||
$this->assertEqual($string->version, \Drupal::VERSION, 'Checked and updated string version to Drupal version.');
|
||||
|
||||
// Create translation and find it by lid and source.
|
||||
$langcode = 'es';
|
||||
$translation = $this->createTranslation($source, $langcode);
|
||||
$this->assertEqual($translation->customized, LOCALE_NOT_CUSTOMIZED, 'Translation created as not customized by default.');
|
||||
$string1 = $this->storage->findTranslation(array('language' => $langcode, 'lid' => $source->lid));
|
||||
$string1 = $this->storage->findTranslation(['language' => $langcode, 'lid' => $source->lid]);
|
||||
$this->assertEqual($string1->translation, $translation->translation, 'Successfully loaded translation by string identifier.');
|
||||
$string2 = $this->storage->findTranslation(array('language' => $langcode, 'source' => $source->source, 'context' => $source->context));
|
||||
$string2 = $this->storage->findTranslation(['language' => $langcode, 'source' => $source->source, 'context' => $source->context]);
|
||||
$this->assertEqual($string2->translation, $translation->translation, 'Successfully loaded translation by source and context.');
|
||||
$translation
|
||||
->setCustomized()
|
||||
->save();
|
||||
$translation = $this->storage->findTranslation(array('language' => $langcode, 'lid' => $source->lid));
|
||||
$translation = $this->storage->findTranslation(['language' => $langcode, 'lid' => $source->lid]);
|
||||
$this->assertEqual($translation->customized, LOCALE_CUSTOMIZED, 'Translation successfully marked as customized.');
|
||||
|
||||
// Delete translation.
|
||||
$translation->delete();
|
||||
$deleted = $this->storage->findTranslation(array('language' => $langcode, 'lid' => $source->lid));
|
||||
$deleted = $this->storage->findTranslation(['language' => $langcode, 'lid' => $source->lid]);
|
||||
$this->assertFalse(isset($deleted->translation), 'Successfully deleted translation string.');
|
||||
|
||||
// Create some translations and then delete string and all of its
|
||||
// translations.
|
||||
$lid = $source->lid;
|
||||
$this->createAllTranslations($source);
|
||||
$search = $this->storage->getTranslations(array('lid' => $source->lid));
|
||||
$search = $this->storage->getTranslations(['lid' => $source->lid]);
|
||||
$this->assertEqual(count($search), 3, 'Created and retrieved all translations for our source string.');
|
||||
|
||||
$source->delete();
|
||||
$string = $this->storage->findString(array('lid' => $lid));
|
||||
$string = $this->storage->findString(['lid' => $lid]);
|
||||
$this->assertFalse($string, 'Successfully deleted source string.');
|
||||
$deleted = $search = $this->storage->getTranslations(array('lid' => $lid));
|
||||
$deleted = $search = $this->storage->getTranslations(['lid' => $lid]);
|
||||
$this->assertFalse($deleted, 'Successfully deleted all translation strings.');
|
||||
|
||||
// Tests that locations of different types and arbitrary lengths can be
|
||||
|
@ -102,7 +102,7 @@ class LocaleStringTest extends WebTestBase {
|
|||
$source_string->addLocation('path', $location = $this->randomString(300));
|
||||
$source_string->save();
|
||||
|
||||
$rows = db_query('SELECT * FROM {locales_location} WHERE sid = :sid', array(':sid' => $source_string->lid))->fetchAllAssoc('type');
|
||||
$rows = db_query('SELECT * FROM {locales_location} WHERE sid = :sid', [':sid' => $source_string->lid])->fetchAllAssoc('type');
|
||||
$this->assertEqual(count($rows), 4, '4 source locations have been persisted.');
|
||||
$this->assertEqual($rows['path']->name, substr($location, 0, 255), 'Too long location has been limited to 255 characters.');
|
||||
}
|
||||
|
@ -117,50 +117,50 @@ class LocaleStringTest extends WebTestBase {
|
|||
// Source 2 will have all translations, customized.
|
||||
// Source 3 will have no translations.
|
||||
$prefix = $this->randomMachineName(100);
|
||||
$source1 = $this->buildSourceString(array('source' => $prefix . $this->randomMachineName(100)))->save();
|
||||
$source2 = $this->buildSourceString(array('source' => $prefix . $this->randomMachineName(100)))->save();
|
||||
$source1 = $this->buildSourceString(['source' => $prefix . $this->randomMachineName(100)])->save();
|
||||
$source2 = $this->buildSourceString(['source' => $prefix . $this->randomMachineName(100)])->save();
|
||||
$source3 = $this->buildSourceString()->save();
|
||||
// Load all source strings.
|
||||
$strings = $this->storage->getStrings(array());
|
||||
$strings = $this->storage->getStrings([]);
|
||||
$this->assertEqual(count($strings), 3, 'Found 3 source strings in the database.');
|
||||
// Load all source strings matching a given string.
|
||||
$filter_options['filters'] = array('source' => $prefix);
|
||||
$strings = $this->storage->getStrings(array(), $filter_options);
|
||||
$filter_options['filters'] = ['source' => $prefix];
|
||||
$strings = $this->storage->getStrings([], $filter_options);
|
||||
$this->assertEqual(count($strings), 2, 'Found 2 strings using some string filter.');
|
||||
|
||||
// Not customized translations.
|
||||
$translate1 = $this->createAllTranslations($source1);
|
||||
// Customized translations.
|
||||
$this->createAllTranslations($source2, array('customized' => LOCALE_CUSTOMIZED));
|
||||
$this->createAllTranslations($source2, ['customized' => LOCALE_CUSTOMIZED]);
|
||||
// Try quick search function with different field combinations.
|
||||
$langcode = 'es';
|
||||
$found = $this->storage->findTranslation(array('language' => $langcode, 'source' => $source1->source, 'context' => $source1->context));
|
||||
$found = $this->storage->findTranslation(['language' => $langcode, 'source' => $source1->source, 'context' => $source1->context]);
|
||||
$this->assertTrue($found && isset($found->language) && isset($found->translation) && !$found->isNew(), 'Translation found searching by source and context.');
|
||||
$this->assertEqual($found->translation, $translate1[$langcode]->translation, 'Found the right translation.');
|
||||
// Now try a translation not found.
|
||||
$found = $this->storage->findTranslation(array('language' => $langcode, 'source' => $source3->source, 'context' => $source3->context));
|
||||
$found = $this->storage->findTranslation(['language' => $langcode, 'source' => $source3->source, 'context' => $source3->context]);
|
||||
$this->assertTrue($found && $found->lid == $source3->lid && !isset($found->translation) && $found->isNew(), 'Translation not found but source string found.');
|
||||
|
||||
// Load all translations. For next queries we'll be loading only translated
|
||||
// strings.
|
||||
$translations = $this->storage->getTranslations(array('translated' => TRUE));
|
||||
$translations = $this->storage->getTranslations(['translated' => TRUE]);
|
||||
$this->assertEqual(count($translations), 2 * $language_count, 'Created and retrieved all translations for source strings.');
|
||||
|
||||
// Load all customized translations.
|
||||
$translations = $this->storage->getTranslations(array('customized' => LOCALE_CUSTOMIZED, 'translated' => TRUE));
|
||||
$translations = $this->storage->getTranslations(['customized' => LOCALE_CUSTOMIZED, 'translated' => TRUE]);
|
||||
$this->assertEqual(count($translations), $language_count, 'Retrieved all customized translations for source strings.');
|
||||
|
||||
// Load all Spanish customized translations.
|
||||
$translations = $this->storage->getTranslations(array('language' => 'es', 'customized' => LOCALE_CUSTOMIZED, 'translated' => TRUE));
|
||||
$translations = $this->storage->getTranslations(['language' => 'es', 'customized' => LOCALE_CUSTOMIZED, 'translated' => TRUE]);
|
||||
$this->assertEqual(count($translations), 1, 'Found only Spanish and customized translations.');
|
||||
|
||||
// Load all source strings without translation (1).
|
||||
$translations = $this->storage->getStrings(array('translated' => FALSE));
|
||||
$translations = $this->storage->getStrings(['translated' => FALSE]);
|
||||
$this->assertEqual(count($translations), 1, 'Found 1 source string without translations.');
|
||||
|
||||
// Load Spanish translations using string filter.
|
||||
$filter_options['filters'] = array('source' => $prefix);
|
||||
$translations = $this->storage->getTranslations(array('language' => 'es'), $filter_options);
|
||||
$filter_options['filters'] = ['source' => $prefix];
|
||||
$translations = $this->storage->getTranslations(['language' => 'es'], $filter_options);
|
||||
$this->assertEqual(count($translations), 2, 'Found 2 translations using some string filter.');
|
||||
|
||||
}
|
||||
|
@ -171,18 +171,18 @@ class LocaleStringTest extends WebTestBase {
|
|||
* @return \Drupal\locale\StringInterface
|
||||
* A locale string.
|
||||
*/
|
||||
public function buildSourceString($values = array()) {
|
||||
return $this->storage->createString($values += array(
|
||||
public function buildSourceString($values = []) {
|
||||
return $this->storage->createString($values += [
|
||||
'source' => $this->randomMachineName(100),
|
||||
'context' => $this->randomMachineName(20),
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates translations for source string and all languages.
|
||||
*/
|
||||
public function createAllTranslations($source, $values = array()) {
|
||||
$list = array();
|
||||
public function createAllTranslations($source, $values = []) {
|
||||
$list = [];
|
||||
/* @var $language_manager \Drupal\Core\Language\LanguageManagerInterface */
|
||||
$language_manager = $this->container->get('language_manager');
|
||||
foreach ($language_manager->getLanguages() as $language) {
|
||||
|
@ -194,12 +194,12 @@ class LocaleStringTest extends WebTestBase {
|
|||
/**
|
||||
* Creates single translation for source string.
|
||||
*/
|
||||
public function createTranslation($source, $langcode, $values = array()) {
|
||||
return $this->storage->createTranslation($values + array(
|
||||
public function createTranslation($source, $langcode, $values = []) {
|
||||
return $this->storage->createTranslation($values + [
|
||||
'lid' => $source->lid,
|
||||
'language' => $langcode,
|
||||
'translation' => $this->randomMachineName(100),
|
||||
))->save();
|
||||
])->save();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,23 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\locale\Tests;
|
||||
namespace Drupal\Tests\locale\Functional;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Adds and configures languages to check field schema definition.
|
||||
*
|
||||
* @group locale
|
||||
*/
|
||||
class LocaleTranslatedSchemaDefinitionTest extends WebTestBase {
|
||||
class LocaleTranslatedSchemaDefinitionTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language', 'locale', 'node');
|
||||
public static $modules = ['language', 'locale', 'node'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -36,19 +36,19 @@ class LocaleTranslatedSchemaDefinitionTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that translated field descriptions do not affect the update system.
|
||||
*/
|
||||
function testTranslatedSchemaDefinition() {
|
||||
public function testTranslatedSchemaDefinition() {
|
||||
/** @var \Drupal\locale\StringDatabaseStorage $stringStorage */
|
||||
$stringStorage = \Drupal::service('locale.storage');
|
||||
|
||||
$source = $stringStorage->createString(array(
|
||||
$source = $stringStorage->createString([
|
||||
'source' => 'Revision ID',
|
||||
))->save();
|
||||
])->save();
|
||||
|
||||
$stringStorage->createTranslation(array(
|
||||
$stringStorage->createTranslation([
|
||||
'lid' => $source->lid,
|
||||
'language' => 'fr',
|
||||
'translation' => 'Translated Revision ID',
|
||||
))->save();
|
||||
])->save();
|
||||
|
||||
// Ensure that the field is translated when access through the API.
|
||||
$this->assertEqual('Translated Revision ID', \Drupal::entityManager()->getBaseFieldDefinitions('node')['vid']->getLabel());
|
||||
|
@ -60,12 +60,12 @@ class LocaleTranslatedSchemaDefinitionTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that translations do not affect the update system.
|
||||
*/
|
||||
function testTranslatedUpdate() {
|
||||
public function testTranslatedUpdate() {
|
||||
// Visit the update page to collect any strings that may be translatable.
|
||||
$user = $this->drupalCreateUser(array('administer software updates'));
|
||||
$user = $this->drupalCreateUser(['administer software updates']);
|
||||
$this->drupalLogin($user);
|
||||
$update_url = $GLOBALS['base_url'] . '/update.php';
|
||||
$this->drupalGet($update_url, array('external' => TRUE));
|
||||
$this->drupalGet($update_url, ['external' => TRUE]);
|
||||
|
||||
/** @var \Drupal\locale\StringDatabaseStorage $stringStorage */
|
||||
$stringStorage = \Drupal::service('locale.storage');
|
||||
|
@ -73,17 +73,17 @@ class LocaleTranslatedSchemaDefinitionTest extends WebTestBase {
|
|||
|
||||
// Translate all source strings found.
|
||||
foreach ($sources as $source) {
|
||||
$stringStorage->createTranslation(array(
|
||||
$stringStorage->createTranslation([
|
||||
'lid' => $source->lid,
|
||||
'language' => 'fr',
|
||||
'translation' => $this->randomMachineName(100),
|
||||
))->save();
|
||||
])->save();
|
||||
}
|
||||
|
||||
// Ensure that there are no updates just due to translations. Check for
|
||||
// markup and a link instead of specific text because text may be
|
||||
// translated.
|
||||
$this->drupalGet($update_url . '/selection', array('external' => TRUE));
|
||||
$this->drupalGet($update_url . '/selection', ['external' => TRUE]);
|
||||
$this->assertRaw('messages--status', 'No pending updates.');
|
||||
$this->assertNoLinkByHref('fr/update.php/run', 'No link to run updates.');
|
||||
}
|
|
@ -18,7 +18,7 @@ class LocaleConfigManagerTest extends KernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('system', 'language', 'locale', 'locale_test', 'block');
|
||||
public static $modules = ['system', 'language', 'locale', 'locale_test', 'block'];
|
||||
|
||||
/**
|
||||
* This test creates simple config on the fly breaking schema checking.
|
||||
|
@ -31,8 +31,8 @@ class LocaleConfigManagerTest extends KernelTestBase {
|
|||
* Tests hasTranslation().
|
||||
*/
|
||||
public function testHasTranslation() {
|
||||
$this->installSchema('locale', array('locales_location', 'locales_source', 'locales_target'));
|
||||
$this->installConfig(array('locale_test'));
|
||||
$this->installSchema('locale', ['locales_location', 'locales_source', 'locales_target']);
|
||||
$this->installConfig(['locale_test']);
|
||||
$locale_config_manager = \Drupal::service('locale.config_manager');
|
||||
|
||||
$language = ConfigurableLanguage::createFromLangcode('de');
|
||||
|
@ -48,8 +48,8 @@ class LocaleConfigManagerTest extends KernelTestBase {
|
|||
* Tests getStringTranslation().
|
||||
*/
|
||||
public function testGetStringTranslation() {
|
||||
$this->installSchema('locale', array('locales_location', 'locales_source', 'locales_target'));
|
||||
$this->installConfig(array('locale_test'));
|
||||
$this->installSchema('locale', ['locales_location', 'locales_source', 'locales_target']);
|
||||
$this->installConfig(['locale_test']);
|
||||
|
||||
$locale_config_manager = \Drupal::service('locale.config_manager');
|
||||
|
||||
|
@ -80,7 +80,7 @@ class LocaleConfigManagerTest extends KernelTestBase {
|
|||
$simple_config->set('foo', 'bar')->save();
|
||||
$this->assertNull(\Drupal::service('locale.config_manager')->getDefaultConfigLangcode($simple_config->getName()), 'Simple config created through the API is not treated as shipped configuration.');
|
||||
|
||||
$block = Block::create(array(
|
||||
$block = Block::create([
|
||||
'id' => 'test_default_config',
|
||||
'theme' => 'classy',
|
||||
'status' => TRUE,
|
||||
|
@ -94,7 +94,7 @@ class LocaleConfigManagerTest extends KernelTestBase {
|
|||
'primary' => TRUE,
|
||||
'secondary' => TRUE,
|
||||
],
|
||||
));
|
||||
]);
|
||||
$block->save();
|
||||
|
||||
// Install the theme after creating the block as installing the theme will
|
||||
|
|
|
@ -124,7 +124,7 @@ class LocaleConfigSubscriberForeignTest extends LocaleConfigSubscriberTest {
|
|||
$config_name = 'locale_test.translation';
|
||||
ConfigurableLanguage::createFromLangcode('en')->save();
|
||||
// Adding a language on the UI would normally call updateConfigTranslations.
|
||||
$this->localeConfigManager->updateConfigTranslations(array($config_name), array('en'));
|
||||
$this->localeConfigManager->updateConfigTranslations([$config_name], ['en']);
|
||||
$this->assertConfigOverride($config_name, 'test', 'English test', 'en');
|
||||
|
||||
$this->configFactory->getEditable('locale.settings')->set('translate_english', TRUE)->save();
|
||||
|
|
|
@ -182,7 +182,7 @@ class LocaleConfigSubscriberTest extends KernelTestBase {
|
|||
* The language code.
|
||||
*/
|
||||
protected function setUpNoTranslation($config_name, $key, $source, $langcode) {
|
||||
$this->localeConfigManager->updateConfigTranslations(array($config_name), array($langcode));
|
||||
$this->localeConfigManager->updateConfigTranslations([$config_name], [$langcode]);
|
||||
$this->assertNoConfigOverride($config_name, $key, $source, $langcode);
|
||||
$this->assertNoTranslation($config_name, $langcode);
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ class LocaleConfigSubscriberTest extends KernelTestBase {
|
|||
->save();
|
||||
$this->configFactory->reset($config_name);
|
||||
$this->localeConfigManager->reset();
|
||||
$this->localeConfigManager->updateConfigTranslations(array($config_name), array($langcode));
|
||||
$this->localeConfigManager->updateConfigTranslations([$config_name], [$langcode]);
|
||||
|
||||
if ($is_active) {
|
||||
$this->assertActiveConfig($config_name, $key, $translation, $langcode);
|
||||
|
@ -291,7 +291,7 @@ class LocaleConfigSubscriberTest extends KernelTestBase {
|
|||
->setString($translation)
|
||||
->save();
|
||||
$this->localeConfigManager->reset();
|
||||
$this->localeConfigManager->updateConfigTranslations(array($config_name), array($langcode));
|
||||
$this->localeConfigManager->updateConfigTranslations([$config_name], [$langcode]);
|
||||
$this->configFactory->reset($config_name);
|
||||
|
||||
if ($is_active) {
|
||||
|
@ -356,7 +356,7 @@ class LocaleConfigSubscriberTest extends KernelTestBase {
|
|||
->getStringTranslation($config_name, $langcode, $source_value, '')
|
||||
->delete();
|
||||
$this->localeConfigManager->reset();
|
||||
$this->localeConfigManager->updateConfigTranslations(array($config_name), array($langcode));
|
||||
$this->localeConfigManager->updateConfigTranslations([$config_name], [$langcode]);
|
||||
$this->configFactory->reset($config_name);
|
||||
|
||||
$this->assertNoConfigOverride($config_name, $key, $source_value, $langcode);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\locale\Kernel\Migrate;
|
||||
|
||||
use Drupal\config\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
|
@ -17,7 +17,7 @@ class MigrateLocaleConfigsTest extends MigrateDrupal6TestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('locale', 'language');
|
||||
public static $modules = ['locale', 'language'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -76,9 +76,9 @@ class LocaleLookupTest extends UnitTestCase {
|
|||
$this->user = $this->getMock('Drupal\Core\Session\AccountInterface');
|
||||
$this->user->expects($this->any())
|
||||
->method('getRoles')
|
||||
->will($this->returnValue(array('anonymous')));
|
||||
->will($this->returnValue(['anonymous']));
|
||||
|
||||
$this->configFactory = $this->getConfigFactoryStub(array('locale.settings' => array('cache_strings' => FALSE)));
|
||||
$this->configFactory = $this->getConfigFactoryStub(['locale.settings' => ['cache_strings' => FALSE]]);
|
||||
|
||||
$this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
|
||||
$this->requestStack = new RequestStack();
|
||||
|
@ -94,15 +94,15 @@ class LocaleLookupTest extends UnitTestCase {
|
|||
* @covers ::resolveCacheMiss
|
||||
*/
|
||||
public function testResolveCacheMissWithoutFallback() {
|
||||
$args = array(
|
||||
$args = [
|
||||
'language' => 'en',
|
||||
'source' => 'test',
|
||||
'context' => 'irrelevant',
|
||||
);
|
||||
];
|
||||
|
||||
$result = (object) array(
|
||||
$result = (object) [
|
||||
'translation' => 'test',
|
||||
);
|
||||
];
|
||||
|
||||
$this->cache->expects($this->once())
|
||||
->method('get')
|
||||
|
@ -114,8 +114,8 @@ class LocaleLookupTest extends UnitTestCase {
|
|||
->will($this->returnValue($result));
|
||||
|
||||
$locale_lookup = $this->getMockBuilder('Drupal\locale\LocaleLookup')
|
||||
->setConstructorArgs(array('en', 'irrelevant', $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack))
|
||||
->setMethods(array('persist'))
|
||||
->setConstructorArgs(['en', 'irrelevant', $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack])
|
||||
->setMethods(['persist'])
|
||||
->getMock();
|
||||
$locale_lookup->expects($this->never())
|
||||
->method('persist');
|
||||
|
@ -133,46 +133,46 @@ class LocaleLookupTest extends UnitTestCase {
|
|||
*/
|
||||
public function testResolveCacheMissWithFallback($langcode, $string, $context, $expected) {
|
||||
// These are fake words!
|
||||
$translations = array(
|
||||
'en' => array(
|
||||
$translations = [
|
||||
'en' => [
|
||||
'test' => 'test',
|
||||
'fake' => 'fake',
|
||||
'missing pl' => 'missing pl',
|
||||
'missing cs' => 'missing cs',
|
||||
'missing both' => 'missing both',
|
||||
),
|
||||
'pl' => array(
|
||||
],
|
||||
'pl' => [
|
||||
'test' => 'test po polsku',
|
||||
'fake' => 'ściema',
|
||||
'missing cs' => 'zaginiony czech',
|
||||
),
|
||||
'cs' => array(
|
||||
],
|
||||
'cs' => [
|
||||
'test' => 'test v české',
|
||||
'fake' => 'falešný',
|
||||
'missing pl' => 'chybějící pl',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$this->storage->expects($this->any())
|
||||
->method('findTranslation')
|
||||
->will($this->returnCallback(function ($argument) use ($translations) {
|
||||
if (isset($translations[$argument['language']][$argument['source']])) {
|
||||
return (object) array('translation' => $translations[$argument['language']][$argument['source']]);
|
||||
return (object) ['translation' => $translations[$argument['language']][$argument['source']]];
|
||||
}
|
||||
return TRUE;
|
||||
}));
|
||||
|
||||
$this->languageManager->expects($this->any())
|
||||
->method('getFallbackCandidates')
|
||||
->will($this->returnCallback(function (array $context = array()) {
|
||||
->will($this->returnCallback(function (array $context = []) {
|
||||
switch ($context['langcode']) {
|
||||
case 'pl':
|
||||
return array('cs', 'en');
|
||||
return ['cs', 'en'];
|
||||
|
||||
case 'cs':
|
||||
return array('en');
|
||||
return ['en'];
|
||||
|
||||
default:
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
}));
|
||||
|
||||
|
@ -188,20 +188,20 @@ class LocaleLookupTest extends UnitTestCase {
|
|||
* Provides test data for testResolveCacheMissWithFallback().
|
||||
*/
|
||||
public function resolveCacheMissWithFallbackProvider() {
|
||||
return array(
|
||||
array('cs', 'test', 'irrelevant', 'test v české'),
|
||||
array('cs', 'fake', 'irrelevant', 'falešný'),
|
||||
array('cs', 'missing pl', 'irrelevant', 'chybějící pl'),
|
||||
array('cs', 'missing cs', 'irrelevant', 'missing cs'),
|
||||
array('cs', 'missing both', 'irrelevant', 'missing both'),
|
||||
return [
|
||||
['cs', 'test', 'irrelevant', 'test v české'],
|
||||
['cs', 'fake', 'irrelevant', 'falešný'],
|
||||
['cs', 'missing pl', 'irrelevant', 'chybějící pl'],
|
||||
['cs', 'missing cs', 'irrelevant', 'missing cs'],
|
||||
['cs', 'missing both', 'irrelevant', 'missing both'],
|
||||
|
||||
// Testing PL with fallback to cs, en.
|
||||
array('pl', 'test', 'irrelevant', 'test po polsku'),
|
||||
array('pl', 'fake', 'irrelevant', 'ściema'),
|
||||
array('pl', 'missing pl', 'irrelevant', 'chybějící pl'),
|
||||
array('pl', 'missing cs', 'irrelevant', 'zaginiony czech'),
|
||||
array('pl', 'missing both', 'irrelevant', 'missing both'),
|
||||
);
|
||||
['pl', 'test', 'irrelevant', 'test po polsku'],
|
||||
['pl', 'fake', 'irrelevant', 'ściema'],
|
||||
['pl', 'missing pl', 'irrelevant', 'chybějící pl'],
|
||||
['pl', 'missing cs', 'irrelevant', 'zaginiony czech'],
|
||||
['pl', 'missing both', 'irrelevant', 'missing both'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -210,25 +210,25 @@ class LocaleLookupTest extends UnitTestCase {
|
|||
* @covers ::resolveCacheMiss
|
||||
*/
|
||||
public function testResolveCacheMissWithPersist() {
|
||||
$args = array(
|
||||
$args = [
|
||||
'language' => 'en',
|
||||
'source' => 'test',
|
||||
'context' => 'irrelevant',
|
||||
);
|
||||
];
|
||||
|
||||
$result = (object) array(
|
||||
$result = (object) [
|
||||
'translation' => 'test',
|
||||
);
|
||||
];
|
||||
|
||||
$this->storage->expects($this->once())
|
||||
->method('findTranslation')
|
||||
->with($this->equalTo($args))
|
||||
->will($this->returnValue($result));
|
||||
|
||||
$this->configFactory = $this->getConfigFactoryStub(array('locale.settings' => array('cache_strings' => TRUE)));
|
||||
$this->configFactory = $this->getConfigFactoryStub(['locale.settings' => ['cache_strings' => TRUE]]);
|
||||
$locale_lookup = $this->getMockBuilder('Drupal\locale\LocaleLookup')
|
||||
->setConstructorArgs(array('en', 'irrelevant', $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack))
|
||||
->setMethods(array('persist'))
|
||||
->setConstructorArgs(['en', 'irrelevant', $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack])
|
||||
->setMethods(['persist'])
|
||||
->getMock();
|
||||
$locale_lookup->expects($this->once())
|
||||
->method('persist');
|
||||
|
@ -257,8 +257,8 @@ class LocaleLookupTest extends UnitTestCase {
|
|||
$this->requestStack->push($request);
|
||||
|
||||
$locale_lookup = $this->getMockBuilder('Drupal\locale\LocaleLookup')
|
||||
->setConstructorArgs(array('en', 'irrelevant', $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack))
|
||||
->setMethods(array('persist'))
|
||||
->setConstructorArgs(['en', 'irrelevant', $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack])
|
||||
->setMethods(['persist'])
|
||||
->getMock();
|
||||
$locale_lookup->expects($this->never())
|
||||
->method('persist');
|
||||
|
|
|
@ -15,9 +15,9 @@ class LocaleLocalTasksTest extends LocalTaskIntegrationTestBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->directoryList = array(
|
||||
$this->directoryList = [
|
||||
'locale' => 'core/modules/locale',
|
||||
);
|
||||
];
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
|
@ -27,9 +27,9 @@ class LocaleLocalTasksTest extends LocalTaskIntegrationTestBase {
|
|||
* @dataProvider getLocalePageRoutes
|
||||
*/
|
||||
public function testLocalePageLocalTasks($route) {
|
||||
$tasks = array(
|
||||
0 => array('locale.translate_page', 'locale.translate_import', 'locale.translate_export', 'locale.settings'),
|
||||
);
|
||||
$tasks = [
|
||||
0 => ['locale.translate_page', 'locale.translate_import', 'locale.translate_export', 'locale.settings'],
|
||||
];
|
||||
$this->assertLocalTasks($route, $tasks);
|
||||
}
|
||||
|
||||
|
@ -37,12 +37,12 @@ class LocaleLocalTasksTest extends LocalTaskIntegrationTestBase {
|
|||
* Provides a list of routes to test.
|
||||
*/
|
||||
public function getLocalePageRoutes() {
|
||||
return array(
|
||||
array('locale.translate_page'),
|
||||
array('locale.translate_import'),
|
||||
array('locale.translate_export'),
|
||||
array('locale.settings'),
|
||||
);
|
||||
return [
|
||||
['locale.translate_page'],
|
||||
['locale.translate_import'],
|
||||
['locale.translate_export'],
|
||||
['locale.settings'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Tests\locale\Unit;
|
||||
|
||||
use Drupal\locale\SourceString;
|
||||
use Drupal\locale\StringStorageException;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
|
@ -13,22 +14,20 @@ class StringBaseTest extends UnitTestCase {
|
|||
|
||||
/**
|
||||
* @covers ::save
|
||||
* @expectedException \Drupal\locale\StringStorageException
|
||||
* @expectedExceptionMessage The string cannot be saved because its not bound to a storage: test
|
||||
*/
|
||||
public function testSaveWithoutStorage() {
|
||||
$string = new SourceString(['source' => 'test']);
|
||||
$this->setExpectedException(StringStorageException::class, 'The string cannot be saved because its not bound to a storage: test');
|
||||
$string->save();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers ::delete
|
||||
* @expectedException \Drupal\locale\StringStorageException
|
||||
* @expectedExceptionMessage The string cannot be deleted because its not bound to a storage: test
|
||||
*/
|
||||
public function testDeleteWithoutStorage() {
|
||||
$string = new SourceString(['lid' => 1, 'source' => 'test']);
|
||||
$this->setExpectedException(StringStorageException::class, 'The string cannot be deleted because its not bound to a storage: test');
|
||||
$string->delete();
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue