Skip to content

Commit

Permalink
Foundations of i18n system
Browse files Browse the repository at this point in the history
  • Loading branch information
yohanboniface committed Jan 5, 2014
1 parent b75f92e commit 3cd5dd7
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 11 deletions.
3 changes: 3 additions & 0 deletions babel.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[python: **.py]
[jinja2: **/templates/**.html]
extensions=jinja2.ext.autoescape,jinja2.ext.with_
35 changes: 35 additions & 0 deletions messages.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Translations template for PROJECT.
# Copyright (C) 2014 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2014.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2014-01-05 12:56+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 1.3\n"

#: piati/helpers.py:73
msgid "funding"
msgstr ""

#: piati/helpers.py:74
msgid "extending"
msgstr ""

#: piati/helpers.py:75
msgid "implementing"
msgstr ""

#: piati/helpers.py:76
msgid "reporting"
msgstr ""

3 changes: 0 additions & 3 deletions piati/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import re

from lxml import etree

from flask import Flask, render_template
Expand All @@ -10,7 +8,6 @@

app = Flask(__name__)


DATA = {}


Expand Down
1 change: 1 addition & 0 deletions piati/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
DEFAULT_MAP_ZOOM = 6
SITE_NAME = "L'aide française au Mali"
SITE_BASELINE = "Suivez l'aide au développement au Mali."
BABEL_DEFAULT_LOCALE = "fr"
12 changes: 12 additions & 0 deletions piati/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import requests

from flask.ext.babel import gettext as _


def fetch_remote_data(url, filepath):
try:
Expand Down Expand Up @@ -66,6 +68,16 @@ def getDateType(value):
return ""


def getRoleType(role):
roles = {
'Funding': _('funding'),
'Extending': _('extending'),
'Implementing': _('implementing'),
'Reporting': _('reporting'),
}
return roles.get(role, role)


def makeIdentifierSafe(identifier):
identifier = re.sub("/", "___", identifier)
identifier = re.sub(":", ">>>", identifier)
Expand Down
6 changes: 3 additions & 3 deletions piati/iati.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from flask import url_for

from .helpers import getDateType
from .helpers import getDateType, getRoleType


class Project(object):
Expand Down Expand Up @@ -70,7 +70,7 @@ def make(node):
return {
"name": node.text,
"ref": node.attrib.get('ref'),
"role": node.attrib.get('role'),
"role": getRoleType(node.attrib.get('role')),
"type": node.attrib.get('type'),
}
return [make(node) for node in self._xml.xpath('participating-org')]
Expand All @@ -82,7 +82,7 @@ def reporting_org(self):
return {
"name": org.text,
"ref": org.attrib.get('ref'),
"role": "Reporting",
"role": getRoleType("Reporting"),
"type": org.attrib.get('type'),
}

Expand Down
6 changes: 3 additions & 3 deletions piati/templates/project.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h1>{{ project.name }}</h1>
<th>Role</th>
</thead>
{% for org in project.participating_org + [project.reporting_org] %}
<tr class="{{ loop.cycle('odd', 'even') }}"><td>{{ org.name }}</td><td>{{ org.role }}</td></tr>
<tr class="{{ loop.cycle('odd', 'even') }}"><td><a href="{{ url_for('show_projects') }}#?orgs={{ org.name }}">{{ org.name }}</a></td><td>{{ org.role }}</td></tr>
{% endfor %}
</table>
<hr />
Expand All @@ -46,8 +46,8 @@ <h1>{{ project.name }}</h1>
<nav class="tabs"><!--
--><a href="#tab-map" class="on">Carte</a><!--
--><a href="#tab-data">Vue d'ensemble</a><!--
--><a href="#tab-financial">Données financières</a>
</nav>
--><a href="#tab-financial">Données financières</a><!--
--></nav>
<div id="tab-map" class="map tab-content on"></div>

<div id="tab-data" class="tab-content">
Expand Down
Binary file added piati/translations/fr/LC_MESSAGES/messages.mo
Binary file not shown.
34 changes: 34 additions & 0 deletions piati/translations/fr/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# French translations for PROJECT.
# Copyright (C) 2014 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2014.
#
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2014-01-05 12:56+0100\n"
"PO-Revision-Date: 2014-01-05 12:31+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: fr <[email protected]>\n"
"Plural-Forms: nplurals=2; plural=(n > 1)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 1.3\n"

#: piati/helpers.py:73
msgid "funding"
msgstr "financier"

#: piati/helpers.py:74
msgid "extending"
msgstr ""

#: piati/helpers.py:75
msgid "implementing"
msgstr "organisme d'exécution"

#: piati/helpers.py:76
msgid "reporting"
msgstr "rapporteur"
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
Babel==1.3
docopt==0.6.1
Flask-Babel==0.9
Flask==0.10.1
Frozen-Flask==0.11
itsdangerous==0.23
Jinja2==2.7.1
lxml==3.2.4
MarkupSafe==0.18
pytz==2013.9
requests==2.1.0
simplejson==3.3.1
speaklater==1.3
Werkzeug==0.9.4
16 changes: 14 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
Usage:
run.py serve [--port=<number>] [--host=<string>] [options]
run.py static [--port=<number>] [--host=<string>] [options]
run.py fetch
run.py build
run.py fetch [options]
run.py build [options]
run.py i18n (extract|update|compile) [options]
Examples:
python run.py serve --port 5432 --debug
Expand All @@ -22,6 +23,8 @@

from docopt import docopt
from flask_frozen import Freezer
from flask.ext.babel import Babel
from babel.messages.frontend import CommandLineInterface

from piati.app import app, load_data
from piati.helpers import fetch_remote_data, get_data_filepath
Expand All @@ -40,6 +43,7 @@ def get_option(option, default=None):
if args["--settings"]:
app.config.from_object(args['--settings'])
freezer = Freezer(app)
babel = Babel(app)
if not args['fetch']:
load_data()

Expand All @@ -61,3 +65,11 @@ def get_option(option, default=None):
port=int(args['--port']),
host=args['--host']
)
elif args['i18n']:
if args['extract']:
babel_args = ['', 'extract', '-F', 'babel.cfg', '-o', 'messages.pot', '.']
elif args['compile']:
babel_args = ['', 'compile', '-d', 'piati/translations']
elif args['update']:
babel_args = ['', 'update', '-i', 'messages.pot', '-d', 'piati/translations']
CommandLineInterface().run(babel_args)

0 comments on commit 3cd5dd7

Please sign in to comment.