I've added the possibility to translate the html error page, replacing a token with the current language prefix.
It only work for websites using the language prefix.
Feel free to improve this with a query to get the domains, and handle the language by domain.

How it works ?

$conf['fast_404_HTML_error_page'] = './404/index_##LANG##.html';

The ##LANG## token will be replaced by the current language prefix.

You can have index_.html, index_en.html, index_it.html, etc.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cutesquirrel’s picture

adammalone’s picture

Status: Patch (to be ported) » Needs work

The only way I could see this working with early stage bootstrap is if the path was parsed and determined to contain a language or if languages were found from the database (We already query the locale table). My concern about this is how we would know which language was desired, I'm not confident about replacing tokens.

This patch also introduces whitespace and shouldn't introduce another global.

alexander.sibert’s picture

Great module and i'm also interest on this feature. I use on a current project i18n with lang codes.

gapple’s picture

Status: Needs work » Needs review
FileSize
8.9 KB

Here's a patch that checks if the requested path is prefixed with a valid language.

Status: Needs review » Needs work

The last submitted patch, 4: fast_404-2370323-4.patch, failed testing.

gapple’s picture

Status: Needs work » Needs review
FileSize
8.97 KB

Here's an updated patch for latest dev

gapple’s picture

I ran into a weird issue on Acquia hosting where the Database API functions were available when fast_404_path_check() was called in settings.php.

This caused problems with my patches, because the variables are not bootstrapped yet, and drupal_multilingual() then always returns false.

I fixed this by using the check for the locale module's status, as was originally used in fast_404_validate_path_drupal(), instead of drupal_multilingual().

eddie_c’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev

It would be great to have this feature in the 8.x-1.x branch. It may be simpler to achieve in the D8 version by parsing the language prefix from the path in Fast404->response() and then using that to load a language appropriate static HTML file in a way similar to the one suggested here by @cutesquirrel

Perhaps this should be worked on for Drupal 8 first and then backported to D7 in order to make sure this feature isn't abandoned going forward?

Optimistically bumping the version of this issue up to 8.x!

gg4’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
YahyaAlHamad’s picture

Added the ability to translate in version 2, I'm not sure if this is the best way. Read the example.settings.fast404.php for more info.

Status: Needs review » Needs work

The last submitted patch, 10: 2370323-10.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

YahyaAlHamad’s picture

Fixed the test, also, added a new test, to test 'fast404_HTML_error_page' functionality.

YahyaAlHamad’s picture

Status: Needs work » Needs review

I used the LanguageManager service to determine the current language, I fear that I have missed the whole point of the module.

Kristen Pol’s picture

Status: Needs review » Needs work

Thanks for the issue, patches, and reviews!

I took a quick look and have some minor feedback, mostly nitpicks. Moving back to needs work for at least fixing the typos.

  1. +++ b/src/EventSubscriber/Fast404EventSubscriber.php
    @@ -25,14 +26,24 @@ class Fast404EventSubscriber implements EventSubscriberInterface {
    +   * The language mananger
    

    * Typo: "mananger" => "manager".
    * Nitpick: Add period.

  2. +++ b/src/Fast404.php
    @@ -40,14 +40,24 @@ class Fast404 {
    +   * The langcode, this will help us to load the translated 404 page if it exists.
    

    Nitpick: This goes beyond 80 characters. Perhaps reword slightly, e.g.

    The langcode to use for the translated 404 page if it exists.

  3. +++ b/src/Fast404.php
    @@ -198,10 +208,20 @@ class Fast404 {
    +        // If it is an array, get path depending on the langcode, if langcode is NULL, default to the first value.
    

    * Nitpick: This goes beyond 80 characters.
    * Nitpick: These should be 2 separate sentences or be separated by a ";" instead of a comma.

  4. +++ b/src/Fast404.php
    @@ -198,10 +208,20 @@ class Fast404 {
    +      } else {
    +        $custom_404_path = $custom_404;
    

    Nitpick: Move else to own line, e.g.

    }
    else {
    
  5. +++ b/src/Fast404.php
    @@ -198,10 +208,20 @@ class Fast404 {
    +      if(file_exists($custom_404_path)) {
    

    Nitpick: Add space after if.

  6. +++ b/tests/html/en.html
    @@ -0,0 +1,14 @@
    +	<head>
    +		<meta charset="UTF-8">
    +		<meta http-equiv="X-UA-Compatible" content="IE=edge">
    +		<meta name="viewport" content="width=device-width, initial-scale=1.0">
    +		<title>Not Found</title>
    +	</head>
    +	<body>
    +		<h1>
    +			Custom Page not found
    +		</h1>
    +	</body>
    
    +++ b/tests/html/fr.html
    @@ -0,0 +1,14 @@
    +	<head>
    +		<meta charset="UTF-8">
    +		<meta http-equiv="X-UA-Compatible" content="IE=edge">
    +		<meta name="viewport" content="width=device-width, initial-scale=1.0">
    +		<title>Pas trouvé</title>
    +	</head>
    +	<body>
    +		<h1>
    +			Page personnalisée introuvable
    +		</h1>
    +	</body>
    

    * Nitpick: Should these use spaces instead of tabs?
    * Nitpick: Change "Custom Page not found" to "Custom Page Not Found".

  7. +++ b/tests/src/Functional/Fast404HtmlPageTest.php
    @@ -0,0 +1,80 @@
    +    // Let fast404 subscribe to NotFoundHttpException
    

    Nitpick: Add period.

  8. +++ b/tests/src/Functional/Fast404HtmlPageTest.php
    @@ -0,0 +1,80 @@
    +    // Try to access a non-existant page.
    

    Typo: "existant" => "existent".

  9. +++ b/tests/src/Functional/Fast404HtmlPageTest.php
    @@ -0,0 +1,80 @@
    +    $this->assertSession()->pageTextContains('Custom Page not found');
    

    Nitpick: Change "Custom Page not found" to "Custom Page Not Found".

  10. +++ b/tests/src/Functional/Fast404HtmlPageTest.php
    @@ -0,0 +1,80 @@
    +    // Try to access a non-existant page.
    

    Typo: "existant" => "existent".

  11. +++ b/tests/src/Functional/Fast404HtmlPageTest.php
    @@ -0,0 +1,80 @@
    +    $this->assertSession()->pageTextContains('Custom Page not found');
    

    Nitpick: Change "Custom Page not found" to "Custom Page Not Found".

  12. +++ b/tests/src/Functional/Fast404HtmlPageTest.php
    @@ -0,0 +1,80 @@
    +    // Try to access a non-existant page.
    

    Typo: "existant" => "existent".

Kristen Pol’s picture

Looks like the approach changed, so the issue summary will need updating.

Kristen Pol’s picture

Issue tags: +Novice

Adding novice tag as changes to patch are simple.

srilakshmier’s picture

Status: Needs work » Needs review
FileSize
7.85 KB
4.58 KB

Uploading the patch based on the feedback in #14.
Please review.

Thank you

Kristen Pol’s picture

Status: Needs review » Needs work

Thanks for the update. I reviewed the interdiff. Not sure why the tests were removed so moving back to needs work for adding those back and I noticed a couple minor things as well.

  1. +++ b/src/Fast404.php
    @@ -213,13 +213,14 @@
    -        // If it is an array, get path depending on the langcode, if langcode is NULL, default to the first value.
    +        // For array, get path depending on the langcode; if langcode is NULL, default to the first value.
    

    Update to wrap comment at <80 characters.

  2. +++ b/src/Fast404.php
    @@ -213,13 +213,14 @@
    +      } ¶
    +      else {
    

    Extra space after the }.

  3. +++ b/src/Fast404.php
    @@ -213,13 +213,14 @@
    --- b/tests/html/en.html
    
    --- b/tests/html/en.html
    +++ /dev/null
    

    Shouldn't be removed.

  4. +++ /dev/null
    @@ -1,14 +0,0 @@
    --- b/tests/html/fr.html
    
    --- b/tests/html/fr.html
    +++ /dev/null
    

    Shouldn't be removed.

  5. +++ /dev/null
    @@ -1,14 +0,0 @@
    --- b/tests/src/Functional/Fast404HtmlPageTest.php
    
    --- b/tests/src/Functional/Fast404HtmlPageTest.php
    +++ /dev/null
    

    Shouldn't be removed.

  6. Most of the feedback from #14 was not addressed.

elber’s picture

Assigned: Unassigned » elber
elber’s picture

Assigned: elber » Unassigned
Status: Needs work » Needs review
FileSize
7.85 KB
1.11 KB

My patch has the changes mentioned in the comment #18, and I didn't exclude the HTML files.

Kristen Pol’s picture

Status: Needs review » Needs work

Thank you for your attempt at helping @elber but this is still using the bad patch from #17 which is missing tests. This is noted in #18 but I guess I didn't make that obvious enough so...

Whoever works on this next:

1. PLEASE USE PATCH FROM #12.

2. Then look at the feedback from #14 and #18.

3. Do an interdiff between #12 and your updated patch. (The patches in #17 and #20 broke things like removing tests.)

Thanks.

elber’s picture

Assigned: Unassigned » elber
elber’s picture

I'm still working on this!

elber’s picture

Assigned: elber » Unassigned
Status: Needs work » Needs review
FileSize
7.87 KB
4.94 KB
Kristen Pol’s picture

Status: Needs review » Needs work

Looked at the interdiff and see the test files being removed. Also, make sure there are no extra spaces at the end of lines.

Back to needs work.

  1. +++ b/src/Fast404.php
    @@ -213,13 +213,15 @@
    --- b/tests/html/en.html
    
    --- b/tests/html/en.html
    +++ /dev/null
    

    Why are you removing test files?

  2. +++ /dev/null
    @@ -1,14 +0,0 @@
    --- b/tests/html/fr.html
    
    --- b/tests/html/fr.html
    +++ /dev/null
    

    Why are you removing test files?

  3. +++ /dev/null
    @@ -1,14 +0,0 @@
    --- b/tests/src/Functional/Fast404HtmlPageTest.php
    
    --- b/tests/src/Functional/Fast404HtmlPageTest.php
    +++ /dev/null
    

    Why are you removing test files?

elber’s picture

Assigned: Unassigned » elber
joshua1234511’s picture

Status: Needs work » Needs review
FileSize
11.24 KB
3.38 KB

Updated the path from #12
Worked on feedback from #14
#13 no specific feedback to be worked on just as #14 was not addressed.

Additional Addresed
FILE: /fast_404/tests/src/Functional/Fast404HtmlPageTest.php
-------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
-------------------------------------------------------------------------------------------------------------------------
79 | ERROR | [x] Expected 1 blank line after function; 0 found
80 | ERROR | [x] The closing brace for the class must have an empty line before it

Kristen Pol’s picture

Thanks @joshua1234511!

We should add some explicit testing steps so people can try this.

This still needs code review too.

Kristen Pol’s picture

Assigned: elber » Unassigned
Status: Needs review » Needs work

Thanks for updating the patch and cleaning up the code formatting issues. I reviewed again and there are a couple things:

  1. +++ b/src/Fast404.php
    @@ -198,10 +208,22 @@ class Fast404 {
    +        // If it is an array, get path depending on the langcode;
    +        // if langcode is NULL, default to the first value.
    

    Comments shouldn't read like code, so this should be reworded to something like:

    For arrays, use the path associated with the langcode or the first path if the langcode is not set.

  2. +++ b/tests/html/en.html
    @@ -0,0 +1,14 @@
    +	<head>
    +		<meta charset="UTF-8">
    +		<meta http-equiv="X-UA-Compatible" content="IE=edge">
    +		<meta name="viewport" content="width=device-width, initial-scale=1.0">
    +		<title>Not Found</title>
    +	</head>
    +	<body>
    +		<h1>
    +			Custom Page Not Found
    +		</h1>
    +	</body>
    

    1. The indentation here does not follow indentation seen in other html files in core, e.g. core/modules/color/preview.html.

    2. Nitpick: Should Custom Page Not Found be wrapped in

    <h1></h1>
    

    on one line? e.g.

    <h1>Custom Page Not Found</h1>
    
  3. +++ b/tests/html/fr.html
    @@ -0,0 +1,14 @@
    +	<head>
    +		<meta charset="UTF-8">
    +		<meta http-equiv="X-UA-Compatible" content="IE=edge">
    +		<meta name="viewport" content="width=device-width, initial-scale=1.0">
    +		<title>Pas trouvé</title>
    +	</head>
    +	<body>
    +		<h1>
    +			Page personnalisée introuvable
    +		</h1>
    +	</body>
    

    Same as above.

lucasbaralm’s picture

Assigned: Unassigned » lucasbaralm
lucasbaralm’s picture

Status: Needs work » Needs review
FileSize
11.21 KB
2.02 KB

Fixing standards and comments mentioned in #29.

lucasbaralm’s picture

Assigned: lucasbaralm » Unassigned
diegors’s picture

Assigned: Unassigned » diegors
diegors’s picture

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

@lucasbaralm has fixed standards mentioned in comment #29.

Kristen Pol’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Novice

Some minor formatting issues remain:

+++ b/src/Fast404.php
@@ -213,8 +213,9 @@
+        // For arrays, use the path associated with the langcode or the ¶
+        //first path if the langcode is not set.
+        ¶

There's some whitespace and wrapping issues here.

1. "first" can move a line up
2. need space after "//"
3. do not have extraneous spaces at end of lines
4. empty line not needed

mrinalini9’s picture

Status: Needs work » Needs review
FileSize
11.19 KB
723 bytes

Updated patch #31 by addressing #35, please review it.

Thanks!

joseph.olstad’s picture

Version: 8.x-2.x-dev » 8.x-3.x-dev
seanB’s picture

Reroll for 3.x.

seanB’s picture

Fixed coding standards and made the patch compatible with 10.x (the method signature for BrowserTestBase::setUp() changed).

seanB’s picture

FileSize
2.41 KB

Yay! Tests are green. Here is the interdiff for the latest 9.x and 10.x patches of #38 / #39.

YahyaAlHamad’s picture

akashpj’s picture

Tested #39 patch in drupal 9.5.x and 10.1.x
patch applied successfully and working as expected
Verified the changes suggested in #35 - Changes are addressed.