Replace g.gettext by iwla._
Add createCurTitle() to factorize code
This commit is contained in:
44
iwla.py
44
iwla.py
@@ -10,7 +10,7 @@ import gzip
|
||||
import importlib
|
||||
import argparse
|
||||
import logging
|
||||
import gettext as g
|
||||
import gettext
|
||||
from calendar import monthrange
|
||||
from datetime import date
|
||||
|
||||
@@ -131,19 +131,13 @@ class IWLA(object):
|
||||
logging.basicConfig(format='%(name)s %(message)s', level=logLevel)
|
||||
self.logger = logging.getLogger(self.__class__.__name__)
|
||||
self.logger.info('==> Start')
|
||||
|
||||
# print conf.locales_path
|
||||
# print conf.locale
|
||||
#print g.find('iwla', localedir=conf.locales_path, all=False)
|
||||
# print g.find('iwla', localedir=conf.locales_path, languages=[conf.locale], all=True)
|
||||
#g.install('iwla', localedir=conf.locales_path)
|
||||
t = g.translation('iwla', localedir=conf.locales_path, languages=[conf.locale])
|
||||
self._ = t.gettext
|
||||
#t.install()
|
||||
# g.install('iwla', localedir=conf.locales_path, names=conf.locale)
|
||||
|
||||
print(self._('Statistics'))
|
||||
# print(_('Statistics'))
|
||||
try:
|
||||
t = gettext.translation('iwla', localedir=conf.locales_path, languages=[conf.locale], codeset='utf8')
|
||||
self.logger.info('\tUsing locale %s' % (conf.locale))
|
||||
except IOError:
|
||||
t = gettext.NullTranslations()
|
||||
self.logger.info('\tUsing default locale en_EN')
|
||||
self._ = t.ugettext
|
||||
|
||||
def getVersion(self):
|
||||
return IWLA.IWLA_VERSION
|
||||
@@ -353,13 +347,13 @@ class IWLA(object):
|
||||
|
||||
def _generateDisplayDaysStats(self):
|
||||
cur_time = self.meta_infos['last_time']
|
||||
title = '%s %d/%02d' % (g.gettext('Statistics'), cur_time.tm_year, cur_time.tm_mon)
|
||||
title = '%s %d/%02d' % (self._('Statistics'), cur_time.tm_year, cur_time.tm_mon)
|
||||
filename = self.getCurDisplayPath('index.html')
|
||||
self.logger.info('==> Generate display (%s)' % (filename))
|
||||
page = self.display.createPage(title, filename, conf.css_path)
|
||||
|
||||
_, nb_month_days = monthrange(cur_time.tm_year, cur_time.tm_mon)
|
||||
days = self.display.createBlock(DisplayHTMLBlockTableWithGraph, g.gettext('By day'), [g.gettext('Day'), g.gettext('Visits'), g.gettext('Pages'), g.gettext('Hits'), g.gettext('Bandwidth'), g.gettext('Not viewed Bandwidth')], None, nb_month_days, range(1,6))
|
||||
days = self.display.createBlock(DisplayHTMLBlockTableWithGraph, self._('By day'), [self._('Day'), self._('Visits'), self._('Pages'), self._('Hits'), self._('Bandwidth'), self._('Not viewed Bandwidth')], None, nb_month_days, range(1,6))
|
||||
days.setColsCSSClass(['', 'iwla_visit', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth'])
|
||||
nb_visits = 0
|
||||
nb_days = 0
|
||||
@@ -396,12 +390,12 @@ class IWLA(object):
|
||||
else:
|
||||
average_row = map(lambda(v): 0, row)
|
||||
|
||||
average_row[0] = g.gettext('Average')
|
||||
average_row[0] = self._('Average')
|
||||
average_row[4] = bytesToStr(average_row[4])
|
||||
average_row[5] = bytesToStr(average_row[5])
|
||||
days.appendRow(average_row)
|
||||
|
||||
row[0] = g.gettext('Total')
|
||||
row[0] = self._('Total')
|
||||
row[4] = bytesToStr(row[4])
|
||||
row[5] = bytesToStr(row[5])
|
||||
days.appendRow(row)
|
||||
@@ -410,9 +404,9 @@ class IWLA(object):
|
||||
|
||||
def _generateDisplayMonthStats(self, page, year, month_stats):
|
||||
cur_time = time.localtime()
|
||||
months_name = ['', g.gettext('Jan'), g.gettext('Feb'), g.gettext('Mar'), g.gettext('Apr'), g.gettext('May'), g.gettext('June'), g.gettext('July'), g.gettext('Aug'), g.gettext('Sep'), g.gettext('Oct'), g.gettext('Nov'), g.gettext('Dec')]
|
||||
title = '%s %d' % (g.gettext('Summary'), year)
|
||||
cols = [g.gettext('Month'), g.gettext('Visitors'), g.gettext('Visits'), g.gettext('Pages'), g.gettext('Hits'), g.gettext('Bandwidth'), g.gettext('Not viewed Bandwidth'), g.gettext('Details')]
|
||||
months_name = ['', self._('Jan'), self._('Feb'), self._('Mar'), self._('Apr'), self._('May'), self._('June'), self._('July'), self._('Aug'), self._('Sep'), self._('Oct'), self._('Nov'), self._('Dec')]
|
||||
title = '%s %d' % (self._('Summary'), year)
|
||||
cols = [self._('Month'), self._('Visitors'), self._('Visits'), self._('Pages'), self._('Hits'), self._('Bandwidth'), self._('Not viewed Bandwidth'), self._('Details')]
|
||||
graph_cols=range(1,7)
|
||||
months = self.display.createBlock(DisplayHTMLBlockTableWithGraph, title, cols, None, 12, graph_cols)
|
||||
months.setColsCSSClass(['', 'iwla_visitor', 'iwla_visit', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth', ''])
|
||||
@@ -422,7 +416,7 @@ class IWLA(object):
|
||||
full_month = '%s %d' % (months_name[i], year)
|
||||
if i in month_stats.keys():
|
||||
stats = month_stats[i]
|
||||
link = '<a href="%d/%02d/index.html">%s</a>' % (year, i, g.gettext('Details'))
|
||||
link = '<a href="%d/%02d/index.html">%s</a>' % (year, i, self._('Details'))
|
||||
row = [full_month, stats['nb_visitors'], stats['nb_visits'], stats['viewed_pages'], stats['viewed_hits'],
|
||||
stats['viewed_bandwidth'], stats['not_viewed_bandwidth'], link]
|
||||
for j in graph_cols:
|
||||
@@ -439,21 +433,21 @@ class IWLA(object):
|
||||
else: css = 'iwla_curday'
|
||||
months.setCellCSSClass(i-1, 0, css)
|
||||
|
||||
total[0] = g.gettext('Total')
|
||||
total[0] = self._('Total')
|
||||
total[5] = bytesToStr(total[5])
|
||||
total[6] = bytesToStr(total[6])
|
||||
months.appendRow(total)
|
||||
page.appendBlock(months)
|
||||
|
||||
def _generateDisplayWholeMonthStats(self):
|
||||
title = '%s %s' % (g.gettext('Statistics for'), conf.domain_name)
|
||||
title = '%s %s' % (self._('Statistics for'), conf.domain_name)
|
||||
filename = 'index.html'
|
||||
|
||||
self.logger.info('==> Generate main page (%s)' % (filename))
|
||||
|
||||
page = self.display.createPage(title, filename, conf.css_path)
|
||||
|
||||
last_update = '<b>%s</b> %s<br />' % (g.gettext('Last update'), time.strftime('%02d %b %Y %H:%M', time.localtime()))
|
||||
last_update = '<b>%s</b> %s<br />' % (self._('Last update'), time.strftime('%02d %b %Y %H:%M', time.localtime()))
|
||||
page.appendBlock(self.display.createBlock(DisplayHTMLRaw, last_update))
|
||||
|
||||
for year in sorted(self.meta_infos['stats'].keys(), reverse=True):
|
||||
|
||||
Reference in New Issue
Block a user