You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2020/01/14 19:45:18 UTC
[tomcat] branch master updated: Fix
https://bz.apache.org/bugzilla/show_bug.cgi?id=64000 i18n use client
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push:
new a8bf66c Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=64000 i18n use client
a8bf66c is described below
commit a8bf66c534dc3ca7ba358f00f858af5142a3f59b
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Tue Jan 14 19:45:03 2020 +0000
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=64000 i18n use client
Ensure that the example web application uses the client locale rather
than the server locale where it provides i18n support
---
.../examples/WEB-INF/classes/CookieExample.java | 21 ++++++++++-----------
.../WEB-INF/classes/RequestHeaderExample.java | 6 +++---
.../WEB-INF/classes/RequestInfoExample.java | 16 ++++++++--------
.../WEB-INF/classes/RequestParamExample.java | 18 +++++++++---------
.../examples/WEB-INF/classes/SessionExample.java | 22 +++++++++++-----------
5 files changed, 41 insertions(+), 42 deletions(-)
diff --git a/webapps/examples/WEB-INF/classes/CookieExample.java b/webapps/examples/WEB-INF/classes/CookieExample.java
index 50808bf..b91b52d 100644
--- a/webapps/examples/WEB-INF/classes/CookieExample.java
+++ b/webapps/examples/WEB-INF/classes/CookieExample.java
@@ -39,13 +39,12 @@ public class CookieExample extends HttpServlet {
private static final long serialVersionUID = 1L;
- private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
-
@Override
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
+ ResourceBundle rb = ResourceBundle.getBundle("LocalStrings",request.getLocale());
String cookieName = request.getParameter("cookiename");
String cookieValue = request.getParameter("cookievalue");
@@ -64,7 +63,7 @@ public class CookieExample extends HttpServlet {
out.println("<head>");
out.println("<meta charset=\"UTF-8\" />");
- String title = RB.getString("cookies.title");
+ String title = rb.getString("cookies.title");
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
@@ -91,7 +90,7 @@ public class CookieExample extends HttpServlet {
if (session != null) {
sessionId = session.getId();
}
- out.println(RB.getString("cookies.cookies") + "<br>");
+ out.println(rb.getString("cookies.cookies") + "<br>");
for (int i = 0; i < cookies.length; i++) {
Cookie cookie = cookies[i];
String cName = cookie.getName();
@@ -102,25 +101,25 @@ public class CookieExample extends HttpServlet {
+ "<br><br>");
}
} else {
- out.println(RB.getString("cookies.no-cookies"));
+ out.println(rb.getString("cookies.no-cookies"));
}
if (aCookie != null) {
out.println("<P>");
- out.println(RB.getString("cookies.set") + "<br>");
- out.print(RB.getString("cookies.name") + " "
+ out.println(rb.getString("cookies.set") + "<br>");
+ out.print(rb.getString("cookies.name") + " "
+ HTMLFilter.filter(cookieName) + "<br>");
- out.print(RB.getString("cookies.value") + " "
+ out.print(rb.getString("cookies.value") + " "
+ HTMLFilter.filter(cookieValue));
}
out.println("<P>");
- out.println(RB.getString("cookies.make-cookie") + "<br>");
+ out.println(rb.getString("cookies.make-cookie") + "<br>");
out.print("<form action=\"");
out.println("CookieExample\" method=POST>");
- out.print(RB.getString("cookies.name") + " ");
+ out.print(rb.getString("cookies.name") + " ");
out.println("<input type=text length=20 name=cookiename><br>");
- out.print(RB.getString("cookies.value") + " ");
+ out.print(rb.getString("cookies.value") + " ");
out.println("<input type=text length=20 name=cookievalue><br>");
out.println("<input type=submit></form>");
diff --git a/webapps/examples/WEB-INF/classes/RequestHeaderExample.java b/webapps/examples/WEB-INF/classes/RequestHeaderExample.java
index 2c3cd70..56c5eeb 100644
--- a/webapps/examples/WEB-INF/classes/RequestHeaderExample.java
+++ b/webapps/examples/WEB-INF/classes/RequestHeaderExample.java
@@ -40,13 +40,13 @@ public class RequestHeaderExample extends HttpServlet {
private static final long serialVersionUID = 1L;
- private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
-
@Override
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
+ ResourceBundle rb = ResourceBundle.getBundle("LocalStrings",request.getLocale());
+
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
@@ -55,7 +55,7 @@ public class RequestHeaderExample extends HttpServlet {
out.println("<head>");
out.println("<meta charset=\"UTF-8\" />");
- String title = RB.getString("requestheader.title");
+ String title = rb.getString("requestheader.title");
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
diff --git a/webapps/examples/WEB-INF/classes/RequestInfoExample.java b/webapps/examples/WEB-INF/classes/RequestInfoExample.java
index d0c7530..c3c3133 100644
--- a/webapps/examples/WEB-INF/classes/RequestInfoExample.java
+++ b/webapps/examples/WEB-INF/classes/RequestInfoExample.java
@@ -36,13 +36,13 @@ public class RequestInfoExample extends HttpServlet {
private static final long serialVersionUID = 1L;
- private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
-
@Override
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
+ ResourceBundle rb = ResourceBundle.getBundle("LocalStrings",request.getLocale());
+
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
@@ -51,7 +51,7 @@ public class RequestInfoExample extends HttpServlet {
out.println("<head>");
out.println("<meta charset=\"UTF-8\" />");
- String title = RB.getString("requestinfo.title");
+ String title = rb.getString("requestinfo.title");
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
@@ -72,23 +72,23 @@ public class RequestInfoExample extends HttpServlet {
out.println("<h3>" + title + "</h3>");
out.println("<table border=0><tr><td>");
- out.println(RB.getString("requestinfo.label.method"));
+ out.println(rb.getString("requestinfo.label.method"));
out.println("</td><td>");
out.println(HTMLFilter.filter(request.getMethod()));
out.println("</td></tr><tr><td>");
- out.println(RB.getString("requestinfo.label.requesturi"));
+ out.println(rb.getString("requestinfo.label.requesturi"));
out.println("</td><td>");
out.println(HTMLFilter.filter(request.getRequestURI()));
out.println("</td></tr><tr><td>");
- out.println(RB.getString("requestinfo.label.protocol"));
+ out.println(rb.getString("requestinfo.label.protocol"));
out.println("</td><td>");
out.println(HTMLFilter.filter(request.getProtocol()));
out.println("</td></tr><tr><td>");
- out.println(RB.getString("requestinfo.label.pathinfo"));
+ out.println(rb.getString("requestinfo.label.pathinfo"));
out.println("</td><td>");
out.println(HTMLFilter.filter(request.getPathInfo()));
out.println("</td></tr><tr><td>");
- out.println(RB.getString("requestinfo.label.remoteaddr"));
+ out.println(rb.getString("requestinfo.label.remoteaddr"));
out.println("</td><td>");
out.println(HTMLFilter.filter(request.getRemoteAddr()));
out.println("</td></tr>");
diff --git a/webapps/examples/WEB-INF/classes/RequestParamExample.java b/webapps/examples/WEB-INF/classes/RequestParamExample.java
index 2bf2b65..6eb2c13 100644
--- a/webapps/examples/WEB-INF/classes/RequestParamExample.java
+++ b/webapps/examples/WEB-INF/classes/RequestParamExample.java
@@ -36,13 +36,13 @@ public class RequestParamExample extends HttpServlet {
private static final long serialVersionUID = 1L;
- private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
-
@Override
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
+ ResourceBundle rb = ResourceBundle.getBundle("LocalStrings",request.getLocale());
+
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
@@ -51,7 +51,7 @@ public class RequestParamExample extends HttpServlet {
out.println("<head>");
out.println("<meta charset=\"UTF-8\" />");
- String title = RB.getString("requestparams.title");
+ String title = rb.getString("requestparams.title");
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
@@ -74,23 +74,23 @@ public class RequestParamExample extends HttpServlet {
out.println("<h3>" + title + "</h3>");
String firstName = request.getParameter("firstname");
String lastName = request.getParameter("lastname");
- out.println(RB.getString("requestparams.params-in-req") + "<br>");
+ out.println(rb.getString("requestparams.params-in-req") + "<br>");
if (firstName != null || lastName != null) {
- out.println(RB.getString("requestparams.firstname"));
+ out.println(rb.getString("requestparams.firstname"));
out.println(" = " + HTMLFilter.filter(firstName) + "<br>");
- out.println(RB.getString("requestparams.lastname"));
+ out.println(rb.getString("requestparams.lastname"));
out.println(" = " + HTMLFilter.filter(lastName));
} else {
- out.println(RB.getString("requestparams.no-params"));
+ out.println(rb.getString("requestparams.no-params"));
}
out.println("<P>");
out.print("<form action=\"");
out.print("RequestParamExample\" ");
out.println("method=POST>");
- out.println(RB.getString("requestparams.firstname"));
+ out.println(rb.getString("requestparams.firstname"));
out.println("<input type=text size=20 name=firstname>");
out.println("<br>");
- out.println(RB.getString("requestparams.lastname"));
+ out.println(rb.getString("requestparams.lastname"));
out.println("<input type=text size=20 name=lastname>");
out.println("<br>");
out.println("<input type=submit>");
diff --git a/webapps/examples/WEB-INF/classes/SessionExample.java b/webapps/examples/WEB-INF/classes/SessionExample.java
index dea09b6..3fc3f72 100644
--- a/webapps/examples/WEB-INF/classes/SessionExample.java
+++ b/webapps/examples/WEB-INF/classes/SessionExample.java
@@ -39,13 +39,13 @@ public class SessionExample extends HttpServlet {
private static final long serialVersionUID = 1L;
- private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
-
@Override
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
+ ResourceBundle rb = ResourceBundle.getBundle("LocalStrings",request.getLocale());
+
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
@@ -55,7 +55,7 @@ public class SessionExample extends HttpServlet {
out.println("<meta charset=\"UTF-8\" />");
- String title = RB.getString("sessions.title");
+ String title = rb.getString("sessions.title");
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
@@ -77,11 +77,11 @@ public class SessionExample extends HttpServlet {
out.println("<h3>" + title + "</h3>");
HttpSession session = request.getSession(true);
- out.println(RB.getString("sessions.id") + " " + session.getId());
+ out.println(rb.getString("sessions.id") + " " + session.getId());
out.println("<br>");
- out.println(RB.getString("sessions.created") + " ");
+ out.println(rb.getString("sessions.created") + " ");
out.println(new Date(session.getCreationTime()) + "<br>");
- out.println(RB.getString("sessions.lastaccessed") + " ");
+ out.println(rb.getString("sessions.lastaccessed") + " ");
out.println(new Date(session.getLastAccessedTime()));
String dataName = request.getParameter("dataname");
@@ -91,7 +91,7 @@ public class SessionExample extends HttpServlet {
}
out.println("<P>");
- out.println(RB.getString("sessions.data") + "<br>");
+ out.println(rb.getString("sessions.data") + "<br>");
Enumeration<String> names = session.getAttributeNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
@@ -105,10 +105,10 @@ public class SessionExample extends HttpServlet {
out.print(response.encodeURL("SessionExample"));
out.print("\" ");
out.println("method=POST>");
- out.println(RB.getString("sessions.dataname"));
+ out.println(rb.getString("sessions.dataname"));
out.println("<input type=text size=20 name=dataname>");
out.println("<br>");
- out.println(RB.getString("sessions.datavalue"));
+ out.println(rb.getString("sessions.datavalue"));
out.println("<input type=text size=20 name=datavalue>");
out.println("<br>");
out.println("<input type=submit>");
@@ -119,10 +119,10 @@ public class SessionExample extends HttpServlet {
out.print(response.encodeURL("SessionExample"));
out.print("\" ");
out.println("method=GET>");
- out.println(RB.getString("sessions.dataname"));
+ out.println(rb.getString("sessions.dataname"));
out.println("<input type=text size=20 name=dataname>");
out.println("<br>");
- out.println(RB.getString("sessions.datavalue"));
+ out.println(rb.getString("sessions.datavalue"));
out.println("<input type=text size=20 name=datavalue>");
out.println("<br>");
out.println("<input type=submit>");
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: [tomcat] branch master updated: Fix
https://bz.apache.org/bugzilla/show_bug.cgi?id=64000 i18n use client
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Mark,
On 1/14/20 2:45 PM, markt@apache.org wrote:
> This is an automated email from the ASF dual-hosted git
> repository.
>
> markt pushed a commit to branch master in repository
> https://gitbox.apache.org/repos/asf/tomcat.git
>
>
> The following commit(s) were added to refs/heads/master by this
> push: new a8bf66c Fix
> https://bz.apache.org/bugzilla/show_bug.cgi?id=64000 i18n use
> client a8bf66c is described below
>
> commit a8bf66c534dc3ca7ba358f00f858af5142a3f59b Author: Mark Thomas
> <ma...@apache.org> AuthorDate: Tue Jan 14 19:45:03 2020 +0000
>
> Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=64000 i18n use
> client
>
> Ensure that the example web application uses the client locale
> rather than the server locale where it provides i18n support ---
> .../examples/WEB-INF/classes/CookieExample.java | 21
> ++++++++++----------- .../WEB-INF/classes/RequestHeaderExample.java
> | 6 +++--- .../WEB-INF/classes/RequestInfoExample.java | 16
> ++++++++-------- .../WEB-INF/classes/RequestParamExample.java
> | 18 +++++++++---------
> .../examples/WEB-INF/classes/SessionExample.java | 22
> +++++++++++----------- 5 files changed, 41 insertions(+), 42
> deletions(-)
>
> diff --git a/webapps/examples/WEB-INF/classes/CookieExample.java
> b/webapps/examples/WEB-INF/classes/CookieExample.java index
> 50808bf..b91b52d 100644 ---
> a/webapps/examples/WEB-INF/classes/CookieExample.java +++
> b/webapps/examples/WEB-INF/classes/CookieExample.java @@ -39,13
> +39,12 @@ public class CookieExample extends HttpServlet {
>
> private static final long serialVersionUID = 1L;
>
> - private static final ResourceBundle RB =
> ResourceBundle.getBundle("LocalStrings"); - @Override public void
> doGet(HttpServletRequest request, HttpServletResponse response)
> throws IOException, ServletException { + ResourceBundle rb =
> ResourceBundle.getBundle("LocalStrings",request.getLocale());
This is a good initial step, but it's not great. What a "real" web
application needs is what amounts to content-negotiation.
Since the client can send Accept-Lang: ru, fr, en, request.getLocale()
will get just the first of those (or the preferred one?). But if we
don't have e.g. "ru" locale, we should really fall-back to "fr", then
"en", etc.
I know it's more code, but it's what must be done in order to
implement things properly. Unfortunately, ResourceBundle doesn't ave a
way to get the available locales: you have to ask for each one in turn.
I'm happy to volunteer for the effort. I just wanted to get the
conversation started.
- -chris
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/
iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl4eRLIACgkQHPApP6U8
pFhYVQ/7B7s0BX8917YAQqZs3DmlxZ6fE5/m/Y+l/pwvdDwVpzie6GxD5b0n/FS7
XGBtM8FcR+dxOraM6J7pq1+bLNZIlrCZt3c26KHtaqXMAVU6UOAiHsvOMjd8+GtW
fnKQqPuE2IYiGkD59qlqypUnQBjopXHwbuQdkn96iawnqHaHwdXV+7i/o8FtXX9A
Ew2nkKPFHNM5tnG4UQ+rMj/i2yCuAf33zZoJS6Qw19ksyFWX1XhYzTY+f+DVRuMS
om+Jimysrth7nvytsaTxhLKSADpBhr8aBC4bOF/Ia6duf5qLzi/jDRPmBDM63hpG
bzHX9MF8c9j0vwTuCs/Xi95PbQlreJn/6JM02Xv9hGRhXWas1pqR3k3ZdeJ3vMK3
W3GU+t2k9wQErH5J/RNN95vHBJWhOvsVcKGJO8QZ79662WwonmiJtklZIvzQbt3R
xDGBudNfZcBXw+uAdrXXQ/zKJTQf9v8Zp1FJe1pUaS2gf5sOwE4Z2wNzSDSWYPgG
KT5DTlUAEnkM/fa5KE22oxitpAKK/yuLoujrDombgqTqkdz68ZObWqt6fWCvb68b
KWT4VLIJz26Q4gD1jMiGIvsEX9Pz/DJqrxf4h/8rG+gtnlry+yQJ+fqaPr3kEBcF
P8/+N+o4ulvxUtIfArnjkdVgeN2nWmCxh4TbhAIsCwE181ZT8dQ=
=iiLA
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org