diff --git a/core/model/ErrorPage.php b/core/model/ErrorPage.php index 5a336e521..11c30e65e 100755 --- a/core/model/ErrorPage.php +++ b/core/model/ErrorPage.php @@ -22,6 +22,8 @@ class ErrorPage extends Page { "ShowInSearch" => 0 ); + protected static $static_filepath = ASSETS_PATH; + /** * Ensures that there is always a 404 page * by checking if there's an instance of @@ -105,7 +107,10 @@ class ErrorPage extends Page { mkdir(ASSETS_PATH, 02775); } - if($fh = fopen(ASSETS_PATH . "/error-$this->ErrorCode.html", "w")) { + // if the page is published in a language other than default language, + // write a specific language version of the HTML page + $filePath = self::get_filepath_for_errorcode($this->ErrorCode, $this->Lang); + if($fh = fopen($filePath, "w")) { fwrite($fh, $errorContent); fclose($fh); } @@ -122,6 +127,39 @@ class ErrorPage extends Page { return $labels; } + + /** + * Returns an absolute filesystem path to a static error file + * which is generated through {@link publish()}. + * + * @param int $statusCode A HTTP Statuscode, mostly 404 or 500 + * @param String $lang A language code in short locale format, e.g. 'de' (Optional) + * @return String + */ + static function get_filepath_for_errorcode($statusCode, $lang = null) { + if(Translatable::is_enabled() && $lang && $lang != Translatable::default_lang()) { + return self::$static_filepath . "/error-{$statusCode}-{$lang}.html"; + } else { + return self::$static_filepath . "/error-{$statusCode}.html"; + } + } + + /** + * Set the path where static error files are saved through {@link publish()}. + * Defaults to /assets. + * + * @param string $path + */ + static function set_static_filepath($path) { + self::$static_filepath = $path; + } + + /** + * @return string + */ + static function get_static_filepath($path) { + return self::$static_filepath; + } } /** diff --git a/dev/Debug.php b/dev/Debug.php index 5a919a256..65a48893d 100644 --- a/dev/Debug.php +++ b/dev/Debug.php @@ -255,7 +255,8 @@ class Debug { if(Director::is_ajax()) { echo $friendlyErrorMessage; } else { - if(file_exists(ASSETS_PATH . "/error-$statusCode.html")) { + $errorFilePath = ErrorPage::get_filepath_for_errorcode($statusCode, Translatable::current_lang()); + if(file_exists($errorfilePath)) { echo file_get_contents(ASSETS_PATH . "/error-$statusCode.html"); } else { $renderer = new DebugView();