Skip to content

Commit

Permalink
templates: translatable text addition
Browse files Browse the repository at this point in the history
* Uses gettext function to make template text translatable.
  (addresses #12)

Signed-off-by: Leonardo Rossi <leonardo.r@cern.ch>
  • Loading branch information
Leonardo Rossi committed Dec 2, 2015
1 parent 5c572ff commit 9be594e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
6 changes: 4 additions & 2 deletions invenio_oauthclient/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import six
from flask import current_app, flash, redirect, render_template, request, \
session, url_for
from flask_babelex import gettext as _
from flask_login import current_user
from invenio_db import db
from werkzeug.utils import import_string
Expand Down Expand Up @@ -180,7 +181,8 @@ def inner(*args, **kwargs):
e.remote, e.response, e.code, e.uri, e.description
)
except OAuthRejectedRequestError:
flash("You rejected the authentication request.", category='info')
flash(_("You rejected the authentication request."),
category='info')
return redirect('/')
return inner

Expand Down Expand Up @@ -396,5 +398,5 @@ def make_token_getter(remote):
def oauth2_handle_error(remote, resp, error_code, error_uri,
error_description):
"""Handle errors during exchange of one-time code for an access tokens."""
flash("Authorization with remote service failed.")
flash(_("Authorization with remote service failed."))
return redirect('/')
12 changes: 7 additions & 5 deletions invenio_oauthclient/templates/invenio_oauthclient/_macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
{% macro form_errors(form) %}
{%- if form.errors %}
<div class="alert alert-danger alert-dismissible text-left" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
{%- for field, errors in form.errors.items() %}
{%- for error in errors %}
<p>{{error}}</p>
<button type="button" class="close" data-dismiss="alert" aria-label="{{ _('Close') }}">
<span aria-hidden="true">&times;</span>
</button>
{%- for field, errors in form.errors.items() %}
{%- for error in errors %}
<p>{{error}}</p>
{%- endfor %}
{%- endfor %}
{%- endfor %}
</div>
{%- endif %}
{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
{%- extends config.OAUTHCLIENT_COVER_TEMPLATE %}

{% block page_body %}
Rejected
{{ _('Rejected'} }}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,27 @@
{% block settings_form %}
<div class="panel-body">
{% block oauth_body_text %}
<p>Tired of entering password for {{config.CFG_SITE_NAME}} every time you sign in? Setup single sign-on with one or more of the services below:</p>
<p>{{ _('Tired of entering password for %(sitename)s every time you sign in? Setup single sign-on with one or more of the services below:',
sitename=config.CFG_SITE_NAME) }}</p>
{% endblock oauth_body_text %}
</div>
<ul class="list-group">
{%- for s in services %}
<li class="list-group-item">
{% block oauth_controls scoped %}
<div class="pull-right">
{%- if s.account -%}
<a href="{{url_for('invenio_oauthclient.disconnect', remote_app=s.appid)}}" class="btn btn-default btn-xs"><i class="fa fa-times-circle"></i> Disconnect</a>
{%- else -%}
<a href="{{url_for('invenio_oauthclient.login', remote_app=s.appid)}}" class="btn btn-default btn-xs"><i class="fa fa-link"></i> Connect</a>
{%- endif -%}
</div>
{% endblock oauth_controls %}
{% if s.icon %}<i class="{{s.icon}}"></i> {% endif %}{{s.title}}{% if s.account %} <i class="fa fa-check" style="color: #5cb85c;"></i>{% endif %}<br/><small class="text-muted">{{s.description}}</small>
{% block oauth_controls scoped %}
<div class="pull-right">
{%- if s.account -%}
<a href="{{url_for('invenio_oauthclient.disconnect', remote_app=s.appid)}}" class="btn btn-default btn-xs"><i class="fa fa-times-circle"></i> {{ _('Disconnect') }}</a>
{%- else -%}
<a href="{{url_for('invenio_oauthclient.login', remote_app=s.appid)}}" class="btn btn-default btn-xs"><i class="fa fa-link"></i> {{ _('Connect') }}</a>
{%- endif -%}
</div>
{% endblock oauth_controls %}
{% if s.icon %}<i class="{{s.icon}}"></i>{% endif %}
{{s.title}}
{% if s.account %}<i class="fa fa-check text-success"></i>{% endif %}
<br/>
<small class="text-muted">{{s.description}}</small>
</li>
{%- endfor %}
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<span class="pull-right"><i class="{{app_icon}} fa-5x"></i></span>
{%- endif %}
{%- endblock %}
<h3> Sign-up with {{app_title}}!</h3>
<h3> {{ _('Sign-up with %(title)s!', title=app_title) }}</h3>
<p>{{ _('Fill in your details to complete your registration. You only have to do this once.') }}</p>
<hr />
{% endblock %}
Expand Down

0 comments on commit 9be594e

Please sign in to comment.