It gets even worse once you start accepting responses with user input, as
you cannot easily control what encoding they are in, and there is no way
(thanks to browsers not implementing standards) to safely know what encoding
the request should be read in. This is my strategy:
1) I make sure and have this tag in my html: <meta http-equiv="content-type"
content="text/html; charset=UTF-8">
2) Somehow, this didn't do it for me completely with frames (I don't know
why!), so I also set the encoding using JavaScript:
function setEncoding(){// called when the frameset loads
        document.charset="UTF-8";
        for(i = 0; i < frames.length; i++){
                try{frames[i].document.charset="utf-8";}
                catch(e){}
        }
}

3) I mangle all user input before sending it to the server (see method at
end of post).
4) I make sure that this gets called somewhere on the request object:
req.setCharacterEncoding("UTF-8");// or UTF8, can't remember
5) I make sure that Velocity gets initialized with the right encoding:
Velocity.getTemplate(vm.getName(), "UTF8").merge(context, writer);
6) make sure that your resource files are UTF-8 and don't have any system
dependent line breaks.

I don't know if any of that is overkill, and I don't know what I'd have to
do to support Russian or Japanese. I'd be eager to hear if other's can
reduce that to maybe two failsafe steps. I'm just glad it works. I think I
had a hard time finding literature on the net that really addressed my needs
when I was writing all this. There was plenty of literature talking about
encodings, but I had to come to the solution described above with, like you
said, many days of head banging.

-Robert Douglass


function mangle(text){ // text is user input
        var mangleArray = {
                '%C0':'%26Agrave%3B',
                '%E0':'%26agrave%3B',
                '%C1':'%26Aacute%3B',
                '%E1':'%26aacute%3B',
                '%C2':'%26Acirc%3B',
                '%E2':'%26acirc%3B',
                '%C3':'%26Atilde%3B',
                '%E3':'%26atilde%3B',
                '%C4':'%26Auml%3B',
                '%E4':'%26auml%3B',
                '%C5':'%26Aring%3B',
                '%E5':'%26aring%3B',
                '%C6':'%26AElig%3B',
                '%E6':'%26aelig%3B',
                '%C7':'%26Ccedil%3B',
                '%E7':'%26ccedil%3B',
                '%D0':'%26ETH%3B',
                '%F0':'%26eth%3B',
                '%C8':'%26Egrave%3B',
                '%E8':'%26egrave%3B',
                '%C9':'%26Eacute%3B',
                '%E9':'%26eacute%3B',
                '%CA':'%26Ecirc%3B',
                '%EA':'%26ecirc%3B',
                '%CB':'%26Euml%3B',
                '%EB':'%26euml%3B',
                '%CC':'%26Igrave%3B',
                '%EC':'%26igrave%3B',
                '%CD':'%26Iacute%3B',
                '%ED':'%26iacute%3B',
                '%CE':'%26Icirc%3B',
                '%EE':'%26icirc%3B',
                '%CF':'%26Iuml%3B',
                '%EF':'%26iuml%3B',
                '%B5':'%26micro%3B',
                '%D1':'%26Ntilde%3B',
                '%F1':'%26ntilde%3B',
                '%D2':'%26Ograve%3B',
                '%F2':'%26ograve%3B',
                '%D3':'%26Oacute%3B',
                '%F3':'%26oacute%3B',
                '%D4':'%26Ocirc%3B',
                '%F4':'%26ocirc%3B',
                '%D5':'%26Otilde%3B',
                '%F5':'%26otilde%3B',
                '%D6':'%26Ouml%3B',
                '%F6':'%26ouml%3B',
                '%D8':'%26Oslash%3B',
                '%F8':'%26oslash%3B',
                '%DF':'%26szlig%3B',
                '%DE':'%26THORN%3B',
                '%FE':'%26thorn%3B',
                '%D9':'%26Ugrave%3B',
                '%F9':'%26ugrave%3B',
                '%DA':'%26Uacute%3B',
                '%FA':'%26uacute%3B',
                '%DB':'%26Ucirc%3B',
                '%FB':'%26ucirc%3B',
                '%DC':'%26Uuml%3B',
                '%FC':'%26uuml%3B',
                '%DD':'%26Yacute%3B',
                '%FD':'%26yacute%3B',
                '%FF':'%26yuml%3B',
                '%A8':'%26uml%3B',
                '%AF':'%26macr%3B',
                '%B4':'%26acute%3B',
                '%B8':'%26cedil%3B',
                '%A1':'%26iexcl%3B',
                '%BF':'%26iquest%3B',
                '%B7':'%26middot%3B',
                '%A6':'%26brvbar%3B',
                '%AB':'%26laquo%3B',
                '%BB':'%26raquo%3B',
                '%B6':'%26para%3B',
                '%A7':'%26sect%3B',
                '%A9':'%26copy%3B',
                '%AE':'%26reg%3B',
                '%B9':'%26sup1%3B',
                '%B2':'%26sup2%3B',
                '%B3':'%26sup3%3B',
                '%AD':'%26shy%3B',
                '%D7':'%26times%3B',
                '%F7':'%26divide%3B',
                '%BC':'%26frac14%3B',
                '%BD':'%26frac12%3B',
                '%BE':'%26frac34%3B',
                '%AA':'%26ordf%3B',
                '%BA':'%26ordm%3B',
                '%AC':'%26not%3B',
                '%B0':'%26deg%3B',
                '%B1':'%26plusmn%3B',
                '%A4':'%26curren%3B',
                '%A2':'%26cent%3B',
                '%A3':'%26pound%3B',
                '%A5':'%26yen%3B',
                '%u0192':'%26fnof%3B',
                '%u0152':'%26OElig%3B',
                '%u0153':'%26oelig%3B',
                '%u0160':'%26Scaron%3B',
                '%u0161':'%26scaron%3B',
                '%u0178':'%26Yuml%3B',
                '%u02C6':'%26circ%3B',
                '%u02DC':'%26tilde%3B',
                '%u2013':'%26ndash%3B',
                '%u2014':'%26mdash%3B',
                '%u2020':'%26dagger%3B',
                '%u2021':'%26Dagger%3B',
                '%u2022':'%26bull%3B',
                '%u2026':'%26hellip%3B',
                '%u2018':'%26lsquo%3B',
                '%u2019':'%26rsquo%3B',
                '%u201C':'%26ldquo%3B',
                '%u201D':'%26rdquo%3B',
                '%u2039':'%26lsaquo%3B',
                '%u203A':'%26rsaquo%3B',
                '%u2122':'%26trade%3B',
                '%u2030':'%26permil%3B'};

        text = text.replace(/€/gm, '&euro;');
        text = escape(text);
        //alert('before:'+text);
        for(var find in mangleArray){
                var re = new RegExp(find, 'gm');
                text = text.replace(re, mangleArray[find]);
        }
        //alert('after:'+text);
        text = unescape(text);
        return text;
}



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of
James Pan
Sent: Wednesday, October 15, 2003 7:58 PM
To: [EMAIL PROTECTED]
Subject: [OS-webwork] Newbie: internationalization for Russian


Hi,

I'm trying to create a page that can be in multiple languages, namely
English, Dutch, Russian, and Japanese.

The resource bundles for them are all in the correct languages, and since
I'm working on Windows, I saved them in Notepad as unicode.

MyAction.properties
MyAction_ru.properties
MyAction_jp.properties
MyAction_nl.properties


Now, English and Dutch display fine, but whenever I switch to Russian, I
have to manually change the browser's encoding to "UTF-8" (and even this
doesn't display my russian text correctly, coming up with squares between
Russian characters).

I ran into this problem before with Japanese, and the solution was to put

<%@ page contentType="text/html; charset=Shift-JIS"%>

at the first line of my JSP page.

Now, since this application is to be in different languages all the time, I
can't do this. I instead need something like:

<%@ page contentType="text/html; charset=<webwork:text
name="'current.encoding'" />"%>

Which obviously doesn't work. And I've been banging my head for almost two
days now for this encoding thing... does anyone have any suggestions??

Thank you very much!

James





-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
_______________________________________________
Opensymphony-webwork mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork



-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
_______________________________________________
Opensymphony-webwork mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork

Reply via email to