Skip to content
This repository was archived by the owner on Aug 2, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include *.txt *.ini *.cfg *.rst
include LICENSE VERSION

recursive-include daybed *.py *.rx *.feature
recursive-include daybed *.py *.mo *.rx *.feature
global-exclude *.pyc
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ tests-failfast: install-dev

serve: install install-dev
$(VENV)/bin/pserve conf/development.ini --reload


makemessages: install install-dev
$(VENV)/bin/pot-create -o daybed/locale/daybed.pot daybed/
msgmerge --update daybed/locale/fr/LC_MESSAGES/daybed.po daybed/locale/daybed.pot

compilemessages:
msgfmt daybed/locale/fr/LC_MESSAGES/daybed.po -o daybed/locale/fr/LC_MESSAGES/daybed.mo
1 change: 1 addition & 0 deletions conf/development.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use = egg:daybed
pyramid.includes = pyramid_debugtoolbar
pyramid.debug_notfound = true
pyramid.default_locale_name = en

# Backend configuration
daybed.backend = daybed.backends.redis.RedisBackend
Expand Down
1 change: 1 addition & 0 deletions conf/docker.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[app:main]
use = egg:daybed
pyramid.default_locale_name = en

# Backend configuration
daybed.backend = ${BACKEND_ENGINE}
Expand Down
41 changes: 32 additions & 9 deletions daybed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@
import logging
import pkg_resources


#: Module version, as defined in PEP-0396.
__version__ = pkg_resources.get_distribution(__package__).version

logger = logging.getLogger(__name__)

import six
from cornice import Service
from pyramid import httpexceptions
from pyramid.config import Configurator
from pyramid.events import NewRequest
from pyramid.renderers import JSONP
from pyramid.authentication import BasicAuthAuthenticationPolicy
from pyramid.i18n import TranslationStringFactory

from pyramid_hawkauth import HawkAuthenticationPolicy
from pyramid_multiauth import MultiAuthenticationPolicy

#: Module version, as defined in PEP-0396.
__version__ = pkg_resources.get_distribution(__package__).version

# API main version
API_VERSION = 'v%s' % __version__.split('.')[0]

# Common logger
logger = logging.getLogger(__name__)

# Common TranslationString
TranslationString = TranslationStringFactory(__name__)


from daybed.permissions import (
RootFactory, DaybedAuthorizationPolicy, get_credentials, check_credentials
)
Expand All @@ -29,9 +37,6 @@
from daybed import indexer, events


API_VERSION = 'v%s' % __version__.split('.')[0]


def settings_expandvars(settings):
"""Expands all environment variables in a settings dictionary.
"""
Expand Down Expand Up @@ -170,6 +175,24 @@ def attach_objects_to_request(event):

config.add_subscriber(attach_objects_to_request, NewRequest)

# i18n

def set_default_locale(event):
request = event.request
if not request.accept_language:
return
available = ('en', 'fr')
accepted = request.accept_language
default = request.registry.settings.get('pyramid.default_locale_name')
request._LOCALE_ = accepted.best_match(available, default)
request.tr = request.localizer.translate

config.add_subscriber(set_default_locale, NewRequest)
config.add_translation_dirs(
'daybed:locale',
'colander:locale'
)

# Plugins

try:
Expand Down
108 changes: 108 additions & 0 deletions daybed/locale/daybed.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#
# SOME DESCRIPTIVE TITLE
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2014.
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE 1.0\n"
"POT-Creation-Date: 2014-11-06 00:13+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"
"Language: \n"

#: ./daybed/views/hello.py:12
msgid "hello"
msgstr ""

#: ./daybed/schemas/geom.py:126
msgid "A point"
msgstr ""

#: ./daybed/schemas/geom.py:141
msgid "A line made of points"
msgstr ""

#: ./daybed/schemas/geom.py:163
msgid "A polygon made of a closed line"
msgstr ""

#: ./daybed/schemas/geom.py:217
msgid "A GeoJSON geometry"
msgstr ""

#: ./daybed/schemas/object.py:34
msgid "An object"
msgstr ""

#: ./daybed/schemas/json.py:36
msgid "A JSON value"
msgstr ""

#: ./daybed/schemas/list.py:21
msgid "A list of objects"
msgstr ""

#: ./daybed/schemas/relations.py:43
msgid "A choice among records"
msgstr ""

#: ./daybed/schemas/relations.py:63
msgid "Some choices among records"
msgstr ""

#: ./daybed/schemas/base.py:39
msgid "An integer"
msgstr ""

#: ./daybed/schemas/base.py:45
msgid "A set of characters"
msgstr ""

#: ./daybed/schemas/base.py:51
msgid "A text"
msgstr ""

#: ./daybed/schemas/base.py:71
msgid "A decimal number"
msgstr ""

#: ./daybed/schemas/base.py:77
msgid "True or false"
msgstr ""

#: ./daybed/schemas/base.py:83
msgid "A choice among values"
msgstr ""

#: ./daybed/schemas/base.py:101
msgid "Some choices among values"
msgstr ""

#: ./daybed/schemas/base.py:119
msgid "A number with limits"
msgstr ""

#: ./daybed/schemas/base.py:139
msgid "A string matching a pattern"
msgstr ""

#: ./daybed/schemas/base.py:157
msgid "A valid email"
msgstr ""

#: ./daybed/schemas/base.py:169
msgid "A valid URL"
msgstr ""

#: ./daybed/schemas/base.py:213
msgid "A date (yyyy-mm-dd)"
msgstr ""

#: ./daybed/schemas/base.py:224
msgid "A date with time (yyyy-mm-ddTHH:MM)"
msgstr ""
Binary file added daybed/locale/fr/LC_MESSAGES/daybed.mo
Binary file not shown.
108 changes: 108 additions & 0 deletions daybed/locale/fr/LC_MESSAGES/daybed.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#
# French translations for PACKAGE package
# This file is distributed under the same license as the PACKAGE package.
# Mathieu Leplatre <[email protected]>, 2014.
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE 1.0\n"
"POT-Creation-Date: 2014-11-06 00:13+0100\n"
"PO-Revision-Date: 2014-11-06 00:13+0100\n"
"Last-Translator: Mathieu Leplatre <[email protected]>\n"
"Language-Team: French\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"

#: daybed/views/hello.py:12
msgid "hello"
msgstr "bonjour"

#: daybed/schemas/geom.py:126
msgid "A point"
msgstr "Un point"

#: daybed/schemas/geom.py:141
msgid "A line made of points"
msgstr "Une ligne faite de points"

#: daybed/schemas/geom.py:163
msgid "A polygon made of a closed line"
msgstr "Un polygone fait d'une ligne fermée"

#: daybed/schemas/geom.py:217
msgid "A GeoJSON geometry"
msgstr "Une géométrie GeoJSON"

#: daybed/schemas/object.py:34
msgid "An object"
msgstr "Un objet"

#: daybed/schemas/json.py:36
msgid "A JSON value"
msgstr "Une valeur JSON"

#: daybed/schemas/list.py:21
msgid "A list of objects"
msgstr "Une liste d'objets"

#: daybed/schemas/relations.py:43
msgid "A choice among records"
msgstr "Un choix parmi des enregistrements"

#: daybed/schemas/relations.py:63
msgid "Some choices among records"
msgstr "Des choix parmi des enregistrements"

#: daybed/schemas/base.py:39
msgid "An integer"
msgstr "Un entier"

#: daybed/schemas/base.py:45
msgid "A set of characters"
msgstr "Une chaîne de caractères"

#: daybed/schemas/base.py:51
msgid "A text"
msgstr "Un texte"

#: daybed/schemas/base.py:71
msgid "A decimal number"
msgstr "Un nombre décimal"

#: daybed/schemas/base.py:77
msgid "True or false"
msgstr "Vrai ou Faux"

#: daybed/schemas/base.py:83
msgid "A choice among values"
msgstr "Un choix parmi des valeurs"

#: daybed/schemas/base.py:101
msgid "Some choices among values"
msgstr "Des choix parmi des valeurs"

#: daybed/schemas/base.py:119
msgid "A number with limits"
msgstr "Un nombre borné"

#: daybed/schemas/base.py:139
msgid "A string matching a pattern"
msgstr "Une chaîne respectant un masque"

#: daybed/schemas/base.py:157
msgid "A valid email"
msgstr "Un email valide"

#: daybed/schemas/base.py:169
msgid "A valid URL"
msgstr "Une URL valide"

#: daybed/schemas/base.py:213
msgid "A date (yyyy-mm-dd)"
msgstr "Une date (aaaa-mm-jj)"

#: daybed/schemas/base.py:224
msgid "A date with time (yyyy-mm-ddTHH:MM)"
msgstr "Une date avec heure (aaaa-mm-jjTHH:MM)"
2 changes: 1 addition & 1 deletion daybed/schemas/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import datetime

from pyramid.i18n import TranslationString as _
from daybed import TranslationString as _
from colander import (
deferred,
SchemaNode,
Expand Down
2 changes: 1 addition & 1 deletion daybed/schemas/geom.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import absolute_import
import json

from pyramid.i18n import TranslationString as _
from daybed import TranslationString as _
import six
from colander import (
SchemaNode,
Expand Down
2 changes: 1 addition & 1 deletion daybed/schemas/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
import json

from pyramid.i18n import TranslationString as _
from daybed import TranslationString as _
import six
from colander import Sequence, null, Invalid, List, Mapping

Expand Down
2 changes: 1 addition & 1 deletion daybed/schemas/list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyramid.i18n import TranslationString as _
from daybed import TranslationString as _
from colander import SchemaNode, Sequence, drop

from . import TypeFieldNode
Expand Down
2 changes: 1 addition & 1 deletion daybed/schemas/object.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import six

from pyramid.i18n import TranslationString as _
from daybed import TranslationString as _
from colander import (Sequence, SchemaNode, Length, String, drop, Invalid)

from daybed.backends.exceptions import ModelNotFound
Expand Down
2 changes: 1 addition & 1 deletion daybed/schemas/relations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import six
from pyramid.i18n import TranslationString as _
from daybed import TranslationString as _
from colander import (String, SchemaNode, Invalid)

from daybed.backends.exceptions import ModelNotFound, RecordNotFound
Expand Down
2 changes: 1 addition & 1 deletion daybed/schemas/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def validate_against_schema(request, schema, data):
except Invalid as e:
# here we transform the errors we got from colander into cornice
# errors
for field, error in e.asdict().items():
for field, error in e.asdict(translate=request.tr).items():
request.errors.add('body', field, error)


Expand Down
Loading