libintl-perl

Home -> libintl-perl -> 2005 -> September

 Weird character set problem 
Login Login Subscribe Subscribe  Date  09/01/05 11:13:49 GMT
 From  Guido Flohr
 Subject  Weird character set problem
 Previous Thread
 Next Thread
 Start of Thread
 Reference
 Previous Reply
 This Message
 Reply
 Next Reply
Hi,

Robin Smidsrød wrote:
> Okay, I'm trying to get my webapplication, which uses Locale::TextDomain to
> display Norwegian characters, and it's turning out to be a real headache.
> Now everything works, but all my national characters turn up on the webage
> as question marks.
> I use CGI.pm and mod_perl 2.0.1 (apache2), and initially in the application
> I set $q->charset('UTF-8').
> ...

I would recommend to use utf-8 in your web application.  But you have to make
sure that you really generate utf-8 strings _and_ that your web server issues
a header with the correct encoding:

	Content-Type: text/html; charset=utf-8

You can check that with the option "--save-headers" from wget, and also in
most browsers (for example in Mozilla try View->Character Encoding).

I suspect that your web server does not respond with the correct header,
probably because the web server configuration contains an "AddDefaultCharset"
directive.  Try to override that in the virtual host configuration with:

	AddDefaultCharset Off
	# Alternatively:
	AddDefaultCharset utf-8

See http://httpd.apache.org/docs/2.0/mod/core.html#adddefaultcharset for
details.  Many Linux vendors have this directive in their web server
configuration.

In order to make absolutely sure that you really spit out utf-8, you should
do this:

	Locale::Messages::nl_putenv ("LANGUAGE=nb_NO.utf8");
	Locale::Messages::nl_putenv ("LANG=nb_NO.utf8");
	Locale::Messages::nl_putenv ("LC_ALL=nb_NO.utf8");
	Locale::Messages::nl_putenv ("LC_MESSAGES=nb_NO.utf8");
	Locale::Messages::nl_putenv ("OUTPUT_CHARSET=utf-8");
	setlocale (LC_ALL, "");

This should do the trick.

BTW, it is preferable to set environment variables, and then call setlocale
with an empty second argument.  Not only, because it is slightly more
portable, but it is also safer if some other part of your application or a
foreign module calls setlocale() behind your back.

Ciao,
Guido
--
Imperia AG, Development
Leyboldstr. 10 - D-50354 Hürth - http://www.imperia.net/
Attachments
 1  +-[no description] multipart/signed  
 2    |-index.html message/rfc822  
 3    +-OpenPGP digital signature application/pgp-signature  

 Download OpenPGP digital signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFDFuJnOo0HNPWNDz0RAp0oAJ4lCDeWHNx6qg7/BJm/y6Vqp/001QCgp8a/
Bt9rZ6+wkdTW/q+LuIH4iZQ=
=PVQo
-----END PGP SIGNATURE-----

ATTENTION: HTML attachments to this mail have been converted to plain text to prevent you from possibly malicious HTML files. Other attachments are included here without any checking. Choose your own poison! The maintainers of this site cannot be held responsible for any damage caused by these attachments.

 Weird character set problem
 Previous Thread
 Next Thread
 Start of Thread
 Reference
 Previous Reply
 This Message
 Reply
 Next Reply
 
 09/01/05 08:09:44 GMT  Robin Smidsrød
 09/01/05 11:13:49 GMT  +--Guido Flohr
 09/01/05 13:54:19 GMT    +--Robin Smidsrød

Powered by Imperia
Home | Top | Imprint