GR problem for Chinese

007pig

Joined: 2004-06-28
Posts: 5
Posted: Mon, 2004-06-28 19:05

There's a problem when list albums. The Chinese chars doesn't display correctly.
After looking into the code, i find that GR phrases albums info by java.util.Properties class. it only accepts "unicode escapes" not the chinese default encoding "GB2312" or even "UTF-8".

"When saving properties to a stream or loading them from a stream, the ISO 8859-1 character encoding is used. For characters that cannot be directly represented in this encoding, Unicode escapes are used; however, only a single 'u' character is allowed in an escape sequence. The native2ascii tool can be used to convert property files to and from other character encodings. "

In J2SDK lib/tools.jar, there's a class sun.tools.native2ascii.Main can convert "GB2312" to "unicode escapes" but i'm not a java master so i don't know how to.
Would you please try to find a way to solve the problem? thank you.

AttachmentSize
temp.jpg7.54 KB
Login or register to post comments
paour
paour's picture

Joined: 2002-08-14
Posts: 1478
Posted: Mon, 2004-06-28 20:31

GR 1.4 correctly displays album names if they are encoded using HTML entities. Using HTML entities is the only way people who browse to your Gallery will be able to see the albums correctly without having to explicitly set the codepage in their browsers, anyway.

Recent versions of Gallery automatically use HTML entities for non-ASCII characters when an album is created.

Login or register to post comments
007pig

Joined: 2004-06-28
Posts: 5
Posted: Tue, 2004-06-29 03:43
Quote:
Recent versions of Gallery automatically use HTML entities for non-ASCII characters when an album is created.

Which version? Gallery 1 or 2? can i get it from cvs and merge it to Gallery 1.4.3?

Login or register to post comments
paour
paour's picture

Joined: 2002-08-14
Posts: 1478
Posted: Tue, 2004-06-29 05:40

It's Gallery 1.4.4-beta, which you can get from the nightlies site.

Login or register to post comments
007pig

Joined: 2004-06-28
Posts: 5
Posted: Tue, 2004-06-29 09:21

thank you. i'll have a try.

Login or register to post comments
007pig

Joined: 2004-06-28
Posts: 5
Posted: Sun, 2004-07-11 09:10

I have installed gallery 1.4.4 RC1 and gallery remote 1.4-RC1. The problem still exists?

Login or register to post comments
007pig

Joined: 2004-06-28
Posts: 5
Posted: Sun, 2004-07-11 12:43

Hi, i got it.
Here's how i did:

in GalleryComm2.java, add a new method called getEscapeString():

	static String getEscapeString(String str) {
        if (str == null) {
            return null;
        }
        char[] bys = new char[str.length()];
        str.getChars(0, str.length(), bys, 0);
        StringBuffer ttsb = new StringBuffer();
        for (int k = 0; k < bys.length; k++) {
            switch (bys[k]) {
                case '\\':
                case '\'':
                case '\"':
                    ttsb.append("\\");
                    ttsb.append( (char) bys[k]);
                    break;
                case '\r':
                    ttsb.append("\r");
                    break;
                case '\n':
                    ttsb.append("\n");
                    break;
                case '\t':
                    ttsb.append("\t");
                    break;
                default:
                    if (bys[k] < ' ' || bys[k] >= '\200') {
                        //System.out.println("unicode...");
                        ttsb.append("\\u" /*243*/);
                        String s13 = Integer.toHexString(bys[k]);
                        for (int l = s13.length(); l < 4; l++) {
                            ttsb.append('0');
                        }
                        ttsb.append(s13);
                    } else {
                        ttsb.append( (char) bys[k]);
                    }
            }
        }
        return ttsb.toString();
    }

modify requestResponse() method:
From:
p.load(new StringBufferInputStream(response));
To:
p.load(new StringBufferInputStream(getEscapeString(response)));

And i attached the correct screenshot:

AttachmentSize
temp.jpg5.66 KB
Login or register to post comments
paour
paour's picture

Joined: 2002-08-14
Posts: 1478
Posted: Mon, 2004-07-12 14:52

I guess that wouldn't hurt, I'll add it to the first betas of GR 1.5. Thanks.

Login or register to post comments