Sefran2
Sefran2

Reputation: 3588

jstl and i18n: language selection and db

I have to build a multi-language web site in JSP/Servlet.

I'm considering JSTL for the i18n, and I've some general questions:

1) is it possible to handle with jstl both the language selection by hand (e.g. through a pull-down menu or a link) and the automatic language recognition?

2) what is the better approach if the most part of strings are dynamic (retrieved from a database)?

Upvotes: 1

Views: 1075

Answers (1)

BalusC
BalusC

Reputation: 1109262

is it possible to handle with jstl both the language selection by hand (e.g. through a pull-down menu or a link) and the automatic language recognition?

Yes. See also How to internationalize a Java web application?.


what is the better approach if the most part of strings are dynamic (retrieved from a database)?

You'd need to create a custom ResourceBundle.Control which you inject in the request scope by a Filter. This filter should basically take over the job of <fmt:setLocale> and <fmt:setBundle>.

request.setAttribute("bundleName", yourCustomResourceBundle);

See also internationalization in JSF with ResourceBundle entries which are loaded from database (although JSF targeted, the idea is the same for plain JSP; as said, you'd only need a Filter instead to set it).

Upvotes: 1

Related Questions