Thymeleaf can not find internationalized messages - spring

I tried searching on Google but could not find any solution to my problem.
The link for code is
https://github.com/optimus29/ThymeleafDemo
I get the following output on running the JUnit test com.jk.th.mail.util.MailTemplateTest.java :
----------------------------------------------
* Mail contents *
----------------------------------------------
Recipients: def#mail.com
Subject: Complete registraion process
Message:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>??subject.registration.complete_en_US??</title>
</head>
<body>
<p>??grettings.user_en_US??</p>
<p>??registration.text.line1_en_US??</p>
<p>
??registration.link.text_en_US??
</p>
<p>??registration.text.line2_en_US??</p>
<div>
<p>
<span>??thanks_en_US??</span><br/>
<span>??pustakalaya.team_en_US??</span><br/>
<span>??contact.mail_en_US??</span><br/>
<span>??contact.number_en_US??</span>
</p>
</div>
</body>
</html>
----------------------------------------------

I'm not really sure what is not right in the way you wrote the configuration, but...
Since you are using the default paths anyway, you could just remove the call (in SpringMailConfig.springTemplateEngine()):
templateEngine.setMessageResolver(messageResolver());
Then you may also remove the beans messageResolver and emailMessageSource.
After you do this, the only unresolved message will be "grettings" (because it's misspelled).

Related

Spring Boot HtmlConverter set dynamic value in html file

I would like to have dynamic value in my html file which gets Convertet to a PDF file. I've got no idea how to do that.
HTML
<!doctype html>
<html lang="en">
<head>
<title>SpringHow html to pdf</title>
</head>
<body>
<div>
<h2> --> DYNAMIC VALUE HERE <-- </h2>
</div>
</body>
</html>
JAVA
HtmlConverter.convertToPdf(new File("template.html"),new File("report.pdf"));

Thymeleaf switch statement including every case

I'm working on my first Spring MVC project and I got stuck at a problem. I have 3 types of users in my application: admin, employee and customer. Depending on the type of user, I would like to have a specific type of menu for each of them. I tried using a switch statement in my thymeleaf template but every case gets included in the output and I don't understand why.
This is the code for my method in the controller:
#RequestMapping(value = "list/{roleId}", method = RequestMethod.GET)
public String listFood(Model model, #PathVariable int roleId){
model.addAttribute("title", "Available Foods");
model.addAttribute("roleId", roleId);
model.addAttribute("foods", foodDao.findAll());
return "food/list";
}
And this is the code from the Thymeleaf template (each fragment will be included in the resulting page):
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head th:replace="fragments :: head"></head>
<body class="container">
<h1 th:text="${title}">Food</h1>
<div th:switch="${roleId}">
<p th:case="0"><nav th:replace="admin-fragments :: navigation"></nav></p>
<p th:case="1"><nav th:replace="employee-fragments :: navigation"></nav></p>
<p th:case="2"><nav th:replace="customer-fragments :: navigation"></nav></p>
</div>
</body>
</html>
However, if I change the template to the following one then only the correct case will be included in the resulting page.
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head th:replace="fragments :: head"></head>
<body class="container">
<h1 th:text="${title}">Food</h1>
<div th:switch="${roleId}">
<p th:case="0">User is an administrator</p>
<p th:case="1">User is an employee</p>
<p th:case="2">User is a customer</p>
</div>
</body>
</html>
Why isn't the switch from the first template behaving like the one in the second template? What should I change in the first template to be able to have a personalised menu for each type of user? Thank you!

How to index file contents

I have a server at batalabs.tk where I use batch files as most of my CGI scripts, I am currently trying to make an Indexing service for a search script...
Example files:
Directory to search:
<DIR HTDOCS>
index.html
otherpage1.html
otherpage2.html
</DIR>
index.html:
<HTML>
<HEAD>
<TITLE>MyWebsite - Buy Products</TITLE>
<META NAME="Description" Content="Buy Software and products from MyWebsite">
</HEAD>
<BODY>
<DIV ALIGN="CENTER">
<H2>Software</H2>
<h4>Find the latest and greatest in software right here at the Shop Page!</h4>
<hr>
Lorum - Free Cloud Storage
<hr>
Ipsum - Free Networking Software
<hr>
</div>
Copyright MyWebsite.com, 2016
</body>
</html>
Otherpage1.html
<html>
<head>
<title>Page One - Hello World!</title>
<META Name="Description" Content="Hello World Page For Testing.">
</head>
<body>
<h1>
Hello, World!
</h1>
<div>
<pre>
this is an example page for use with testing.
Any of these words can be searched and should (optimally) show this page in the results.
</pre>
</div>
</body>
</html>
otherpage2.html:
<html>
<head>
<title>Page Two - The Revenge Of The Coder</title>
<meta Name="Tags" content="dummy; coder; file; otherpage2;;">
</head>
<body>
<pre>
Hello, This file doesn't matter. At all. It is a dummy.
</pre>
</body>
</html>
These are just example files, But i want my batch file to pick up on the
<META> tag with Description and Tags, as well as the file's name, every word in the body,
and the title... I've tried some stuff to no avail, any help?
So maybe a user could type "dummy" as their keyword, and Otherpage2.html would pop up like so:
Page Two - The Revenge Of The Coder
HTTPS://www.batalabs.tk/otherpage2.html
Hello, this file doesn't matter. At all. It is a dummy.

How to change the language of new Captcha-Recaptcha

Can anyone give me an example about to change to italian ReCaptcha questions and answers?
I found the following code:
<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl=it" />
But no idea where to put it and all attempts to place it on my contact form failed.
It always speaks english only.
Thanks in advance
Script tags usually go in the head section, between the <head> and </head> tags, or just before the body closing tag, </body>.
However, you also need to add a tag in the form for the ReCaptcha to be show.
This code will display the ReCaptcha in Italian:
<html>
<head>
<title>reCAPTCHA demo: Simple page</title>
<script src="https://www.google.com/recaptcha/api.js?hl=it" async defer></script>
</head>
<body>
<form action="?" method="POST">
<div class="g-recaptcha" data-sitekey="your_site_key"></div>
<br/>
<input type="submit" value="Submit">
</form>
</body>
</html>
You need to replace the data-sitekey attribute with your own API sitekey.

jekyll/liquid does not parse key/value dicts in page preamble on github pages

I have a file test.md:
---
layout: test
item: {"label":"value"}
---
This text should not appear
and a corresponding file _layouts/test.html:
<!DOCTYPE html>
<html>
<body>
<h1>Hello world!</h1>
The field <em>label</em> has value <em>{{ page.item.label }}</em>.
</body>
</html>
On my local server I get, as expected, the following page in _site/test.html:
<!DOCTYPE html>
<html>
<body>
<h1>Hello world!</h1>
The field <em>label</em> has value <em>value</em>.
</body>
</html>
while on github (see http://altomani.github.com/test.html) the result is:
<p>This text should not appear</p>
Though I couldn’t reproduce the problem, I would suggest you to follow the guidelines and use yaml in preambles rather than dicts:
---
layout : test
item :
label : value
---
This should definitely work.

Resources