basic locale support for dates
This commit is contained in:
parent
cd45d67c62
commit
55ab840bc8
4 changed files with 26 additions and 1 deletions
|
@ -131,3 +131,17 @@ UI_CALENDAR_FREQUENCY_THRESHOLD
|
||||||
BOOTSTRAP_SERVE_LOCAL
|
BOOTSTRAP_SERVE_LOCAL
|
||||||
larigira can serve every js and css by itself. However, you might like to make the user download standard
|
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``.
|
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 <http://babel.pocoo.org/en/latest/dates.html>`_. Default is ``medium``.
|
||||||
|
|
||||||
|
As an example, ``eee dd LLL`` will show ``Sun 10 Mar`` for english, and ``dom 10 mar`` for italian.
|
||||||
|
|
|
@ -31,6 +31,7 @@ def get_conf(prefix='LARIGIRA_'):
|
||||||
conf['TMPDIR'] = os.getenv('TMPDIR', '/tmp/')
|
conf['TMPDIR'] = os.getenv('TMPDIR', '/tmp/')
|
||||||
conf['FILE_PATH_SUGGESTION'] = () # tuple of paths
|
conf['FILE_PATH_SUGGESTION'] = () # tuple of paths
|
||||||
conf['UI_CALENDAR_FREQUENCY_THRESHOLD'] = 4*60*60 # 4 hours
|
conf['UI_CALENDAR_FREQUENCY_THRESHOLD'] = 4*60*60 # 4 hours
|
||||||
|
conf['UI_CALENDAR_DATE_FMT'] = 'medium'
|
||||||
conf['EVENT_FILTERS'] = []
|
conf['EVENT_FILTERS'] = []
|
||||||
conf.update(from_envvars(prefix=prefix))
|
conf.update(from_envvars(prefix=prefix))
|
||||||
return conf
|
return conf
|
||||||
|
|
|
@ -48,7 +48,8 @@ li.alarm .alarm-actions { display: none; }
|
||||||
{% for week, weekdays in weeks|dictsort %}
|
{% for week, weekdays in weeks|dictsort %}
|
||||||
<div class="week row" id="week-{{week[0]}}-{{week[1]}}">
|
<div class="week row" id="week-{{week[0]}}-{{week[1]}}">
|
||||||
{% for day in weeks[week] %}
|
{% for day in weeks[week] %}
|
||||||
<div class="day col-lg-2 col-md-3 col-sm-6 col-xs-12"><h2>{{day}}</h2>
|
<div class="day col-lg-2 col-md-3 col-sm-6 col-xs-12">
|
||||||
|
<h2><time datetime="{{day}}">{{day|dateformat(config.UI_CALENDAR_DATE_FMT)}}</time></h2>
|
||||||
{% for t in days[day]|sort %}
|
{% for t in days[day]|sort %}
|
||||||
<div>
|
<div>
|
||||||
<ul>
|
<ul>
|
||||||
|
|
|
@ -6,6 +6,7 @@ from greenlet import greenlet
|
||||||
from flask import current_app, Blueprint, Flask, jsonify, render_template, \
|
from flask import current_app, Blueprint, Flask, jsonify, render_template, \
|
||||||
request, abort
|
request, abort
|
||||||
from flask_bootstrap import Bootstrap
|
from flask_bootstrap import Bootstrap
|
||||||
|
from flask.ext.babel import Babel
|
||||||
from werkzeug.contrib.cache import SimpleCache
|
from werkzeug.contrib.cache import SimpleCache
|
||||||
|
|
||||||
from .dbadmin import db
|
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):
|
def create_app(queue, larigira):
|
||||||
app = Flask('larigira',
|
app = Flask('larigira',
|
||||||
static_url_path=get_conf()['ROUTE_PREFIX'] + '/static')
|
static_url_path=get_conf()['ROUTE_PREFIX'] + '/static')
|
||||||
app.config.update(get_conf())
|
app.config.update(get_conf())
|
||||||
Bootstrap(app)
|
Bootstrap(app)
|
||||||
|
babel = Babel(app)
|
||||||
|
babel.localeselector(babel_get_locale)
|
||||||
app.register_blueprint(rpc)
|
app.register_blueprint(rpc)
|
||||||
app.register_blueprint(viewui)
|
app.register_blueprint(viewui)
|
||||||
app.register_blueprint(db)
|
app.register_blueprint(db)
|
||||||
|
|
Loading…
Reference in a new issue