From d8b98ca5fbae68a4c15612f59f56cd70b38123df Mon Sep 17 00:00:00 2001 From: Stefan Ritter Date: Wed, 17 Feb 2010 11:16:00 +0100 Subject: Show localized times if locales are generated for this country --- blogthon.cgi | 52 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 14 deletions(-) (limited to 'blogthon.cgi') diff --git a/blogthon.cgi b/blogthon.cgi index c8c5a61..c7ad573 100755 --- a/blogthon.cgi +++ b/blogthon.cgi @@ -16,8 +16,17 @@ # * Complete Atom Feed (like RSS) # * Fix broken charset in outgoing mails (needs some testing) -import cgi, os, time, glob, re, md5, sys, random, smtplib import ConfigParser +import os +import sys +import time +import locale +import re +import cgi +import glob +import md5 +import random +import smtplib # A wonderful place for doing some regexp ;) no_break = re.compile('^\s*(|||||||).*$') @@ -111,10 +120,25 @@ except: errorpage('"style" is missing in configuration!') try: language = configuration.get('look', 'language') except: errorpage('"language" is missing in configuration!') -if language == "de" or language == "at": - locale = ("Seiten", "Monate", "Links", "Keine Kommentare", "Kommentare", "Alle Einträge anzeigen...", "Name", "Text", "Absenden") +if language == "de": + blog_locale = ("Seiten", "Monate", "Links", "Keine Kommentare", "Kommentare", "Alle Einträge anzeigen...", "Name", "Text", "Absenden") + locales_de = ("de_DE.UTF-8", "de_DE.@euro", "de_DE") + for i in locales_de: + try: + locale.setlocale(locale.LC_TIME, i) + break + except: continue + else: locale.setlocale(locale.LC_TIME, None) + else: - locale = ("pages", "months", "links", "no comments", "comments", "View all entries...", "name", "text", "commit") + blog_locale = ("pages", "months", "links", "no comments", "comments", "View all entries...", "name", "text", "commit") + locales_en = ("en_US.UTF-8", "en_US.ISO-8859-15", "en_US") + for i in locales_en: + try: + locale.setlocale(locale.LC_TIME, i) + break + except: continue + else: locale.setlocale(locale.LC_TIME, None) try: entries_per_page = configuration.getint('look', 'entries_per_page') except: errorpage('"entries_per_page" is missing in configuration!') @@ -201,7 +225,7 @@ if cname and ctext and ctitle: try: content = open(entries_dir + ctitle + '.comments', "a") content.write("-." + cname + "\n") - content.write("+." + time.asctime() + "\n") + content.write("+." + time.strftime("%c", time.localtime()) + "\n") ctext = ctext.split("\n") for line in ctext: content.write("." + line + "\n") @@ -353,7 +377,7 @@ else: staticpages_list = glob.glob(staticpages_dir + '*') staticpages_list.sort() print '
' - print '
' + locale[0] + '
' + print '
' + blog_locale[0] + '
' print '
' print '
    ' for staticpage in staticpages_list: @@ -377,7 +401,7 @@ else: if monthlist == "True": olddate = "" print '
    ' - print '
    ' + locale[1] + '
    ' + print '
    ' + blog_locale[1] + '
    ' print '
    ' print '
      ' for entry in entries: @@ -395,7 +419,7 @@ else: # Linklist if linklist == "True": print ' ' print '' @@ -550,7 +574,7 @@ else: for line in comments_content: if line.split(".", 1)[0] == "-": comments_counter += 1 print '
      ' - print ' ' + locale[4] + ' (' + str(comments_counter) + ')' + print ' ' + blog_locale[4] + ' (' + str(comments_counter) + ')' print '
      ' print '
    ' print '' @@ -563,7 +587,7 @@ else: entry_counter += 1 if not month_display and not post_display and not allentries_display and entry_counter == entries_per_page: # Display pagelist - print '
    ' + locale[5] + '
    ' + print '
    ' + blog_locale[5] + '
    ' print '
    ' print '' -- cgit v1.2.3