On Wed, 21 Oct 2009 at 04:46PM +0900, Dan Drake wrote:
> I was inspired by the Korean translation of the notebook to try and
> get internationalization (i18n) support into the notebook.
> 
> I got a good start on figuring out what to do, but I'm a bit stuck and
> I need some help. I have some stuff working, but right now, utf-8
> strings in the notebook don't work and I'm not sure what's wrong.
> 
> If you'd like to work on this, you can download the tarball at
> http://sagenb.kaist.ac.kr/~drake/sagenb-with-gettext.tar.bz2 and use
> it to replace $SAGE_ROOT/local/lib/python/site-packages/sagenb. You'll
> need 4.2.alpha0 or 4.1.2 with Jinja2 installed. Then run the notebook
> and try things until something breaks. The above tarball is just a
> rough draft, really just messing around to see how to get stuff
> working, so my modifications are a bit random and messy.

William asked me to post a bit more about what goes wrong. If you grab
the above tarball and drop it into the site-packages directory, you
should be able to run the notebook as usual. You'll notice some new bits
on the front notebook page -- those are translated strings that are
getting correctly pulled in via gettext. Log into the notebook as usual,
and you'll see the "sign out" string is also "translated".

The problem occurs when you try to print non-ascii text in a worksheet.
If you open a worksheet and execute a cell like

    print 'Français'

the server either gets stuck in an infinite loop, or just won't render
the page. The traceback looks something like this:

          File 
"/scratch/drake/sage-4.2.alpha0-x86_64-Linux/local/lib/python2.6/site-packages/sagenb/notebook/twist.py",
 line 1469, in render
            self.worksheet.sage()
          File 
"/scratch/drake/sage-4.2.alpha0-x86_64-Linux/local/lib/python2.6/site-packages/sagenb/notebook/worksheet.py",
 line 2933, in sage
            self.initialize_sage()
          File 
"/scratch/drake/sage-4.2.alpha0-x86_64-Linux/local/lib/python2.6/site-packages/sagenb/notebook/worksheet.py",
 line 2911, in initialize_sage
            self._enqueue_auto_cells()
          File 
"/scratch/drake/sage-4.2.alpha0-x86_64-Linux/local/lib/python2.6/site-packages/sagenb/notebook/worksheet.py",
 line 3337, in _enqueue_auto_cells
            for c in self.cell_list():
          File 
"/scratch/drake/sage-4.2.alpha0-x86_64-Linux/local/lib/python2.6/site-packages/sagenb/notebook/worksheet.py",
 line 2651, in cell_list
            self.set_body(open(worksheet_html).read())
          File 
"/scratch/drake/sage-4.2.alpha0-x86_64-Linux/local/lib/python2.6/site-packages/sagenb/notebook/worksheet.py",
 line 2137, in set_body
            self.edit_save(body)
          File 
"/scratch/drake/sage-4.2.alpha0-x86_64-Linux/local/lib/python2.6/site-packages/sagenb/notebook/worksheet.py",
 line 2279, in edit_save
            C.set_output_text(output, '')
          File 
"/scratch/drake/sage-4.2.alpha0-x86_64-Linux/local/lib/python2.6/site-packages/sagenb/notebook/cell.py",
 line 1348, in set_output_text
            self.__out = unicode(output)
        exceptions.UnicodeDecodeError: 'ascii' codec can't decode byte 0xed in 
position 1: ordinal not in range(128)

I've messed around in cell.py, trying to get all the strings to be
Unicode objects, but haven't met with any success. In the regular
notebook, I get no trouble with things like "print 'Français'", so
something about the gettext'ed code is wonky, but I'm not sure what.

If you want to work on this, the Sage tree in
/scratch/drake/sage-4.2.alpha0-x86_64-Linux on sage.math has my changes
in it.

Thanks for any help,

Dan

-- 
---  Dan Drake
-----  http://mathsci.kaist.ac.kr/~drake
-------

Attachment: signature.asc
Description: Digital signature

Reply via email to