Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -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;
|
||||
|
|
Reference in a new issue