[Zope] RE: Help with Japanese rendering in Zope...?

Small Business Services toolkit at magma.ca
Wed Dec 10 22:43:50 EST 2003


kiruI have a relatively short chunk of dtml code that we used to test chinese characters.  I know this works for chinese character display, so maybe you could modify it for testing Japanese character display

*** code start ***

<html>
<head>
 <meta http-equiv="content-type" content="text/html;charset=gb2312">
 <style type="text/css">
<!--
.heading {background-color: white; color: black; font-size: 15px; font-weight: bold}
.number {background-color: white; color: black; font-size: 15px}
.symbol {background-color: white; color: black; font-size: 22px}
-->
 </style>
</head>

<body>
<br><br>
<center>
<b>
<table border="1" cellpadding="2">
  <tr>
    <td class="heading">Code</td>
    <td class="heading">Symbol</td>
    <td>&nbsp;</td>
    <td class="heading">Code</td>
    <td class="heading">Symbol</td>
    <td>&nbsp;</td>
    <td class="heading">Code</td>
    <td class="heading">Symbol</td>
    <td>&nbsp;</td>
    <td class="heading">Code</td>
    <td class="heading">Symbol</td>
    <td>&nbsp;</td>
    <td class="heading">Code</td>
    <td class="heading">Symbol</td>
  </tr>

  <dtml-in "_.range(19968, 20000, 5)">
   <tr>
    <td class="number"><dtml-var sequence-item></td>
    <td class="symbol" align="center">&#<dtml-var sequence-item>;</td>

    <td>&nbsp;</td>

    <td class="number"><dtml-var "_.int(_['sequence-item'])+1"></td>
    <td class="symbol" align="center">&#<dtml-var "_.int(_['sequence-item'])+1">;</td>

    <td>&nbsp;</td>

    <td class="number"><dtml-var "_.int(_['sequence-item'])+2"></td>
    <td class="symbol" align="center">&#<dtml-var "_.int(_['sequence-item'])+2">;</td>

    <td>&nbsp;</td>

    <td class="number"><dtml-var "_.int(_['sequence-item'])+3"></td>
    <td class="symbol" align="center">&#<dtml-var "_.int(_['sequence-item'])+3">;</td>

    <td>&nbsp;</td>

    <td class="number"><dtml-var "_.int(_['sequence-item'])+4"></td>
    <td class="symbol" align="center">&#<dtml-var "_.int(_['sequence-item'])+4">;</td>
   </tr>
  </dtml-in>

  <dtml-in "_.range(20003, 20500, 5)">
   <tr>
    <td class="number"><dtml-var sequence-item></td>
    <td class="symbol" align="center">&#<dtml-var sequence-item>;</td>

    <td>&nbsp;</td>

    <td class="number"><dtml-var "_.int(_['sequence-item'])+1"></td>
    <td class="symbol" align="center">&#<dtml-var "_.int(_['sequence-item'])+1">;</td>

    <td>&nbsp;</td>

    <td class="number"><dtml-var "_.int(_['sequence-item'])+2"></td>
    <td class="symbol" align="center">&#<dtml-var "_.int(_['sequence-item'])+2">;</td>

    <td>&nbsp;</td>

    <td class="number"><dtml-var "_.int(_['sequence-item'])+3"></td>
    <td class="symbol" align="center">&#<dtml-var "_.int(_['sequence-item'])+3">;</td>

    <td>&nbsp;</td>

    <td class="number"><dtml-var "_.int(_['sequence-item'])+4"></td>
    <td class="symbol" align="center">&#<dtml-var "_.int(_['sequence-item'])+4">;</td>
   </tr>
  </dtml-in>

  <dtml-in "_.range(20503, 21000, 5)">
   <tr>
    <td class="number"><dtml-var sequence-item></td>
    <td class="symbol" align="center">&#<dtml-var sequence-item>;</td>

    <td>&nbsp;</td>

    <td class="number"><dtml-var "_.int(_['sequence-item'])+1"></td>
    <td class="symbol" align="center">&#<dtml-var "_.int(_['sequence-item'])+1">;</td>

    <td>&nbsp;</td>

    <td class="number"><dtml-var "_.int(_['sequence-item'])+2"></td>
    <td class="symbol" align="center">&#<dtml-var "_.int(_['sequence-item'])+2">;</td>

    <td>&nbsp;</td>

    <td class="number"><dtml-var "_.int(_['sequence-item'])+3"></td>
    <td class="symbol" align="center">&#<dtml-var "_.int(_['sequence-item'])+3">;</td>

    <td>&nbsp;</td>

    <td class="number"><dtml-var "_.int(_['sequence-item'])+4"></td>
    <td class="symbol" align="center">&#<dtml-var "_.int(_['sequence-item'])+4">;</td>
   </tr>
  </dtml-in>
</font>
</table>
<br>
</b>
</center>
<dtml-var standard_html_footer>

*** code end ***


HTH

Jonathan
  ----- Original Message ----- 
  From: Erik Anderson 
  To: bjorn at stabell.name 
  Cc: zope at zope.org 
  Sent: December 10, 2003 9:43 PM
  Subject: [Zope] RE: Help with Japanese rendering in Zope...?


  Hey there Bjorn -- 

  Finally found the time to try out dump_obj, and it's showing me that
  everything *should* be stored correctly in Unicode.  Furthermore, the
  properties page itself (sample attached) does correctly identify the
  input as UTF-8.  However, the results of my simple dtml method still
  show question marks, even when I look at the source of the generated
  page (attached, along with the results of dump_obj).  

  Given that the dtml-method result page *source* shows question marks in
  place of proper Japanese, it suggests to me that something isn't
  returning properly.  Perhaps some intermediary function is not
  Unicode-aware and fills in the non-ascii chars with question marks?

  Thanks too for your Plone suggestion.  I'm wading through the Plone and
  Archetype documentation, but it's a bit thin on the right kind of
  detail for a Plone/Zope newbie like me.  I appreciate your time in
  helping me out.  

  Cheers,

          Erik Anderson

  --- Bjorn Stabell <bjorn at stabell.name> wrote:
  > Hi Erik,
  > 
  > I'd recommend you get and install Plone+CMF+Zope from plone.org
  > instead
  > of trying to find all the correct products of the right versions
  > yourself.
  > 
  > As for your problem displaying Japanese characters, it does sound
  > like
  > you're running into a unicode encoding/decoding problem.
  > 
  > If your properties are stored as unicode, Zope will automatically
  > encode
  > them in the output character encoding (in your case, this seems to be
  > UTF-8).
  > 
  > Getting the input from your form decoded propertly takes a bit more
  > work, though.  Make sure all HTML text field names have :ustring:utf8
  > (or uline, utokens, or utext) appended to them, e.g.,
  > 
  >    <input type="text" name="title:ustring:utf8">
  > 
  > Zope will look at the name of the field when guessing at which
  > character
  > encoding the text is in, and then decode it into a unicode string
  > (which
  > is stored using Python's internal encoding).  This type of string
  > will
  > be of type "ustring".
  > 
  > To double-check that your strings are really stored as ustrings (they
  > will look like u"hello", not "hello"), install and run the attached
  > dump_obj external method on your object.
  > 
  > If this discussion continues, let's move this discussion to the Zope
  > list (zope at zope.org) so that it gets archived and others can learn
  > from
  > it and help with it as well.
  > 
  > Bye,
  > -- 
  > Bjorn
  > 

  > ATTACHMENT part 2 message/rfc822 
  > From: "Admin-Unix2" <admin at exoweb.net>
  > To: "Bjorn Stabell" <bjorn at exoweb.net>
  > Date: Thu, 4 Dec 2003 14:12:59 +0800
  > 
  > # TODO:
  > # - editing interface (open new window for each property)
  > # - also list functions
  > # - searching/ filtering
  > # - collapse/ expand (dynamically load)
  > # - include size information
  > # - include cache information (ghosted or active)
  > #
  > # IDEAS:
  > # - add debug to URL to have execution traced in a separate window,
  > e.g.,
  > # .../debug/login_form
  > 
  > from DocumentTemplate.html_quote import html_quote
  > 
  > def dump_obj(self, depth=10):
  > #
  > # don't go too deep
  > #
  > if depth<0: return `self`
  > out = ""
  > 
  > #
  > # images; also show them
  > #
  > if hasattr(self, 'tag'):
  > out += '<IMG SRC="'+self.getId()+'" style="float:
  > right;"/>'
  >         #return self.tag(self)  TODO: acquisition doesn't work?
  > # files TODO: add link for downloading
  > 
  > #
  > # list-like types
  > #
  > if type(self) in [type([]), type(())]:
  > out += "\n"
  > for item in self:
  > out += "<DIV style='border-top: solid #cccccc
  > 1px;'>"+dump_obj(item)+"</DIV>"
  > return out
  > 
  > #
  > # dictionary-like types (including objects)
  > #
  > d = {}
  > if type(self) is type({}): # dictionaries
  > d = self
  > elif hasattr(self, '__dict__'): # objects
  > d = self.__dict__
  > if d:
  > out += "<TABLE>\n"
  > for key,val in d.items():
  > out += "<TR>"
  > out += "<TH align=left valign=top>"
  > out += "<a
  > title=\""+html_quote(str(type(val)))+"\">"+str(key)+"</a>"
  > out += "</TH>"
  > out += "<TD valign=top style='border: solid
  > #669966 1px;'>"
  > if type(d) is type({}):
  > out += dump_obj(val, depth-1)
  > else:
  > out += dump_obj(getattr(d, key),
  > depth-1)
  > out += "</TD></TR>\n"
  > out += "</TABLE>\n"
  > return out
  > 
  > #
  > # basic types
  > #
  > s = `self`
  > if len(s) > 400:
  > out += html_quote(s[:400])+'<b style="color:
  > #cc3300;">...</b>'
  > else:
  > out += html_quote(s)
  > return out
  >


------------------------------------------------------------------------------


  kiru
  ??

  ?? descendants are:




------------------------------------------------------------------------------


        Â Â    
                  
         Contents   Properties   View  
         
         

         Glossary Term Template at  /Testing/kiru/propertysheets/TermProperties  

  Properties allow you to assign simple values to Zope objects. To change property values, edit the values and click "Save Changes". 

        Â   Name  Value  Type  
       Romaji    ustring  
       Kana    ustring  
       Ancestors  No value for .  multiple selection  
       Descendants  No value for .  multiple selection  
        Â    Â  



------------------------------------------------------------------------------


        Kana u'\u5207\u308b' 
        id 'kiru' 
        __ac_local_roles__ admin 'Owner' 
       
        kiru-1.1 id 'kiru-1.1' 
              __ac_local_roles__ admin 'Owner' 
             
       
        _objects meta_type 'Glossary Term Kanji' 
              id 'kiru-1.1' 
       
        Descendants '' 
        Romaji u'kiru' 
        Ancestors '' 
        _owner 'acl_users'
        'admin' 



------------------------------------------------------------------------------


  _______________________________________________
  Zope maillist  -  Zope at zope.org
  http://mail.zope.org/mailman/listinfo/zope
  **   No cross posts or HTML encoding!  **
  (Related lists - 
   http://mail.zope.org/mailman/listinfo/zope-announce
   http://mail.zope.org/mailman/listinfo/zope-dev )

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope/attachments/20031210/ddc48f05/attachment.html


More information about the Zope mailing list