Internationalization

I plan to design a web page with language options like English and Traditional Chinese. User could choose the output language they want.

My computer uses the Hong Kong SAR for the regional and the language setting. When I open a jsp page, it displayed "?title?" for the title. Below is an example of my code:

Code of welcome.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%>

<fmt:bundle basename="welcome">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title><fmt:message key="title"/></title>

</head>

</html>

</fmt:bundle>

Code of welcome_en.properties:

title=Welcome!

Code of welcome_zh_hk.properties:

title=歡迎光臨!

But, when I change the language to English, it could displayed "Welcome!".

[1266 byte] By [HoneyLemona] at [2007-11-26 16:27:16]
# 1

You say that you have the following 2 files:

welcome_en.properties

welcome_zh_hk.properties

And you tell us what the regional and language settings of your computer are - that is not the most important issue for a servlet application, however. You either use the language that is passed in by your browser or let the user select the language explicitly. From your code below I assume it relies on the browser language setting - check what it is.

If the browser setting is 'zh', then your 'zh_HK' file won't be found, since the name is too specific. And if you don't have a file with the base name 'welcome.properties', then it won't find a resource at all, thus displaying question marks.

So if you really don't have a properties file with just the base name, you need to create it - it is the file that will be used as a fallback if none of the files for the specific locale requested are found.

one_danea at 2007-7-8 22:51:27 > top of Java-index,Desktop,I18N...
# 2
Thanks for your explanation. It really helps.I had used the tool native2ascii to convert the traditional Chinese characters to the appropriate encoding. Then, refer to your reference. The problem solved.
HoneyLemona at 2007-7-8 22:51:27 > top of Java-index,Desktop,I18N...