boboson has asked for the wisdom of the Perl Monks concerning the following question:

I am developing a webpage in 2 different languages. Swedish and English. I am using the CGI::Application framework with HTML::Template as a template system
I am using the Class::PhraseBook module to accomplish this.
Class::PhraseBook loads an XML file which holds my phrases in Swedish and English, it looks like this:
<?xml version="1.0"?> <!DOCTYPE phrasebook [ <!ELEMENT phrasebook (dictionary)*> <!ELEMENT dictionary (phrase)*> <!ATTLIST dictionary name CDATA #REQUIRED> <!ELEMENT phrase (#PCDATA)> <!ATTLIST phrase name CDATA #REQUIRED> ]> <phrasebook> <dictionary name="SE"> <phrase name="1">tävlingar</phrase> </dictionary> <dictionary name="EN"> <phrase name="1">comp</phrase> </dictiona +ry> </phrasebook>
I create the C::PhraseBook objekt in my CGI::App base class like this.
# get phrasebook $self->param('pb' => new Class::Phrasebook(undef, $self->param('phrase +_url')));
I load the correct language in my subroutines.
# phrasebook handle my $pb = $self->param('pb'); $pb->load("SE");
and substitute the variable in my HTML::Template file.
$tmpl->param(1 => $pb->get("1") );
I want it to print out the Swedish word "tävlingar" but I get the following word "tävlingar" I can't get the Swedish letters å,ä and ö to work with Class::PhraseBook. There is something with the encoding of the XML file that I am missing. I seems like Class::PhraseBook have already decided what encoding to use. Anybody have a solution?

Replies are listed 'Best First'.
Re: can't get å,ä and ö to work with Class::PhraseBook
by graff (Chancellor) on Mar 13, 2006 at 00:05 UTC
    Based on your updated post (thanks for the added details -- that helps), it looks like you are trying to use ISO-8859-1 in your xml data file of phrase translations, and one step or another in the process is converting these to utf8 for you. (Maybe Class::PhraseBook is doing that, I don't know.)

    It might not be surprising that the conversion to utf8 is happening -- it makes things easier for multi-language text processing, in general. If you want to make sure that your final output reverts back to 8859-1, you'll probably want to use a PerlIO encoding layer on STDOUT -- like this:

    binmode STDOUT, ":encoding(iso-8859-1)";
    Do that before you start printing any page content. (update: and hope that some clever module doesn't reset it to ":utf8" for you later on)

    Alternatively, you could just "go with the flow", have your page content written as utf8 text, and change your browser to use utf8 instead of 8859-1 -- probably no code-changes needed at all if you do it that way.

    (update: when I set my browser to use utf8, the OP shows the correct character in the example that the OP says is "wrong")

      No, graff, you have the encodings the wrong way around.

      boboson, you have UTF-8 in the XML file, and it is wrongly treated as 8859-1. Ã is symptomatic for this common Unicode mess-up. You have to tell the user agent (web browser) that you deliver content in UTF-8:

      $webapp->header_add( -type => 'text/html; charset=utf-8' );

        Thanks! now I am back on track!
        I thought I was back on track, but implementing your suggestion just gave me some other problems.
        It now works with the text from the XML file, but the rest of the webpage text now looks something like this:
        Om nŠ­n av de obligatoriska uppgifterna inte visar sig st&#19309;a och + du inte r&#19764;ar till detta p¶Âppmaning fr³èoss sˆîommer ditt kon +to att raderas.
        I know I can get rid of these strange signs by using "& aring;" = å "& auml;" = ä and "& ouml;" = ö, but there must be some other way around all this? Is there a way to put codes for å, ä and ö in the XML file? or is there any other solution?
Re: can't get å,ä and ö to work with Class::PhraseBook
by Aristotle (Chancellor) on Mar 12, 2006 at 22:15 UTC

    Without you giving any data or code samples, no. See How (Not) To Ask A Question. I’d like to help, but I have no idea what to suggest based on the little you’ve told us.

    Makeshifts last the longest.

      Sorry, I have now updated my question!