[Zope] The date in Dutch

Steve Alexander steve@cat-box.net
Fri, 18 Aug 2000 09:59:15 +0100


Michel Houben wrote:
> How can I fix the date in Dutch, for example Donderdag 17 Augustus 2000 
> instead of Thursday 17 August 2000. I hope someone can solve this problem.

I don't know any Dutch.

However, here's an external method that will convert the months and days
of the week in a string from English to German.

There are probably better names for the variables and such, so don't
take this as as example of clear maintainable programming :)

It ought be be pretty efficient.

Assuming you call the external method D_date, use something like this:

  <dtml-var "D_date('October February July, Tuesday, 23 March 2000')">

----
import re

# you can remove lines where the words are the same in both languages
replacements={
    'Monday':'Montag',
    'Tuesday':'Dienstag',
    'Wednesday':'Mittwoch',
    'Thursday':'Donnerstag',
    'Friday':'Freitag',
    'Saturday':'Samstag',
    'Sunday':'Sonntag',
    'January':'Januar',
    'February':'Februar',
    'March':'M&auml;rz',
    'April':'April',
    'May':'Mai',
    'June':'Juni',
    'July':'Juli',
    'August':'Augustus',
    'September':'September',
    'October':'Oktober',
    'November':'November',
    'December':'Dezember'
    }

class re_stored:
  def __init__(self, e, d):
    self.d = d
    self.regex=re.compile(e)
    
  def r(self, s):
    return self.regex.sub(self.d, s)

replace_regexes=[]
for e,d in replacements.items():
    replace_regexes.append(re_stored(e,d))
   

def D_date(datestring):
    return reduce(lambda x,y: y.r(x), replace_regexes, datestring)
----

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net