#2186 closed enhancement (fixed)
japanese environment on windows
| Reported by: | 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 , 20 years ago
| Component: | general → trac-admin |
|---|---|
| Owner: | changed from to |
| Version: | 0.8.4 → 0.9b2 |
comment:2 by , 20 years ago
comment:3 by , 20 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 , 20 years ago
| Milestone: | → 0.10 |
|---|---|
| Resolution: | → fixed |
| Status: | new → closed |
sys.stdin.encoding is indeed used in the latest admin.py (r3114).
This should now work as expected here.



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