hamster-applet r664 - trunk/hamster



Author: tbaugis
Date: Thu Dec 18 09:32:46 2008
New Revision: 664
URL: http://svn.gnome.org/viewvc/hamster-applet?rev=664&view=rev

Log:
some magic for Japanese locale (Takao Fujiwara ).  Fixes bug 562298

Modified:
   trunk/hamster/reports.py
   trunk/hamster/stats.py
   trunk/hamster/stuff.py

Modified: trunk/hamster/reports.py
==============================================================================
--- trunk/hamster/reports.py	(original)
+++ trunk/hamster/reports.py	Thu Dec 18 09:32:46 2008
@@ -40,6 +40,7 @@
     
 
     report_path = os.path.join(os.path.expanduser("~"), "%s.html" % title)
+    report_path = stuff.locale_from_utf8(report_path)
     report = open(report_path, "w")    
     report.write("""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>

Modified: trunk/hamster/stats.py
==============================================================================
--- trunk/hamster/stats.py	(original)
+++ trunk/hamster/stats.py	Thu Dec 18 09:32:46 2008
@@ -236,7 +236,7 @@
             self.fact_store.set_value(by_day[day]["row_pointer"], 2,
                 stuff.format_duration(by_day[day]["duration"]))
             if (self.end_date - self.start_date).days < 20:
-                strday = day.strftime('%a')
+                strday = stuff.locale_to_utf8(day.strftime('%a'))
                 totals["by_day"].append([strday, by_day[day]["duration"] / 60.0, None, None, day])
             else:
                 # date format in month chart in overview window (click on "month" to see it)

Modified: trunk/hamster/stuff.py
==============================================================================
--- trunk/hamster/stuff.py	(original)
+++ trunk/hamster/stuff.py	Thu Dec 18 09:32:46 2008
@@ -27,6 +27,24 @@
 from pango import ELLIPSIZE_END
 
 import datetime as dt
+import locale
+
+# it seems that python or something has bug of sorts, that breaks stuff for
+# japanese locale, so we have this locale from and to ut8 magic in some places
+# see bug 562298
+def locale_from_utf8(utf8_str):
+    try:
+        retval = unicode (utf8_str, "utf-8").encode(locale.getpreferredencoding())
+    except:
+        retval = utf8_str
+    return retval
+
+def locale_to_utf8(locale_str):
+    try:
+        retval = unicode (locale_str, locale.getpreferredencoding()).encode("utf-8")
+    except:
+        retval = locale_str
+    return retval
 
 class CategoryCell(gtk.CellRendererText):
     def __init__(self):
@@ -92,6 +110,9 @@
     res[prefix+"Y"] = date.strftime("%Y")
     res[prefix+"Z"] = date.strftime("%Z")
     
+    for i, value in res.items():
+        res[i] = locale_to_utf8(value)
+
     return res
 
 class DayStore(object):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]