Skip to content

Commit

Permalink
Skeleton for the internationalization.
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricbonhomme committed May 22, 2018
1 parent 739ae42 commit 796c7fb
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ syntax: glob
*~
*.db

*.mo

# Emacs
eproject.cfg
*#
Expand Down
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Flask-paginate = "*"
Flask-Mail = "*"
WTForms = "*"
validate_email = "*"
flask-babel = "*"

[dev-packages]
sqlalchemy-schemadisplay = "*"
24 changes: 23 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "MOSP",
"description": "A platform to create, edit and share JSON objects.",
"keywords": [
"MOSP",
"json",
"json-schema"
],
"website": "https://github.com/cedricbonhomme/MOSP",
"repository": "https://github.com/cedricbonhomme/MOSP",
"scripts": {
"postdeploy": "pybabel compile -d src/web/translations"
},
"addons": [
"heroku-postgresql:hobby-dev"
],
"buildpacks": [
{
"url": "https://github.com/heroku/heroku-buildpack-nodejs"
},
{
"url": "heroku/python"
}
],
"env": {
"APPLICATION_SETTINGS": {
"description": "Configuration file for Heroku",
"required": true,
"value": "heroku.cfg"
},
}
}
26 changes: 23 additions & 3 deletions src/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import os
import errno
import logging
import flask_restless
from flask import Flask, request
from flask_sqlalchemy import SQLAlchemy
import flask_restless
from flask_mail import Mail
from flask_babel import Babel, gettext

# from flask_mail import Mail


def set_logging(log_path=None, log_level=logging.INFO, modules=(),
Expand Down Expand Up @@ -49,7 +51,25 @@ def set_logging(log_path=None, log_level=logging.INFO, modules=(),
'APPLICATION_SETTINGS',
'development.cfg'), silent=False)
db = SQLAlchemy(application)
mail = Mail(application)
# mail = Mail(application)

babel = Babel(application)
@babel.localeselector
def get_locale():
# if a user is logged in, use the locale from the user settings
# user = getattr(g, 'user', None)
# if user is not None:
# return user.locale
# otherwise try to guess the language from the user accept
# header the browser transmits. We support de/fr/en in this
# example. The best match wins.
return request.accept_languages.best_match(['fr', 'en'])

# @babel.timezoneselector
# def get_timezone():
# user = getattr(g, 'user', None)
# if user is not None:
# return user.timezone


# Jinja filters
Expand Down
4 changes: 2 additions & 2 deletions src/web/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<div class="container">
<div class="row">
<div class="col">
<h4>Recently updated schemas</h4>
<h4>{{ _('Recently updated schemas') }}</h4>
<div id="list-schemas"></div>
</div>
<div class="col">
<h4>Recently updated objects</h4>
<h4>{{ _('Recently updated objects') }}</h4>
<div id="list-json-objects"></div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/web/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<div class="container-fluid">
<div class="row">
<div class="col-md-10 text-white">
Create, edit and share JSON objects&nbsp;🐘&nbsp;GNU Affero General Public License&nbsp;🐘&nbsp;<a href="{{ url_for('about') }}">About</a>
{{ _('Create, edit and share JSON objects') }}&nbsp;🐘&nbsp;GNU Affero General Public License&nbsp;🐘&nbsp;<a href="{{ url_for('about') }}">About</a>
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/web/translations/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_
32 changes: 32 additions & 0 deletions src/web/translations/fr/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# French translations for PROJECT.
# Copyright (C) 2018 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2018.
#
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2018-05-22 11:25+0200\n"
"PO-Revision-Date: 2018-05-22 11:26+0200\n"
"Last-Translator: \n"
"Language-Team: fr <LL@li.org>\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"Generated-By: Babel 2.5.3\n"
"X-Generator: Poedit 2.0.6\n"

#: src/web/templates/index.html:10
msgid "Recently updated schemas"
msgstr "Schémas récemment mis à jour"

#: src/web/templates/index.html:14
msgid "Recently updated objects"
msgstr "Objets récemment mis à jour"

#: src/web/templates/layout.html:88
msgid "Create, edit and share JSON objects"
msgstr "Créer, modifier et partager des objets JSON"
4 changes: 4 additions & 0 deletions src/web/translations/internationalization.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#! /bin/sh

pybabel extract -F src/web/translations/babel.cfg -k lazy_gettext -o src/web/translations/messages.pot src/web/
poedit src/web/translations/fr/LC_MESSAGES/messages.po
31 changes: 31 additions & 0 deletions src/web/translations/messages.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Translations template for PROJECT.
# Copyright (C) 2018 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2018.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2018-05-22 11:25+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.5.3\n"

#: src/web/templates/index.html:10
msgid "Recently updated schemas"
msgstr ""

#: src/web/templates/index.html:14
msgid "Recently updated objects"
msgstr ""

#: src/web/templates/layout.html:88
msgid "Create, edit and share JSON objects"
msgstr ""

0 comments on commit 796c7fb

Please sign in to comment.