D8 installer is broken if selecting a non-English language on installation.

Exception shown is:

[Thu Aug 16 02:26:48 2012] [error] [client 127.0.0.1] PHP Fatal error:  Class 'Drupal\\locale\\Gettext' not found in /var/www/d8/core/includes/install.inc on line 704
[Thu Aug 16 02:26:48 2012] [error] [client 127.0.0.1] PHP Stack trace:
[Thu Aug 16 02:26:48 2012] [error] [client 127.0.0.1] PHP   1. {main}() /var/www/d8/core/install.php:0
[Thu Aug 16 02:26:48 2012] [error] [client 127.0.0.1] PHP   2. install_drupal() /var/www/d8/core/install.php:36
[Thu Aug 16 02:26:48 2012] [error] [client 127.0.0.1] PHP   3. install_begin_request() /var/www/d8/core/includes/install.core.inc:83
[Thu Aug 16 02:26:48 2012] [error] [client 127.0.0.1] PHP   4. install_verify_database_settings() /var/www/d8/core/includes/install.core.inc:315
[Thu Aug 16 02:26:48 2012] [error] [client 127.0.0.1] PHP   5. install_database_errors() /var/www/d8/core/includes/install.core.inc:880
[Thu Aug 16 02:26:48 2012] [error] [client 127.0.0.1] PHP   6. db_run_tasks() /var/www/d8/core/includes/install.core.inc:1019
[Thu Aug 16 02:26:48 2012] [error] [client 127.0.0.1] PHP   7. Drupal\\Core\\Database\\Install\\Tasks->runTasks() /var/www/d8/core/includes/install.inc:887
[Thu Aug 16 02:26:48 2012] [error] [client 127.0.0.1] PHP   8. call_user_func_array() /var/www/d8/core/lib/Drupal/Core/Database/Install/Tasks.php:136
[Thu Aug 16 02:26:48 2012] [error] [client 127.0.0.1] PHP   9. Drupal\\Core\\Database\\Install\\Tasks->runTestQuery() /var/www/d8/core/lib/Drupal/Core/Database/Install/Tasks.php:0
[Thu Aug 16 02:26:48 2012] [error] [client 127.0.0.1] PHP  10. Drupal\\Core\\Database\\Driver\\mysql\\Install\\Tasks->name() /var/www/d8/core/lib/Drupal/Core/Database/Install/Tasks.php:185
[Thu Aug 16 02:26:48 2012] [error] [client 127.0.0.1] PHP  11. st() /var/www/d8/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php:27

Steps to reproduce:

1. Create folder sites/default/files/translations
2. Download there a translation from http://localize.drupal.org/translate/downloads, e.g. Spanish
3. Rename the file to install.es.po
4. Open core/install.php and select Spanish.

Files: 
CommentFileSizeAuthor
#17 1733746-17.patch1.88 KBGábor Hojtsy
PASSED: [[SimpleTest]]: [MySQL] 40,086 pass(es). View
#15 cleaned_up_previous_patch-1733746-14.patch1.89 KBsxnc
PASSED: [[SimpleTest]]: [MySQL] 40,077 pass(es). View
#12 added_comment-1733746-12.patch3.18 KBsxnc
PASSED: [[SimpleTest]]: [MySQL] 40,070 pass(es). View
#8 1733746-installing-other-language-4.patch1.73 KBjsbalsera
PASSED: [[SimpleTest]]: [MySQL] 40,075 pass(es). View
#8 interdiff.txt1.4 KBjsbalsera
#4 1733746-installing-other-language-1.patch1.75 KBpenyaskito
PASSED: [[SimpleTest]]: [MySQL] 40,048 pass(es). View
#1 1733746-installing-other-language-0.patch721 bytespenyaskito
PASSED: [[SimpleTest]]: [MySQL] 40,064 pass(es). View

Comments

penyaskito’s picture

FileSize
721 bytes
PASSED: [[SimpleTest]]: [MySQL] 40,064 pass(es). View

First problem is that Drupal\\locale is not registered in the classloader in st() on installation.

I tested using drupal_classloader_register, but no luck. Including the class manually seems to fix the first problem, but not sure if it's an acceptable workaround.

penyaskito’s picture

Status: Active » Needs work
penyaskito’s picture

With the patch above I've been able of succesfully installing D8, but Drupal\\locale warnings are everywhere when trying to import the language.

Front page (/) is in English, but if navigating away from the frontpage (e.g. /node) the UI is in Spanish. Pretty confusing.

penyaskito’s picture

Status: Needs work » Needs review
FileSize
1.75 KB
PASSED: [[SimpleTest]]: [MySQL] 40,048 pass(es). View

The patch removes the warnings, and the installation process now is translated to the selected language on step 1.

However, when visiting the frontpage (/), it's shown in English instead of the selected language.

Seems like a totally unrelated issue.

penyaskito’s picture

Installed a new site in English, changed default language to Spanish, and / is in Spanish, so the bug seems to be on the localized installation, against my initial thoughts.

Gábor Hojtsy’s picture

Status: Needs review » Needs work
+++ b/core/includes/install.incundefined
@@ -700,6 +700,7 @@ function st($string, array $args = array(), array $options = array()) {
       if (!empty($files)) {
+        include_once drupal_get_path('module', 'locale') . '/lib/Drupal/locale/Gettext.php';
         $strings = Gettext::filesToArray($install_state['parameters']['langcode'], $files);

This should be referenced in a "use ..." clause above, instead of including the file, no? This is what you referenced above as "First problem is that Drupal\\locale is not registered in the classloader in st() on installation."?

+++ b/core/lib/Drupal/Component/Gettext/PoMemoryWriter.phpundefined
@@ -34,11 +34,12 @@ class PoMemoryWriter implements PoWriterInterface {
+    $context = $item->getContext();
+    $this->_items[$context != NULL ? $item->getContext() : ''][$item->getSource()] = $item->getTranslation();

Just use $context instead of calling getContext() again AFAIS.

penyaskito’s picture

This should be referenced in a "use ..." clause above, instead of including the file, no? This is what you referenced above as "First problem is that Drupal\\locale is not registered in the classloader in st() on installation."?

The use clause is there. The problem here seems to be that the ClassLoader doesn't know yet that it should be looking for that class at core/modules/locale/lib/Drupal/locale. If I debug $classloader , Drupal\\locale is not a registered namespace. Tried drupal_classloader_register('locale', drupal_get_path('module', 'locale')) instead of the include_once, but didn't work either.

Just use $context instead of calling getContext() again AFAIS.

I'll attach a new patch later today.

jsbalsera’s picture

Assigned: penyaskito » Unassigned
Status: Needs work » Needs review
FileSize
1.4 KB
1.73 KB
PASSED: [[SimpleTest]]: [MySQL] 40,075 pass(es). View

Hi!

I've made the requested changes and it works for me, although when you access to the / page its content is presented in english. If I access to /node its presented in the installed language.

maxtorete’s picture

Status: Needs review » Needs work

I have tried jsbalsera's patch and it works fine.

maxtorete’s picture

Status: Needs work » Needs review

Sorry about the status change, I fix it :-(

Gábor Hojtsy’s picture

Status: Needs review » Needs work

Looks better! One more note:

+++ b/core/includes/install.incundefined
@@ -700,6 +700,7 @@ function st($string, array $args = array(), array $options = array()) {
       $files = install_find_translation_files($install_state['parameters']['langcode']);
       if (!empty($files)) {
+        drupal_classloader_register('locale', drupal_get_path('module', 'locale'));
         $strings = Gettext::filesToArray($install_state['parameters']['langcode'], $files);
       }
     }

This is pretty unusual to see, so I'd add some comments to the effect of:

// Register locale classes with the classloader. Locale module is not yet enabled at this stage, so this is not happening automatically.

(Wrap the comment to 80 chars of course :).

sxnc’s picture

Status: Needs work » Needs review
FileSize
3.18 KB
PASSED: [[SimpleTest]]: [MySQL] 40,070 pass(es). View

Testest the patch from comment #8 with 3 languages:

-German
-Japanese
-Swiss German

worked like a charm, no errors. Also added the comment from #11 to the patch from #8

Gábor Hojtsy’s picture

Status: Needs review » Needs work

Looks like this got unrelated code at the end from another patch from #1737186: Fix code style issues in new OOP Gettext parser. Let's remove that from here.

lazysoundsystem’s picture

Assigned: Unassigned » lazysoundsystem
sxnc’s picture

Status: Needs work » Needs review
FileSize
1.89 KB
PASSED: [[SimpleTest]]: [MySQL] 40,077 pass(es). View

Sorry about that!

Here's a clean version.

lazysoundsystem’s picture

Assigned: lazysoundsystem » Unassigned
Status: Needs review » Reviewed & tested by the community

Just tested this and the last patch works cleanly for me.

Gábor Hojtsy’s picture

FileSize
1.88 KB
PASSED: [[SimpleTest]]: [MySQL] 40,086 pass(es). View

The comment should wrap as close to 80 chars as possible (it fits on 2 lines instead of 3 lines that way). This is minor, but is our coding standard. Should not change RTBC status, however, best wait for it to come back green :)

sxnc’s picture

I see! Will remember that for the next time, thanks! :)

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Checked with Gábor, and unfortunately we can't add test coverage for this. Sad panda. :(

However, this definitely needs to be fixed, and then fix looks good to me!

Committed and pushed to 8.x. Thanks!

Gábor Hojtsy’s picture

Issue tags: -sprint

Off of the sprint.

penyaskito’s picture

Gábor Hojtsy’s picture

Issue tags: +sprint

Putting back on sprint just for easier tracking of our work. Will remove later next week.

Gábor Hojtsy’s picture

Issue tags: -sprint

Removing as promised. We do not need a change notice or changelog entry for this.

Automatically closed -- issue fixed for 2 weeks with no activity.