I found solution:
write in unicode symbols. For this:
IDEA -- has special "Transparent native-to-ASCII conversion" option (Settings > File Encoding).
Domanda
I want to add i18n to my web project.
But I it prints gibberish, before:
after:
Here is page snippet of page code:
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<c:set var="language"
value="${not empty param.language ? param.language : not empty language ? language : pageContext.request.locale}"
scope="session"/>
<fmt:setLocale value="${language}"/>
<fmt:setBundle basename="com.java.task11.i18n.text"/>
<html lang="${language}">
<head>
<title>Profile Info</title>
<jsp:include page="parts/header.jsp"/>
</head>
<body>
<div class="container-fluid users-table">
<%--navbar--%>
<div class="row">
<div class="col-md-10 col-xs-12 col-md-offset-1 table-nav">
<jsp:include page="parts/navbar.jsp"/>
</div>
</div>
and snippet of navbar.jsp
:
<li class="lang">
<a href="<%= request.getContextPath()%>?language=${language == 'ua' ? 'en' : 'uk'}">
${language == 'ua' ? 'EN' : 'UKR'}
</a>
</li>
Here is resource bundle looking:
I couldn't figure out why this happen?
How to solve this trouble?
Soluzione 2
I found solution:
write in unicode symbols. For this:
IDEA -- has special "Transparent native-to-ASCII conversion" option (Settings > File Encoding).
Altri suggerimenti
My hypothesis here is that you use a ResourceBundle
.
Unfortunately, and for backwards compatibility reasons, it cannot read property files in any other encoding than ISO-8859-1. And your properties file seems to be encoded in UTF-8.
Demonstration: let us take a file names t.properties
at the root of the classpath, whose contents are encoded in UTF-8:
mouton = bêêêê
Now, let us try and print out this mouton
key:
final ResourceBundle bundle = ResourceBundle.getBundle("t");
System.out.println(bundle.getString("mouton"));
Output:
bêêêê
Garbage.
This is why I have developped this library which does not have this problem; it can read i18n property files in UTF-8. Demonstration:
// Reads in UTF-8 by default; can choose any encoding
final MessageBundle bundle = PropertiesBundle.forPath("t");
System.out.println(bundle.getMessage("mouton"));
Output:
bêêêê
Correct!
The "funny" thing is that this uses a method which is available in Properties
(since 1.6) but which ResourceBundle
doesn't use, nor does it provide a way to use it...