XWiki Character Encoding Configuration

Here is below the configuration for UTF-8. Note that this is valid for XWiki 1.0 b5 and above. Easier configuration might be provided for upcoming releases.

XWiki encoding

Change the charset enconding in these XWiki files :

  • web.xml: locate the filter class com.xpn.xwiki.web.SetCharacterEncodingFilter and change it to UTF-8. It should look like this
<filter>
    <filter-name>Set Character Encoding</filter-name>
    <filter-class>com.xpn.xwiki.web.SetCharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
</filter>

  • xwiki.cfg : locate the line containing xwiki.encoding and change it to look like this
xwiki.encoding = UTF-8

HTML encoding

Change the HTML encoding in XWiki through Administration --> Preferences --> Presentation --> HTTP Meta information. Inside this textbox locate the Content-type meta tag and make it look like this, changing the encoding to UTF-8

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

Hibernate configuration

Add the following lines in the hibernate.cfg.xml file:

<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>

MySQL configuration

It's common practice that the MySQL configuration file, in *nix systems is located in /etc/mysql/my.cnf

[client]
default-character-set=utf8
[mysqld]
default-character-set=utf8
character-set-server = utf8
collation-server = utf8_general_ci

Java application server (Tomcat or Jetty for instance)

Jetty

echo off
rem set LANG=fr_FR.ISO8859-1
set LANG=en_US.UTF-8
set JETTY_PORT=8080
set JETTY_HOME=.
java %JAVA_OPTS% -Djetty.port=%JETTY_PORT% -Djetty.home=%JETTY_HOME% -Dfile.encoding=UTF-8 -jar %JETTY_HOME%/start.jar

Instead of config system variable LANG you can use JVM properties

-Duser.language=en
-Duser.country=US

in server startup script.

Tomcat

In order to enable UTF-8 in tomcat, you have to add

uRIEncoding="UTF-8"

to each connector enabled/used in conf/server.xml. For example the non-SSL HTTP Connector should read:

<Connector port="8080" maxHttpHeaderSize="8192"
    maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
    enableLookups="false" redirectPort="8443" acceptCount="100"
    connectionTimeout="20000" disableUploadTimeout="true"
    uRIEncoding="UTF-8"/>

System config

Add the following variables to your system

LANG = en_US.UTF-8

Credits: http://www.nabble.com/Re%3A-problem-with-Chinese-p9547507.html

Version 5.2 last modified by NielsMayer on 20/04/2008 at 08:22

Comments 3

amelentev | 20.03.2007 at 02:31 PM
As i know $LANG must be "en_US.UTF-8" ? (wrong format)

bitman09 | 20.11.2007 at 02:46 PM
You're right, it has been corrected. BTW, anyone that can log-in to the wiki (free registration) can change it. No offense, please.

NielsMayer | 20.04.2008 at 08:22 AM
Is anything more than "default-character-set=utf8" needed under mysqld? in /etc/my.cnf in order to get mysql working properly with UTF8? At least in my case, I think UTF-8 has been working correctly both without 'character-set-server = utf8' and 'collation-server = utf8_general_ci'

I'm using "mysql Ver 14.12 Distrib 5.0.45, for redhat-linux-gnu (x86_64) using readline 5.0"

Also, I've been running successfully with UTF8 WITHOUT "LANG=en_US.UTF-8" env-var setting. Is this really necessary? It seems quite broken for an environment variable in the server's shell to affect the language settings of webapps running on that server.... (not that that's a good reason for a "feature" like this to occur).

Attachments 0

No attachments for this document

Creator: slauriere on 2007/03/20 11:54
This wiki is licensed under a Creative Commons license
1.3.2.9174