Edgewall Software
Modify

Opened 19 years ago

Closed 18 years ago

Last modified 18 years ago

#2186 closed enhancement (fixed)

japanese environment on windows

Reported by: masaaki.naito@… Owned by: daniel
Priority: normal Milestone: 0.10
Component: admin/console Version: 0.9b2
Severity: normal Keywords: unicode
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

I install trac on windows 2000 and use japanese. But I can't use japanese in some components.

In trac-admin, I add component in japanese. but japanese component name can't show in component list.

So I change admin.py and util.py for show japanese.

Here is patch

Index: util.py =================================================================== —- util.py (revision 2328) +++ util.py (working copy) @@ -80,6 +80,22 @@

u = unicode(text, 'iso-8859-15')

return u.encode('utf-8')

+def from_utf8(text, charset='iso-8859-15'): + """Convert a string from UTF-8, assuming the encoding is either UTF-8, ISO + Latin-1, or as specified by the optional charset parameter.""" + try: + # Do nothing if it's already utf-8 + u = unicode(text, 'utf-8') + return u.encode(charset) + except UnicodeError: + try: + # Use the user supplied charset if possible + u = unicode(text, charset) + except UnicodeError: + # This should always work + u = unicode(text, 'iso-8859-15') + return u.encode(charset) +

def sql_escape(text):

""" Escapes the given string so that it can be safely used in an SQL

Attachments (0)

Change History (5)

comment:1 by anonymous, 19 years ago

Component: generaltrac-admin
Owner: changed from Jonas Borgström to daniel
Version: 0.8.40.9b2

comment:2 by anonymous, 19 years ago

Index: util.py
===================================================================
--- util.py     (revision 2328)
+++ util.py     (working copy)
@@ -80,6 +80,22 @@
             u = unicode(text, 'iso-8859-15')
         return u.encode('utf-8')

+def from_utf8(text, charset='iso-8859-15'):
+    """Convert a string from UTF-8, assuming the encoding is either UTF-8, ISO
+    Latin-1, or as specified by the optional `charset` arameter."""
+    try:
+        # Do nothing if it's already utf-8
+        u = unicode(text, 'utf-8')
+        return u.encode(charset)
+    except UnicodeError:
+        try:
+            # Use the user supplied charset if possible
+            u = unicode(text, charset)
+        except UnicodeError:
+            # This should always work
+            u = unicode(text, 'iso-8859-15')
+        return u.encode(charset)
+
 def sql_escape(text):
     """
     Escapes the given string so that it can be safely used in an SQL


Index: scripts/admin.py
===================================================================
--- scripts/admin.py    (revision 2328)
+++ scripts/admin.py    (working copy)
@@ -190,7 +190,7 @@
                 if cnum + 1 == ncols:
                     sp = '' # No separator after last column
                 print ('%%-%ds%s' % (colw[cnum], sp)) \
-                      % (ldata[rnum][cnum] or ''),
+                      % util.from_utf8((ldata[rnum][cnum] or ''), sys.stdin.encoding),
             print
             if rnum == 0 and decor:
                 print ''.join(['-' for x in

comment:3 by anonymous, 19 years ago

Previous patch was not work in wiki functions. I think this is more better.

--- admin.py	(revision 2353)
+++ admin.py	(working copy)
@@ -25,6 +25,7 @@
 import time
 import traceback
 import urllib
+import types
 
 import trac
 from trac import perm, util, db_default
@@ -189,8 +190,13 @@
                     sp = sep
                 if cnum + 1 == ncols:
                     sp = '' # No separator after last column
-                print ('%%-%ds%s' % (colw[cnum], sp)) \
-                      % (ldata[rnum][cnum] or ''),
+                o = ldata[rnum][cnum] or ''
+                if type(o) == types.StringType:
+                  print ('%%-%ds%s' % (colw[cnum], sp)) \
+                        % util.from_utf8((ldata[rnum][cnum] or ''), sys.stdin.encoding),
+                else:
+                  print ('%%-%ds%s' % (colw[cnum], sp)) \
+                        % (ldata[rnum][cnum] or ''),
             print
             if rnum == 0 and decor:
                 print ''.join(['-' for x in

comment:4 by Christian Boos, 18 years ago

Milestone: 0.10
Resolution: fixed
Status: newclosed

sys.stdin.encoding is indeed used in the latest admin.py (r3114).

This should now work as expected here.

comment:5 by Christian Boos, 18 years ago

Keywords: unicode added

(forgot to add the relevant keyword)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain daniel.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from daniel to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.