From 55ab840bc8d7b28a38dd1c7398c673c5f4e74cfe Mon Sep 17 00:00:00 2001 From: boyska Date: Sat, 9 Feb 2019 23:27:47 +0100 Subject: [PATCH] basic locale support for dates --- doc/source/install.rst | 14 ++++++++++++++ larigira/config.py | 1 + larigira/dbadmin/templates/calendar.html | 3 ++- larigira/rpc.py | 9 +++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/doc/source/install.rst b/doc/source/install.rst index 611b3da..d16406b 100644 --- a/doc/source/install.rst +++ b/doc/source/install.rst @@ -131,3 +131,17 @@ UI_CALENDAR_FREQUENCY_THRESHOLD BOOTSTRAP_SERVE_LOCAL larigira can serve every js and css by itself. However, you might like to make the user download standard libraries from CDNs. In that case, set this variable to ``false``. + +Localization +++++++++++++++ + +Localization support in larigira is basic to say the least. However, something can be done. +Dates (not consistently! sigh) are formatted according to locale. + +LARIGIRA_BABEL_DEFAULT_LOCALE + The short language code you want to use when the user doesn't specify any. Values are in the form + ``it``, ``en``, ``en-US``... +LARIGIRA_UI_CALENDAR_DATE_FMT + The format to show in ``/db/calendar`` page. The format is specified `here `_. Default is ``medium``. + + As an example, ``eee dd LLL`` will show ``Sun 10 Mar`` for english, and ``dom 10 mar`` for italian. diff --git a/larigira/config.py b/larigira/config.py index cdfd1f2..53da879 100644 --- a/larigira/config.py +++ b/larigira/config.py @@ -31,6 +31,7 @@ def get_conf(prefix='LARIGIRA_'): conf['TMPDIR'] = os.getenv('TMPDIR', '/tmp/') conf['FILE_PATH_SUGGESTION'] = () # tuple of paths conf['UI_CALENDAR_FREQUENCY_THRESHOLD'] = 4*60*60 # 4 hours + conf['UI_CALENDAR_DATE_FMT'] = 'medium' conf['EVENT_FILTERS'] = [] conf.update(from_envvars(prefix=prefix)) return conf diff --git a/larigira/dbadmin/templates/calendar.html b/larigira/dbadmin/templates/calendar.html index a8f0621..6a4a77f 100644 --- a/larigira/dbadmin/templates/calendar.html +++ b/larigira/dbadmin/templates/calendar.html @@ -48,7 +48,8 @@ li.alarm .alarm-actions { display: none; } {% for week, weekdays in weeks|dictsort %}
{% for day in weeks[week] %} -

{{day}}

+
+

{% for t in days[day]|sort %}
    diff --git a/larigira/rpc.py b/larigira/rpc.py index 3fb0e74..97aed06 100644 --- a/larigira/rpc.py +++ b/larigira/rpc.py @@ -6,6 +6,7 @@ from greenlet import greenlet from flask import current_app, Blueprint, Flask, jsonify, render_template, \ request, abort from flask_bootstrap import Bootstrap +from flask.ext.babel import Babel from werkzeug.contrib.cache import SimpleCache from .dbadmin import db @@ -173,11 +174,19 @@ def rpc_wip(): )) +def babel_get_locale(): + if request.accept_languages: + return request.accept_languages[0][0] + return None + + def create_app(queue, larigira): app = Flask('larigira', static_url_path=get_conf()['ROUTE_PREFIX'] + '/static') app.config.update(get_conf()) Bootstrap(app) + babel = Babel(app) + babel.localeselector(babel_get_locale) app.register_blueprint(rpc) app.register_blueprint(viewui) app.register_blueprint(db)