aboutsummaryrefslogtreecommitdiffstats
path: root/blogthon.cgi
diff options
context:
space:
mode:
authorStefan Ritter <xeno@thehappy.de>2010-02-17 11:16:00 +0100
committerStefan Ritter <xeno@thehappy.de>2010-02-17 11:16:00 +0100
commitd8b98ca5fbae68a4c15612f59f56cd70b38123df (patch)
tree1812907ff3ddc5a8fd0b008514877c42a48cbdea /blogthon.cgi
parenteae87ee0ecebb6df34ad5c6086f0223c93e7d491 (diff)
Show localized times if locales are generated for this country
Diffstat (limited to 'blogthon.cgi')
-rwxr-xr-xblogthon.cgi52
1 files changed, 38 insertions, 14 deletions
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*(<ul|</ul>|<li|</li>|<ol|</ol>|<table|</table>|<tr|</tr>|<td|</td>|<th|</th>|<p|</p>).*$')
@@ -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 ' <div class="pages">'
- print ' <div class="pages_title">' + locale[0] + '</div>'
+ print ' <div class="pages_title">' + blog_locale[0] + '</div>'
print ' <div class="pages_list">'
print ' <ul class="pages_list">'
for staticpage in staticpages_list:
@@ -377,7 +401,7 @@ else:
if monthlist == "True":
olddate = ""
print ' <div class="months">'
- print ' <div class="months_title">' + locale[1] + '</div>'
+ print ' <div class="months_title">' + blog_locale[1] + '</div>'
print ' <div class="months_list">'
print ' <ul class="months_list">'
for entry in entries:
@@ -395,7 +419,7 @@ else:
# Linklist
if linklist == "True":
print ' <div class="linklist">'
- print ' <div class="linklist_title">' + locale[2] + '</div>'
+ print ' <div class="linklist_title">' + blog_locale[2] + '</div>'
print ' <div class="linklist_list">'
print ' <ul class="linklist_list">'
try:
@@ -526,10 +550,10 @@ else:
print ' <form action="" method="post">'
print ' <input type="hidden" name="ctitle" value="' + title + '" />'
print ' <input type="hidden" name="cquizv" value="' + str(cquizv) + '" />'
- print ' <label class="submit_comment_name">' + locale[6] + ':</label><input class="submit_comment_name_input" type="text" id="cname" name="cname" />'
- print ' <br /><label class="submit_comment_text">' + locale[7] + ':</label><textarea class="submit_comment_textarea" id="ctext" name="ctext"></textarea>'
+ print ' <label class="submit_comment_name">' + blog_locale[6] + ':</label><input class="submit_comment_name_input" type="text" id="cname" name="cname" />'
+ print ' <br /><label class="submit_comment_text">' + blog_locale[7] + ':</label><textarea class="submit_comment_textarea" id="ctext" name="ctext"></textarea>'
print ' <br /><label class="submit_comment_quiz">' + str(random_int_a) + '+' + str(random_int_b) + '=</label><input class="submit_comment_quiz_input" type="text" id="cquiz" name="cquiz" />'
- print ' <br /><input class="submit_comment_button" type="submit" id="submit" value="' + locale[8] + '" />'
+ print ' <br /><input class="submit_comment_button" type="submit" id="submit" value="' + blog_locale[8] + '" />'
print ' </form>'
print ' </div>'
else:
@@ -540,7 +564,7 @@ else:
comments_file = glob.glob(entries_dir + title + '.comments')
if not comments_file and not post_display:
print ' <div class="entry_comment">'
- print ' <a href="?p=' + title.replace(' ','-') + '" class="entry_comment">' + locale[3] + '</a>'
+ print ' <a href="?p=' + title.replace(' ','-') + '" class="entry_comment">' + blog_locale[3] + '</a>'
print ' </div>'
print ' </div>'
print ''
@@ -550,7 +574,7 @@ else:
for line in comments_content:
if line.split(".", 1)[0] == "-": comments_counter += 1
print ' <div class="entry_comment">'
- print ' <a href="?p=' + title.replace(' ', '-') + '" class="entry_comment">' + locale[4] + ' (' + str(comments_counter) + ')</a>'
+ print ' <a href="?p=' + title.replace(' ', '-') + '" class="entry_comment">' + blog_locale[4] + ' (' + str(comments_counter) + ')</a>'
print ' </div>'
print ' </div>'
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 ' <div class="entry"><a href=?a=1>' + locale[5] + '</a></div>'
+ print ' <div class="entry"><a href=?a=1>' + blog_locale[5] + '</a></div>'
print ' </div>'
print ''