Use g.gettext for translations
This commit is contained in:
@@ -10,6 +10,7 @@ import gzip
|
||||
import importlib
|
||||
import argparse
|
||||
import logging
|
||||
import gettext as g
|
||||
from calendar import monthrange
|
||||
from datetime import date
|
||||
|
||||
@@ -32,6 +33,7 @@ from display import *
|
||||
# Conf values needed :
|
||||
# analyzed_filename
|
||||
# domain_name
|
||||
# locales_path
|
||||
# compress_output_files*
|
||||
#
|
||||
# Output files :
|
||||
@@ -130,6 +132,19 @@ class IWLA(object):
|
||||
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'))
|
||||
|
||||
def getVersion(self):
|
||||
return IWLA.IWLA_VERSION
|
||||
|
||||
@@ -338,13 +353,13 @@ class IWLA(object):
|
||||
|
||||
def _generateDisplayDaysStats(self):
|
||||
cur_time = self.meta_infos['last_time']
|
||||
title = 'Stats %d/%02d' % (cur_time.tm_year, cur_time.tm_mon)
|
||||
title = '%s %d/%02d' % (g.gettext('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, 'By day', ['Day', 'Visits', 'Pages', 'Hits', 'Bandwidth', 'Not viewed Bandwidth'], None, nb_month_days, range(1,6))
|
||||
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.setColsCSSClass(['', 'iwla_visit', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth'])
|
||||
nb_visits = 0
|
||||
nb_days = 0
|
||||
@@ -381,12 +396,12 @@ class IWLA(object):
|
||||
else:
|
||||
average_row = map(lambda(v): 0, row)
|
||||
|
||||
average_row[0] = 'Average'
|
||||
average_row[0] = g.gettext('Average')
|
||||
average_row[4] = bytesToStr(average_row[4])
|
||||
average_row[5] = bytesToStr(average_row[5])
|
||||
days.appendRow(average_row)
|
||||
|
||||
row[0] = 'Total'
|
||||
row[0] = g.gettext('Total')
|
||||
row[4] = bytesToStr(row[4])
|
||||
row[5] = bytesToStr(row[5])
|
||||
days.appendRow(row)
|
||||
@@ -395,9 +410,9 @@ class IWLA(object):
|
||||
|
||||
def _generateDisplayMonthStats(self, page, year, month_stats):
|
||||
cur_time = time.localtime()
|
||||
months_name = ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
||||
title = 'Summary %d' % (year)
|
||||
cols = ['Month', 'Visitors', 'Visits', 'Pages', 'Hits', 'Bandwidth', 'Not viewed Bandwidth', 'Details']
|
||||
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')]
|
||||
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', ''])
|
||||
@@ -407,7 +422,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">Details</a>' % (year, i)
|
||||
link = '<a href="%d/%02d/index.html">%s</a>' % (year, i, g.gettext('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:
|
||||
@@ -424,21 +439,21 @@ class IWLA(object):
|
||||
else: css = 'iwla_curday'
|
||||
months.setCellCSSClass(i-1, 0, css)
|
||||
|
||||
total[0] = 'Total'
|
||||
total[0] = g.gettext('Total')
|
||||
total[5] = bytesToStr(total[5])
|
||||
total[6] = bytesToStr(total[6])
|
||||
months.appendRow(total)
|
||||
page.appendBlock(months)
|
||||
|
||||
def _generateDisplayWholeMonthStats(self):
|
||||
title = 'Stats for %s' % (conf.domain_name)
|
||||
title = '%s %s' % (g.gettext('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>Last update</b> %s<br />' % (time.strftime('%02d %b %Y %H:%M', time.localtime()))
|
||||
last_update = '<b>%s</b> %s<br />' % (g.gettext('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):
|
||||
@@ -669,7 +684,7 @@ if __name__ == '__main__':
|
||||
loglevel = getattr(logging, args.loglevel.upper(), None)
|
||||
if not isinstance(loglevel, int):
|
||||
raise ValueError('Invalid log level: %s' % (args.loglevel))
|
||||
|
||||
|
||||
iwla = IWLA(loglevel)
|
||||
|
||||
required_conf = ['analyzed_filename', 'domain_name']
|
||||
|
||||
Reference in New Issue
Block a user