开发者

tcl utf-8 characters not displaying properly in ui

Objective : To have multi language characters in the user id in Enovia v开发者_C百科6

I am using utf-8 encoding in tcl script and it seems it saves multi language characters properly in the database (after some conversion). But, in ui i literally see the saved information from the database.

While doing the same excercise throuhg Power Web, saved data somehow gets converted back into proper multi language character and displays properly.

Am i missing something while taking tcl approach?

Pasting one example to help understand better.

Original Name: Kátai-Pál Name saved in database as: Kátai-Pál In UI I see name as: Kátai-Pál

In Tcl I use below syntax set encoded [encoding convertto utf-8 Kátai-Pál]; Now user name becomes: Kátai-Pál In UI I see name as “Kátai-Pál”


The trick is to think in terms of characters, not bytes. They're different things. Encodings are ways of representing characters as byte sequences (internally, Tcl's really quite complicated, but you shouldn't ever have to care about that if you're not developing Tcl's implementation itself; suffice to say it's Unicode). Thus, when you use:

encoding convertto utf-8 "Kátai-Pál"

You're taking a sequence of characters and asking for the sequence of bytes (one per result character) that is the encoding of those characters in the given encoding (UTF-8).

What you need to do is to get the database integration layer to understand what encoding the database is using so it can convert back into characters for you (you can only ever communicate using bytes; everything else is just a simplification). There are two ways that can happen: either the information is correctly shared (via metadata or defined convention), or both sides make assumptions which come unstuck occasionally. It sounds like the latter is what's happening, alas.

If you can't handle it any other way, you can take the bytes produced out of the database layer and convert into characters:

encoding convertfrom $theEncoding $theBytes

Working out what $theEncoding should be is in general very tricky, but it sounds like it's utf-8 for you. Once you've got characters, Tcl/Tk will be able to display them correctly; it knows how to transfer them correctly into the guts of the platform's GUI. (And in scripts that you actually write, you're best off replacing non-ASCII characters with their \uXXXX escapes, because platforms don't agree on what encoding is right to use for scripts. Alas.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜