[jboss-user] [JBoss Seam] - Step-by-step localization guide

nhpvti do-not-reply at jboss.com
Mon Sep 4 05:08:36 EDT 2006


You know, most of us in the world are natively speaking not English. 
So I think that it would make sense to pre-configure Seam samples and seam-gen to produce ready-to-localize applications. I spent  last Friday by figuring out how to fill this gap.

Here is my step-by-step localization guide compiled from different sources on net:

1) add new supported locale
in .../WEB-INF/faces-config.xml for example:
<locale-config>
  |  <default-locale>en</default-locale>
  |  <supported-locale>en</supported-locale>
  |  <supported-locale>de</supported-locale>	
  |  <supported-locale>ru</supported-locale>		
  | </locale-config>
  | 
2) Create new messages files, in my example messages_de.properties and messages_ru.properties
The 1st obstacle that should be considered here: property files should be UTF-8 encoded and transformed into ASCII by escaping UTF-8 characters (mix of ISO char sets is not advisable in a multi-language web application). 
Built-in Eclipse properties editor cannot handle this, so I've installed Resource Bundle editor from
http://sourceforge.net/projects/eclipse-rbe/  (thank you guys for excellent work!)
Alternatively you can use utility from JDK, e.g.:
native2ascii.exe -encoding utf-8 messages_ru.txt messages_ru.properties
3) Configure your code editors to use UTF-8.
For example in Eclipse 3.2 check settings under i.	Window-Preferences-General-Workspace-Text and ii.	Window-Preferences-Web and XML-CSS Files, HTML Files, JSP Files, XML Files

4) In order to enable UTF-8 in input fields (the 2nd big obstacle) you will need a phase listener (compensating bug in myfaces and(or) JSF components?) that re-sets request char set to UTF-8.
To do this follow instructions found in 
https://facelets.dev.java.net/servlets/ReadMsg?list=users&msgNo=1403
(see also discussion here  http://www.jboss.com/?module=bb&op=viewtopic&t=73369)

and activate the listener in the .../WEB-INF/faces-config.xml file, e.g.:
<lifecycle>
  | <phase-listener>org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener</phase-listener>
  | <phase-listener>com.xxx.yyy.zzz.util.UTF8PhaseListener</phase-listener>
  | </lifecycle>

5) Set char set in template(s) to UTF-8:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" pageEncoding="UTF-8" />

6) The last, MySQL specific, obstacle eaten much time to find out a solution: force JDBC driver to use UTF-8, otherwise only ? characters will be saved in the database. So extend JDBC url in a data source file, e.g.:
<jndi-name>myDatasource</jndi-name>
  | <connection-url>jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=utf8&charactetrResultSets=utf8</connection-url>
  | <driver-class>com.mysql.jdbc.Driver</driver-class>

7) Create database with default UTF-8 support, for example for MySQL:
CREATE DATABASE mydb DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
  | 
Note: probably you have to change default tables type to InnoDB for transactions support. You can do this by adding start parameter (or via MySQL configuration file). On SuSE 9.2 this can look so:
in /etc/init.d/mysql.server:
$bindir/mysqld_safe --datadir=$datadir --default-table-type=innodb --pid-file=$pid_file >/dev/null 2>&1 &

Ready, now you have your native language as static text, data input and database output.
 
I hope this small contribution will save you a couple of hours.
And I hope that others in this forum will follow my example and share their experience in more detail, not simply stating: "I've solved the problem XYZ!"

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3969180#3969180

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3969180



More information about the jboss-user mailing list