diff --git a/core/lib/Drupal/Component/Gettext/PoStreamReader.php b/core/lib/Drupal/Component/Gettext/PoStreamReader.php index d2840a6..74a9bae 100644 --- a/core/lib/Drupal/Component/Gettext/PoStreamReader.php +++ b/core/lib/Drupal/Component/Gettext/PoStreamReader.php @@ -165,7 +165,7 @@ class PoStreamReader implements PoStreamInterface, PoReaderInterface { */ public function open() { if (!empty($this->_uri)) { - $this->_fd = fopen($this->_uri, 'rb'); + $this->_fd = fopen(drupal_realpath($this->_uri), 'rb'); $this->_size = ftell($this->_fd); $this->readHeader(); } diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleExportTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleExportTest.php index bc7a69b..9c63839 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleExportTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleExportTest.php @@ -39,6 +39,14 @@ class LocaleExportTest extends WebTestBase { $this->admin_user = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages')); $this->drupalLogin($this->admin_user); + + // Set the translation file directory to something writable. + $destination = conf_path() . '/files/translations'; + file_prepare_directory($destination, FILE_CREATE_DIRECTORY); + + // Copy test po files to the same directory. + file_unmanaged_copy(drupal_get_path('module', 'locale') . '/tests/test.de.po', $destination, FILE_EXISTS_REPLACE); + file_unmanaged_copy(drupal_get_path('module', 'locale') . '/tests/test.xx.po', $destination, FILE_EXISTS_REPLACE); } /** diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleFileImportStatus.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleFileImportStatus.php index a19351d..53cadc0 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleFileImportStatus.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleFileImportStatus.php @@ -35,8 +35,13 @@ class LocaleFileImportStatus extends WebTestBase { $admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer languages', 'access administration pages')); $this->drupalLogin($admin_user); - // Set the translation file directory. - variable_set('locale_translate_file_directory', drupal_get_path('module', 'locale') . '/tests'); + // Set the translation file directory to something writable. + $destination = conf_path() . '/files/translations'; + file_prepare_directory($destination, FILE_CREATE_DIRECTORY); + + // Copy test po files to the same directory. + file_unmanaged_copy(drupal_get_path('module', 'locale') . '/tests/test.de.po', $destination, FILE_EXISTS_REPLACE); + file_unmanaged_copy(drupal_get_path('module', 'locale') . '/tests/test.xx.po', $destination, FILE_EXISTS_REPLACE); } /** @@ -79,8 +84,7 @@ class LocaleFileImportStatus extends WebTestBase { * A file object of type stdClass. */ function mockImportedPoFile($langcode, $timestamp_difference = 0) { - $dir = variable_get('locale_translate_file_directory', drupal_get_path('module', 'locale') . '/tests'); - $testfile_uri = $dir . '/test.' . $langcode . '.po'; + $testfile_uri = 'translations://test.' . $langcode . '.po'; $file = locale_translate_file_create($testfile_uri); $file->original_timestamp = $file->timestamp; @@ -189,13 +193,10 @@ class LocaleFileImportStatus extends WebTestBase { * Delete translation files after deleting a language. */ function testDeleteLanguage() { - $dir = conf_path() . '/files/translations'; - file_prepare_directory($dir, FILE_CREATE_DIRECTORY); - variable_set('locale_translate_file_directory', $dir); $langcode = 'de'; $this->addLanguage($langcode); - $file_uri = $dir . '/po_' . $this->randomName() . '.' . $langcode . '.po'; - file_put_contents($file_uri, $this->randomName()); + $file_uri = 'translations://po_' . $this->randomName() . '.' . $langcode . '.po'; + file_put_contents(drupal_realpath($file_uri), $this->randomName()); $this->assertTrue(is_file($file_uri), 'Translation file is created.'); language_delete($langcode); $this->assertTrue($file_uri); diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleImportFunctionalTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleImportFunctionalTest.php index bfab647..d87af40 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleImportFunctionalTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleImportFunctionalTest.php @@ -36,8 +36,13 @@ class LocaleImportFunctionalTest extends WebTestBase { function setUp() { parent::setUp(); - // Set the translation file directory. - variable_set('locale_translate_file_directory', drupal_get_path('module', 'locale') . '/tests'); + // Set the translation file directory to something writable. + $destination = conf_path() . '/files/translations'; + file_prepare_directory($destination, FILE_CREATE_DIRECTORY); + + // Copy test po files to the same directory. + file_unmanaged_copy(drupal_get_path('module', 'locale') . '/tests/test.de.po', $destination, FILE_EXISTS_REPLACE); + file_unmanaged_copy(drupal_get_path('module', 'locale') . '/tests/test.xx.po', $destination, FILE_EXISTS_REPLACE); $this->admin_user = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages')); $this->drupalLogin($this->admin_user); diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc index fa400b5..19fcf68 100644 --- a/core/modules/locale/locale.bulk.inc +++ b/core/modules/locale/locale.bulk.inc @@ -106,7 +106,6 @@ function locale_translate_import_form($form, &$form_state) { function locale_translate_import_form_submit($form, &$form_state) { // Ensure we have the file uploaded. if ($file = file_save_upload('file', $form['file']['#upload_validators'])) { - // Add language, if not yet supported. $language = language_load($form_state['values']['langcode']); if (empty($language)) { @@ -357,7 +356,14 @@ function locale_translate_batch_import_files($options, $force = FALSE) { */ function locale_translate_get_interface_translation_files($langcode = NULL) { $directory = variable_get('locale_translate_file_directory', conf_path() . '/files/translations'); - return file_scan_directory($directory, '!' . (!empty($langcode) ? '\.' . preg_quote($langcode, '!') : '') . '\.po$!', array('recurse' => FALSE)); + $return = file_scan_directory($directory, '!' . (!empty($langcode) ? '\.' . preg_quote($langcode, '!') : '') . '\.po$!', array('recurse' => FALSE)); + + foreach ($return as $filepath => $file) { + $file->uri = 'translations://' . $file->filename; + $return[$file->uri] = $file; + unset($return[$filepath]); + } + return $return; } /** @@ -440,8 +446,10 @@ function locale_translate_batch_import($filepath, $options, &$context) { ); // The filename is either {langcode}.po or {prefix}.{langcode}.po, so // we can extract the language code to use for the import from the end. - if ($options['langcode'] || preg_match('!(/|\.)([^\./]+)\.po$!', $filepath, $matches)) { - $file = entity_create('file', array('filename' => drupal_basename($filepath), 'uri' => $filepath)); + if (isset($options['langcode']) && $options['langcode'] || + preg_match('!(/|\.)([^\./]+)\.po$!', $filepath, $matches)) { + $basename = drupal_basename($filepath); + $file = entity_create('file', array('filename' => $basename, 'uri' => 'translations://'. $basename)); // We need only the last match, but only if the langcode is not explicitly // specified in the $options array. if (!$options['langcode'] && is_array($matches)) { @@ -450,7 +458,7 @@ function locale_translate_batch_import($filepath, $options, &$context) { try { if (empty($context['sandbox'])) { $context['sandbox']['parse_state'] = array( - 'filesize' => filesize($file->uri), + 'filesize' => filesize(drupal_realpath($file->uri)), 'chunk_size' => 200, 'seek' => 0, ); @@ -551,7 +559,7 @@ function locale_translate_file_create($filepath) { $file = new stdClass(); $file->filename = drupal_basename($filepath); $file->uri = $filepath; - $file->timestamp = filemtime($file->uri); + $file->timestamp = filemtime(drupal_realpath($file->uri)); return $file; } diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 228bf32..39febca 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -13,6 +13,7 @@ use Drupal\locale\LocaleLookup; use Drupal\locale\LocaleConfigSubscriber; +use Drupal\locale\TranslationsStream; /** * Regular expression pattern used to localize JavaScript strings. @@ -171,6 +172,21 @@ function locale_theme() { } /** + * Implements hook_stream_wrappers(). + */ +function locale_stream_wrappers() { + $wrappers = array( + 'translations' => array( + 'name' => t('Translation files'), + 'class' => 'Drupal\locale\TranslationsStream', + 'description' => t('Translation files'), + 'type' => STREAM_WRAPPERS_LOCAL_NORMAL, + ), + ); + return $wrappers; +} + +/** * Implements hook_language_insert(). */ function locale_language_insert($language) {