From 06c3a4bc2981fd5589967f96736de51c503bb301 Mon Sep 17 00:00:00 2001
From: Robert Goldmann <deadlocker@gmx.de>
Date: Sat, 17 Mar 2018 17:16:52 +0100
Subject: [PATCH] Fixed #295 - localize error pages

---
 .../budgetmaster/controller/TeapotController.java          | 2 +-
 src/main/resources/application.properties                  | 2 --
 src/main/resources/languages/_de.properties                | 7 +++++++
 src/main/resources/languages/_en.properties                | 7 +++++++
 .../{static/error/403.html => templates/error/403.ftl}     | 5 +++--
 .../{static/error/404.html => templates/error/404.ftl}     | 5 +++--
 .../{static/error/418.html => templates/error/418.ftl}     | 7 ++++---
 .../{static/error/500.html => templates/error/500.ftl}     | 5 +++--
 8 files changed, 28 insertions(+), 12 deletions(-)
 rename src/main/resources/{static/error/403.html => templates/error/403.ftl} (89%)
 rename src/main/resources/{static/error/404.html => templates/error/404.ftl} (89%)
 rename src/main/resources/{static/error/418.html => templates/error/418.ftl} (82%)
 rename src/main/resources/{static/error/500.html => templates/error/500.ftl} (90%)

diff --git a/src/main/java/de/deadlocker8/budgetmaster/controller/TeapotController.java b/src/main/java/de/deadlocker8/budgetmaster/controller/TeapotController.java
index f69564084..d5fc0e947 100644
--- a/src/main/java/de/deadlocker8/budgetmaster/controller/TeapotController.java
+++ b/src/main/java/de/deadlocker8/budgetmaster/controller/TeapotController.java
@@ -10,6 +10,6 @@ public class TeapotController extends BaseController
 	@RequestMapping("/418")
 	public String index()
 	{
-		return "error/418.html";
+		return "error/418";
 	}
 }
\ No newline at end of file
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index f027bea07..736cccfe5 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -5,8 +5,6 @@ logging.level.root=INFO
 logging.level.de.deadlocker8=DEBUG
 logging.file=error.log
 
-spring.freemarker.template-loader-path=classpath:/templates
-spring.freemarker.suffix=.ftl
 spring.mvc.log-resolved-exception=false
 
 spring.jpa.hibernate.ddl-auto=update
diff --git a/src/main/resources/languages/_de.properties b/src/main/resources/languages/_de.properties
index f1227ca6e..a0f0313de 100644
--- a/src/main/resources/languages/_de.properties
+++ b/src/main/resources/languages/_de.properties
@@ -10,6 +10,13 @@ folder=Deadlocker/BudgetMaster
 roadmap.url=https://deadlocker.thecodelabs.de/roadmap/php/index.php?id=1
 github.url=https://github.com/deadlocker8/BudgetMaster
 
+# ERRORPAGES
+errorpages.home=Zur Startseite
+errorpages.403=Zugriff nicht gestattet.
+errorpages.404=Die angegebene Seite konnte nicht gefunden werden.
+errorpages.418=I'm a teapot.
+errorpages.418.credits=Teapot icon made by <a href="http://www.freepik.com" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a>
+errorpages.500=Ein interner Serverfehler ist aufgetreten.
 
 # TITLE
 title.incomes=Einnahmen
diff --git a/src/main/resources/languages/_en.properties b/src/main/resources/languages/_en.properties
index 1254f6fbf..586aa8788 100644
--- a/src/main/resources/languages/_en.properties
+++ b/src/main/resources/languages/_en.properties
@@ -10,6 +10,13 @@ folder=Deadlocker/BudgetMaster
 roadmap.url=https://deadlocker.thecodelabs.de/roadmap/php/index.php?id=2
 github.url=https://github.com/deadlocker8/BudgetMaster
 
+# ERRORPAGES
+errorpages.home=To Homepage
+errorpages.403=Access denied.
+errorpages.404=The requested page doesn't exist.
+errorpages.418=I'm a teapot.
+errorpages.418.credits=Teapot icon made by <a href="http://www.freepik.com" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a>
+errorpages.500=An internal server error occurred.
 
 # TITLE
 title.incomes=Incomes
diff --git a/src/main/resources/static/error/403.html b/src/main/resources/templates/error/403.ftl
similarity index 89%
rename from src/main/resources/static/error/403.html
rename to src/main/resources/templates/error/403.ftl
index 92b3051d4..d2eb3e6d1 100644
--- a/src/main/resources/static/error/403.html
+++ b/src/main/resources/templates/error/403.ftl
@@ -8,6 +8,7 @@
         <link type="text/css" rel="stylesheet" href="/css/login.css"/>
 
         <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
+        <#assign locale = localization["tools.Localization"]>
     </head>
     <body class="budgetmaster-blue-light">
         <main>
@@ -21,11 +22,11 @@
                             <div class="row">
                                 <div class="col s12 center-align">
                                     <h1>šŸ”’ 403</h1>
-                                    <h5>Zugriff nicht gestattet.</h5>
+                                    <h5>${locale.getString("errorpages.403")}</h5>
                                 </div>
                             </div>
                             <div class="center-align">
-                                <a href="/" class="waves-effect waves-light btn budgetmaster-blue"><i class="material-icons left">home</i>Zur Startseite</a>
+                                <a href="/" class="waves-effect waves-light btn budgetmaster-blue"><i class="material-icons left">home</i>${locale.getString("errorpages.home")}</a>
                             </div>
                         </div>
                     </div>
diff --git a/src/main/resources/static/error/404.html b/src/main/resources/templates/error/404.ftl
similarity index 89%
rename from src/main/resources/static/error/404.html
rename to src/main/resources/templates/error/404.ftl
index fa9d094f4..34ef5cb44 100644
--- a/src/main/resources/static/error/404.html
+++ b/src/main/resources/templates/error/404.ftl
@@ -8,6 +8,7 @@
         <link type="text/css" rel="stylesheet" href="/css/login.css"/>
 
         <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
+        <#assign locale = localization["tools.Localization"]>
     </head>
     <body class="budgetmaster-blue-light">
         <main>
@@ -21,11 +22,11 @@
                             <div class="row">
                                 <div class="col s12 center-align">
                                     <h1>šŸ˜” 404</h1>
-                                    <h5>Die angegebene Seite konnte nicht gefunden werden.</h5>
+                                    <h5>${locale.getString("errorpages.404")}</h5>
                                 </div>
                             </div>
                             <div class="center-align">
-                                <a href="/" class="waves-effect waves-light btn budgetmaster-blue"><i class="material-icons left">home</i>Zur Startseite</a>
+                                <a href="/" class="waves-effect waves-light btn budgetmaster-blue"><i class="material-icons left">home</i>${locale.getString("errorpages.home")}</a>
                             </div>
                         </div>
                     </div>
diff --git a/src/main/resources/static/error/418.html b/src/main/resources/templates/error/418.ftl
similarity index 82%
rename from src/main/resources/static/error/418.html
rename to src/main/resources/templates/error/418.ftl
index 81c1f733e..88bf69273 100644
--- a/src/main/resources/static/error/418.html
+++ b/src/main/resources/templates/error/418.ftl
@@ -8,6 +8,7 @@
         <link type="text/css" rel="stylesheet" href="/css/login.css"/>
 
         <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
+        <#assign locale = localization["tools.Localization"]>
     </head>
     <body class="budgetmaster-blue-light">
         <main>
@@ -22,12 +23,12 @@
                                 <div class="col s12 center-align">
                                     <img id="teapot" src="/images/teapot.png">
                                     <h1>418</h1>
-                                    <h5>I’m a teapot.</h5>
-                                    <div>Teapot icon made by <a href="http://www.freepik.com" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a></div>
+                                    <h5>${locale.getString("errorpages.418")}</h5>
+                                    <div>${locale.getString("errorpages.418.credits")}</div>
                                 </div>
                             </div>
                             <div class="center-align">
-                                <a href="/" class="waves-effect waves-light btn budgetmaster-blue"><i class="material-icons left">home</i>Zur Startseite</a>
+                                <a href="/" class="waves-effect waves-light btn budgetmaster-blue"><i class="material-icons left">home</i>${locale.getString("errorpages.home")}</a>
                             </div>
                         </div>
                     </div>
diff --git a/src/main/resources/static/error/500.html b/src/main/resources/templates/error/500.ftl
similarity index 90%
rename from src/main/resources/static/error/500.html
rename to src/main/resources/templates/error/500.ftl
index d2f1963e3..ac535d122 100644
--- a/src/main/resources/static/error/500.html
+++ b/src/main/resources/templates/error/500.ftl
@@ -8,6 +8,7 @@
         <link type="text/css" rel="stylesheet" href="/css/login.css"/>
 
         <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
+        <#assign locale = localization["tools.Localization"]>
     </head>
     <body class="budgetmaster-blue-light">
         <main>
@@ -21,11 +22,11 @@
                             <div class="row">
                                 <div class="col s12 center-align">
                                     <h1>šŸ˜” 500</h1>
-                                    <h5>Ein interner Serverfehler ist aufgetreten.</h5>
+                                    <h5>${locale.getString("errorpages.500")}</h5>
                                 </div>
                             </div>
                             <div class="center-align">
-                                <a href="/" class="waves-effect waves-light btn budgetmaster-blue"><i class="material-icons left">home</i>Zur Startseite</a>
+                                <a href="/" class="waves-effect waves-light btn budgetmaster-blue"><i class="material-icons left">home</i>${locale.getString("errorpages.home")}</a>
                             </div>
                         </div>
                     </div>
-- 
GitLab