Venus Locale Support

Zack . zajmal at hotmail.com
Wed Sep 19 14:23:13 EST 2007


Hi,

I needed locale support for our Urdu Planet (classic Planet version at http=
://www.urduweb.org/planet/). So I dropped in the locale code from Planet 2.=
0 to Venus. It is working for my test installation, but I haven't done any =
extensive testing. Sorry, I don't know how to submit test cases but I am at=
taching the patch I used to add locale support to Venus.

After adding this patch to Venus, locale support should work like it used t=
o with Planet 2.0. Do note that you would have to use the planet:format att=
ribute of atom:updated for the purpose.

I actually don't like this approach because of the way the date and time ar=
e separated from each other in the xslt templates (using comma and space po=
sitioning to do so). This would generally mean that when you change the loc=
ale in your config you might need to edit index.html.xslt as well. Any idea=
s to do this in a better way?

Also, how do I strip all html/xhtml etc. tags from entry:content in Venus?

--
Zack Ajmal
http://www.zackvision.com/weblog/
http://www.urduweb.org/planet/

_________________________________________________________________
More photos; more messages; more whatever =96 Get MORE with Windows Live=99=
 Hotmail=AE. NOW with 5GB storage.
http://imagine-windowslive.com/hotmail/?locale=3Den-us&ocid=3DTXT_TAGHM_mig=
ration_HM_mini_5G_0907
-------------- next part --------------
--- planet/reconstitute.py.old	2007-09-18 20:43:34.000000000 -0700
+++ planet/reconstitute.py	2007-09-18 20:43:34.000000000 -0700
@@ -13,7 +13,7 @@
 Todo:
   * extension elements
 """
-import re, time, md5, sgmllib
+import re, time, md5, sgmllib, locale
 from xml.sax.saxutils import escape
 from xml.dom import minidom, Node
 from html5lib import liberalxmlparser
@@ -224,6 +224,23 @@
 =

 def reconstitute(feed, entry):
     """ create an entry document from a parsed feed """
+    # Define locale
+    # The user can specify more than one locale (separated by ":") as
+    # fallbacks.
+    locale_ok =3D False
+    for user_locale in config.locale().split(':'):
+        user_locale =3D user_locale.strip()
+        try:
+            locale.setlocale(locale.LC_ALL, user_locale)
+        except locale.Error:
+            pass
+        else:
+            locale_ok =3D True
+            break
+    if not locale_ok:
+        print >>sys.stderr, "Unsupported locale setting."
+        sys.exit(1)
+
     xdoc=3Dminidom.parseString('<entry xmlns=3D"http://www.w3.org/2005/Ato=
m"/>\n')
     xentry=3Dxdoc.documentElement
     xentry.setAttribute('xmlns:planet',planet.xmlns)
--- planet/config.py.old	2007-09-18 21:02:52.000000000 -0700
+++ planet/config.py	2007-09-18 20:16:50.000000000 -0700
@@ -26,7 +26,7 @@
   * error handling (example: no planet section)
 """
 =

-import os, sys, re, urllib
+import os, sys, re, urllib, locale
 from ConfigParser import ConfigParser
 from urlparse import urljoin
 =

@@ -105,6 +105,7 @@
     define_planet('output_theme', '')
     define_planet('output_dir', 'output')
     define_planet('spider_threads', 0) =

+    define_planet('locale', locale.setlocale(locale.LC_ALL, ''))
 =

     define_planet_int('new_feed_items', 0) =

     define_planet_int('feed_timeout', 20)


More information about the devel mailing list