Freemarker (by default) uses the locale to build the file names it looks for when loading and including templates. For example, loading tos.ftl
(the template) with the en_US
locale would look for:
This can be useful to translate whole pages when the pages are completely different between different languages. For example, a "Terms of Service" page might be mostly static so different languages would have completely different content. In this case, it is a hassle to externalize the whole content to messages loaded from message bundles.
I am now learning Thymeleaf and can't find any information about a similar functionality. I know that Thymeleaf uses localized message bundles to fill in th:text
elements, but can it load localized versions of the template files?
Note: I'm using Spring Boot
FreeMarker has all the essential features to generate HTML for most of the cases, and it is easier to learn. So it is not a bad idea if you want to use it. However, Thymeleaf is the way to go if you want to add custom functionality to your templates.
Thymeleaf is a modern server-side Java template engine for both web and standalone environments.
Thymeleaf is a serve-side template engine for Java. It has built-in support for Spring framework and is widely used in Spring based Projects. In fact, Spring Boot itself has been promoting thymeleaf via several thymeleaf based projects and examples in its blog.
Thymeleaf is a modern server-side Java template engine for both web and standalone environments, capable of processing HTML, XML, JavaScript, CSS and even plain text. The main goal of Thymeleaf is to provide an elegant and highly-maintainable way of creating templates.
Thymeleaf's behaviour the same as Spring 4 MVC Internationalization (I guess you using Thymeleaf with Spring??), it uses messages.properties
to realize that.
For example you have a template with #{hello}
message:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<title></title>
</head>
<body>
<span th:text="#{hello}">
</body>
#{hello}
text will be binded to the messages.properties
proprty hello
.
If you locale
would be another, e.g. ru_RU
you just add messages_ru_RU.properties
and change the locale
of your application.
After that, your message will be taken from localized properties file.
Note that necessarily to have messages.properties
file if you using localized messages file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With