adding translations support for publish-date

This commit is contained in:
Thomas Pointhuber 2014-03-14 10:55:52 +01:00
parent c54baf6301
commit 7a922b2ab8
1 changed files with 4 additions and 4 deletions

View File

@ -32,7 +32,7 @@ from flask import (
Flask, request, render_template, url_for, Response, make_response, Flask, request, render_template, url_for, Response, make_response,
redirect, send_from_directory redirect, send_from_directory
) )
from flask.ext.babel import Babel from flask.ext.babel import Babel, gettext, ngettext, format_date
from searx import settings, searx_dir from searx import settings, searx_dir
from searx.engines import ( from searx.engines import (
search as do_search, categories, engines, get_engines_stats, search as do_search, categories, engines, get_engines_stats,
@ -162,11 +162,11 @@ def index():
if result['publishedDate'].date() == datetime.now().date(): if result['publishedDate'].date() == datetime.now().date():
timedifference = datetime.now()-result['publishedDate'] timedifference = datetime.now()-result['publishedDate']
if timedifference.seconds < 60*60: if timedifference.seconds < 60*60:
result['publishedDate'] = '{0:d} minutes ago'.format(timedifference.seconds/60) result['publishedDate'] = gettext(u'{0:d} minutes ago').format(timedifference.seconds/60)
else: else:
result['publishedDate'] = '{0:d} hours ago'.format(timedifference.seconds/60/60) result['publishedDate'] = gettext(u'{0:d} hours ago').format(timedifference.seconds/60/60)
else: else:
result['publishedDate'] = result['publishedDate'].strftime('%d.%m.%Y') result['publishedDate'] = format_date(result['publishedDate'])
if search.request_data.get('format') == 'json': if search.request_data.get('format') == 'json':
return Response(json.dumps({'query': search.query, return Response(json.dumps({'query': search.query,