Skip to content

Commit

Permalink
Add translation support
Browse files Browse the repository at this point in the history
This commit turns most of the messages into translatable messages.

Also includes German translation for all messages.
  • Loading branch information
Benestar committed Oct 14, 2017
1 parent 8afc1a9 commit af928a3
Show file tree
Hide file tree
Showing 26 changed files with 662 additions and 139 deletions.
2 changes: 1 addition & 1 deletion bootstrap.sh
Expand Up @@ -4,7 +4,7 @@ echo "Bootstrapping Django Vagrant machine..."
sudo apt-get update
sudo apt-get install -y vim git make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
libncursesw5-dev xz-utils
libncursesw5-dev xz-utils gettext

# Install NodeJS

Expand Down
9 changes: 5 additions & 4 deletions depot/models.py
@@ -1,5 +1,6 @@
from django.db import models
from django.contrib.auth.models import Group, User
from django.db import models
from django.utils.translation import ugettext_lazy as _


class Organization(models.Model):
Expand Down Expand Up @@ -138,9 +139,9 @@ class Item(models.Model):
VISIBILITY_PRIVATE = '2'
VISIBILITY_DELETED = '3'
VISIBILITY_LEVELS = (
(VISIBILITY_PUBLIC, 'public'),
(VISIBILITY_PRIVATE, 'private'),
(VISIBILITY_DELETED, 'deleted'),
(VISIBILITY_PUBLIC, _('public')),
(VISIBILITY_PRIVATE, _('private')),
(VISIBILITY_DELETED, _('deleted')),
)

name = models.CharField(max_length=32)
Expand Down
44 changes: 25 additions & 19 deletions depot/templates/depot/create-rental.html
@@ -1,30 +1,30 @@
{% extends 'layout.html' %}

{% load tags %}
{% load i18n %}

{% block title %}
New Rental for {{ depot.name }}
{% blocktrans trimmed with depot_name=depot.name %}
New Rental for {{ depot_name }}
{% endblocktrans %}
{% endblock %}

{% block content %}
<ol class="breadcrumb">
<li>
<a href="{% url 'depot:index' %}">Depots</a>
<a href="{% url 'depot:index' %}">{% trans 'Depots' %}</a>
</li>
<li>
<a href="{% url 'depot:detail' depot.id %}">{{ depot.name }}</a>
</li>
<li class="active">
<span>New Rental</span>
<span>{% trans 'New Rental' %}</span>
</li>
</ol>

{% if errors %}
<div class="alert alert-danger" role="alert">
Please fix the
<a href="#errors-collapse" class="alert-link" data-toggle="collapse">errors below</a>
and in the
<a href="#checkout-modal" class="alert-link" data-toggle="modal">checkout form</a>
{% trans 'Please fix the errors below and in the checkout form.' %}

<a href="#errors-collapse" class="alert-link pull-right" data-toggle="collapse">
<span class="caret"></span>
Expand All @@ -48,35 +48,41 @@

<div class="page-header">
<h1>
New Rental <small>for {{ depot.name }}</small>
{% blocktrans trimmed with depot_name=depot.name %}
New Rental <small>for {{ depot_name }}</small>
{% endblocktrans %}
</h1>
</div>

<p>
Create a new rental
{% trans 'Create a new rental' %}
<a href="#date-modal" data-toggle="modal">
from {{ start_date }} to {{ return_date }}
{% blocktrans trimmed %}
from {{ start_date }} to {{ return_date }}.
{% endblocktrans %}
</a>
</p>

<div class="panel panel-default">
<div class="panel-body">
Hint: You can click on the number of available items
to get a detailed view of its availability over time.
{% blocktrans trimmed %}
Hint: You can click on the number of available items
to get a detailed view of its availability over time.
{% endblocktrans %}
</div>

<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th class="text-center">Available</th>
<th>Location</th>
<th>{% trans 'Name' %}</th>
<th class="text-center">{% trans 'Available' %}</th>
<th>{% trans 'Location' %}</th>
{% if show_visibility %}
<th class="text-center">Visibility</th>
<th class="text-center">{% trans 'Visibility' %}</th>
{% endif %}
<th>Selected</th>
<th>{% trans 'Selected' %}</th>
</tr>
</thead>

Expand Down Expand Up @@ -138,12 +144,12 @@ <h1>
<button type="button" class="btn btn-primary" id="checkout-button"
data-toggle="modal" data-target="#checkout-modal"
{% if not errors %} disabled {% endif %}>
Checkout
{% trans 'Checkout' %}
</button>

<button type="button" class="btn btn-default"
data-toggle="modal" data-target="#date-modal">
Change time frame
{% trans 'Change time frame' %}
</button>
</div>
</div>
Expand Down
34 changes: 21 additions & 13 deletions depot/templates/depot/detail.html
@@ -1,15 +1,18 @@
{% extends 'layout.html' %}

{% load tags %}
{% load i18n %}

{% block title %}
{{ depot.name }} by {{ depot.organization.name }}
{% blocktrans trimmed with depot_name=depot.name organization_name=depot.organization.name %}
{{ depot_name }} by {{ organization_name }}
{% endblocktrans %}
{% endblock %}

{% block content %}
<ol class="breadcrumb">
<li>
<a href="{% url 'depot:index' %}">Depots</a>
<a href="{% url 'depot:index' %}">{% trans 'Depots' %}</a>
</li>
<li class="active">
<span>{{ depot.name }}</span>
Expand All @@ -18,31 +21,36 @@

<div class="page-header">
<h1>
{{ depot.name }} <small>by {{ depot.organization.name }}</small>
{% blocktrans trimmed with depot_name=depot.name organization_name=depot.organization.name %}
{{ depot_name }} <small>by {{ organization_name }}</small>
{% endblocktrans %}

{% if managed_by_user %}
<a href="{% url 'admin:depot_depot_change' depot.id %}"
class="btn btn-default" target="_blank">
Manage
{% trans 'Manage' %}
</a>
<a href="{% url 'depot:rentals' depot.id %}"
class="btn btn-default">
Rentals
{% trans 'Rentals' %}
</a>
{% endif %}
</h1>
</div>

<p>
This depot is managed by {% concat_with_and depot.managers|full_names empty='no one apparently' %}.
{% concat_with_and depot.managers|full_names empty=_('no one apparently') as managers %}
{% blocktrans trimmed %}
This depot is managed by {{ managers }}.
{% endblocktrans %}
</p>

<div class="panel panel-default">
<div class="panel-body">
{% if depot.description %}
{{ depot.description }}
{% else %}
<i>No description provided.</i>
<i>{% trans 'No description provided' %}</i>
{% endif %}
</div>

Expand All @@ -51,11 +59,11 @@ <h1>
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th class="text-center">Quantity</th>
<th>Location</th>
<th>{% trans 'Name' %}</th>
<th class="text-center">{% trans 'Quantity' %}</th>
<th>{% trans 'Location' %}</th>
{% if show_visibility %}
<th class="text-center">Visibility</th>
<th class="text-center">{% trans 'Visibility' %}</th>
{% endif %}
</tr>
</thead>
Expand Down Expand Up @@ -90,7 +98,7 @@ <h1>
{% empty %}
<tr>
<td class="text-center" colspan="99">
<i>No items available</i>
<i>{% trans 'No items available' %}</i>
</td>
</tr>
{% endfor %}
Expand All @@ -102,7 +110,7 @@ <h1>
<button type="button" class="btn btn-primary"
data-toggle="modal" data-target="#date-modal"
{% if not item_list %} disabled {% endif %}>
Request rental
{% trans 'Request rental' %}
</button>
</div>
</div>
Expand Down
24 changes: 17 additions & 7 deletions depot/templates/depot/index.html
@@ -1,14 +1,15 @@
{% extends 'layout.html' %}

{% load tags %}
{% load i18n %}

{% block title %}
Depots by organization
{% trans 'Depots by organization' %}
{% endblock %}

{% block content %}
<div class="page-header">
<h1>Depots by organization</h1>
<h1>{% trans 'Depots by organization' %}</h1>
</div>

{% for organization in organization_depots %}
Expand All @@ -17,13 +18,16 @@ <h2>
{% if organization.managed_by_user %}
<a href="{% url 'admin:depot_organization_change' organization.model.id %}"
class="btn btn-default" target="_blank">
Manage
{% trans 'Manage' %}
</a>
{% endif %}
</h2>

<p>
This organization is managed by {% concat_with_and organization.model.managers.all|full_names empty='no one apparently' %}.
{% concat_with_and organization.model.managers.all|full_names empty=_('no one apparently') as managers %}
{% blocktrans trimmed %}
This organization is managed by {{ managers }}.
{% endblocktrans %}
</p>

<div class="columns">
Expand All @@ -33,7 +37,13 @@ <h2>
<h3 class="panel-title">
{{ depot.name }}

<span class="badge">{{ depot.public_items.count }} items</span>
<span class="badge">
{% blocktrans trimmed count counter=depot.public_items.count %}
{{ counter }} item
{% plural %}
{{ counter }} items
{% endblocktrans %}
</span>

<span class="glyphicon glyphicon-list-alt pull-right" aria-hidden="true"></span>
</h3>
Expand All @@ -42,15 +52,15 @@ <h3 class="panel-title">
{% if depot.description %}
{{ depot.description }}
{% else %}
<i>No description provided.</i>
<i>{% trans 'No description provided' %}</i>
{% endif %}
</div>
</div>
{% endfor %}
</div>
{% empty %}
<div class="alert alert-danger" role="alert">
No depots available :(
{% trans 'No depots available' %} :(
</div>
{% endfor %}
{% endblock %}
8 changes: 6 additions & 2 deletions depot/templates/depot/modals/availability-modal.html
@@ -1,3 +1,5 @@
{% load i18n %}

<div class="modal fade" id="availability-modal" tabindex="-1"
role="dialog" aria-labelledby="availability-title">
<div class="modal-dialog" role="document">
Expand All @@ -7,15 +9,17 @@
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title" id="availability-title">
Availability <small>of <span id="availability-item"></span></small>
{% blocktrans trimmed with item='<span id="availability-item"></span>' %}
Availability <small>of {{ item }}</small>
{% endblocktrans %}
</h4>
</div>
<div class="modal-body">
<canvas id="availability-chart" height="200"></canvas>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
Close
{% trans 'Close' %}
</button>
</div>
</div>
Expand Down
22 changes: 13 additions & 9 deletions depot/templates/depot/modals/checkout-form.html
@@ -1,6 +1,8 @@
{% load i18n %}

<div class="row">
<div class="form-group col-md-6 {% if errors.firstname %} has-error {% endif %}">
<label for="firstname">First Name</label>
<label for="firstname">{% trans 'First Name' %}</label>
<div class="input-group name">
<input type="text" class="form-control" id="firstname"
name="firstname" value="{% firstof data.firstname user.first_name %}" required>
Expand All @@ -17,7 +19,7 @@
{% endif %}
</div>
<div class="form-group col-md-6 {% if errors.firstname %} has-error {% endif %}">
<label for="lastname">Last Name</label>
<label for="lastname">{% trans 'Last Name' %}</label>
<div class="input-group name">
<input type="text" class="form-control" id="lastname"
name="lastname" value="{% firstof data.lastname user.last_name %}" required>
Expand All @@ -36,7 +38,7 @@
</div>

<div class="form-group {% if errors.email %} has-error {% endif %}">
<label for="email">Email address</label>
<label for="email">{% trans 'Email address' %}</label>
<div class="input-group">
<input type="email" class="form-control" id="email"
name="email" value="{% firstof data.email user.email %}" required>
Expand All @@ -52,7 +54,7 @@
</div>

<div class="form-group {% if errors.purpose %} has-error {% endif %}">
<label for="purpose">Purpose</label>
<label for="purpose">{% trans 'Purpose' %}</label>
<div class="input-group">
<textarea class="form-control" id="purpose" name="purpose"
required>{{ data.purpose }}</textarea>
Expand All @@ -70,15 +72,17 @@
</div>

<div class="form-group">
<label>Summary</label>
<label>{% trans 'Summary' %}</label>
<p>
You are creating a new rental from {{ start_date }} to {{ return_date }}
{% blocktrans trimmed %}
You are creating a new rental from {{ start_date }} to {{ return_date }}.
{% endblocktrans %}
</p>
<table class="table rental-summary">
<tr>
<th>Name</th>
<th>Location</th>
<th>Selected</th>
<th>{% trans 'Name' %}</th>
<th>{% trans 'Location' %}</th>
<th>{% trans 'Selected' %}</th>
</tr>
</table>
</div>

0 comments on commit af928a3

Please sign in to comment.