Permalink
Browse files

Add translations and passing lang via middleware

This patch adds some translations for the validator messages, and a way
to pass a get_lang function instead of a translator function via
middleware configuration.
  • Loading branch information...
Cito committed Oct 2, 2012
1 parent e4f2982 commit a10a14e260aa0f459d8586f4066c7c2519a2f58c
@@ -4,6 +4,8 @@ Thumbs.db
docs/.output/
.coverage
.noseids
.project
.pydevproject
html
dist
build
@@ -4,6 +4,8 @@ glob:Thumbs.db
glob:docs/.output/
glob:.coverage
glob:.noseids
glob:.project
glob:.pydevproject
glob:html
glob:dist
glob:build
@@ -6,3 +6,25 @@ with-coverage = true
cover-package = tw2.core
cover-html = true
cover-html-dir = htmlcov
[compile_catalog]
domain = tw2core
directory = tw2/core/i18n
statistics = true
[extract_messages]
add_comments = TRANSLATORS:
output_file = tw2/core/i18n/tw2core.pot
width = 80
keywords = l_
[init_catalog]
domain = tw2core
input_file = tw2/core/i18n/tw2core.pot
output_dir = tw2/core/i18n
[update_catalog]
domain = tw2core
input_file = tw2/core/i18n/tw2core.pot
output_dir = tw2/core/i18n
previous = true
@@ -1,12 +1,43 @@
import gettext
import os
try:
from pkg_resources import resource_filename
except ImportError:
resource_filename = None
from speaklater import make_lazy_string
import core
import traceback
import logging
log = logging.getLogger(__name__)
def get_localedir():
"""Get the location of locales."""
locale_dir = ''
if resource_filename is not None:
try:
locale_dir = resource_filename(__name__, "/i18n")
except NotImplementedError:
pass
if not hasattr(os, 'access'):
return os.path.join(os.path.dirname(__file__), 'i18n')
if os.access(locale_dir, os.R_OK | os.X_OK):
return locale_dir
locale_dir = os.path.join(os.path.dirname(__file__), 'i18n')
if not os.access(locale_dir, os.R_OK | os.X_OK):
locale_dir = os.path.normpath('/usr/share/locale')
return locale_dir
def get_translator(lang=None, domain='tw2core', localedir=get_localedir()):
return gettext.translation(domain=domain, languages=lang,
localedir=localedir, fallback=True).ugettext
def tw2_translation_string(sval):
def lookup_provided_translator(_sval):
@@ -15,13 +46,18 @@ def lookup_provided_translator(_sval):
return _sval
try:
return core.request_local()['middleware'].config.translator(_sval)
except TypeError:
log.warn(traceback.format_exc())
return _sval
translator = get_translator(mw.config.get_lang())
except AttributeError:
try:
translator = mw.config.translator
except AttributeError:
return _sval
return translator(_sval)
return make_lazy_string(lambda: lookup_provided_translator(sval))
_ = tw2_translation_string
__all__ = [
Binary file not shown.
@@ -0,0 +1,112 @@
# German translations for tw2.core.
# Copyright (C) 2012 ORGANIZATION
# This file is distributed under the same license as the tw2.core project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2012.
# Christoph Zwerschke <cito@online.de>, 2012.
msgid ""
msgstr ""
"Project-Id-Version: tw2.core 2.1.2\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2012-10-02 00:21+0200\n"
"PO-Revision-Date: 2012-10-02 02:10+0200\n"
"Last-Translator: Christoph Zwerschke <cito@online.de>\n"
"Language-Team: German <toscawidgets-discuss@googlegroups.com>\n"
"Language: de\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 0.9.6\n"
#: tw2/core/validation.py:181
msgid "Enter a value"
msgstr "Bitte einen Wert eingeben"
#: tw2/core/validation.py:182
msgid "Received in wrong character set; should be $encoding"
msgstr "In falschem Zeichensatz empfangen; sollte $encoding sein"
#: tw2/core/validation.py:183
msgid "Form submission received corrupted; please try again"
msgstr ""
"Formulardaten wurden nicht richtig empfangen; bitte noch einmal versuchen"
#: tw2/core/validation.py:240
msgid "Value is too short"
msgstr "Wert ist zu kurz"
#: tw2/core/validation.py:241
msgid "Value is too long"
msgstr "Wert ist zu lang"
#: tw2/core/validation.py:262
msgid "Must be at least $min characters"
msgstr "Muss mindestens $min Zeichen haben"
#: tw2/core/validation.py:264
msgid "Cannot be longer than $max characters"
msgstr "Darf nicht mehr als $max Zeichen haben"
#: tw2/core/validation.py:275
msgid "Select at least $min"
msgstr "Wählen Sie mindestens $min"
#: tw2/core/validation.py:276
msgid "Select no more than $max"
msgstr "Wählen Sie höchstens $max"
#: tw2/core/validation.py:292
msgid "Must be at least $min"
msgstr "Muss mindestens $min sein"
#: tw2/core/validation.py:293
msgid "Cannot be more than $max"
msgstr "Darf höchstens $max sein"
#: tw2/core/validation.py:312
msgid "Must be an integer"
msgstr "Muss eine ganze Zahl sein"
#: tw2/core/validation.py:347
msgid "You must select this"
msgstr "Sie müssen dies auswählen"
#: tw2/core/validation.py:364 tw2/core/validation.py:462
msgid "Invalid value"
msgstr "Ungültiger Wert"
#: tw2/core/validation.py:384
msgid "Must follow date format $format_str"
msgstr "Muss dem Datumsformat $format_str entsprechen"
#: tw2/core/validation.py:385
msgid "Cannot be earlier than $min_str"
msgstr "Darf nicht früher als $min_str sein"
#: tw2/core/validation.py:386
msgid "Cannot be later than $max_str"
msgstr "Darf nicht später als $max_str sein"
#: tw2/core/validation.py:440
msgid "Must follow date/time format $format_str"
msgstr "Muss dem Datums/Zeitformat $format_str entsprechen"
#: tw2/core/validation.py:477
msgid "Must be a valid email address"
msgstr "Bitte eine gültige E-Mail-Adresse eing"
#: tw2/core/validation.py:487
msgid "Must be a valid URL"
msgstr "Bitte eine gültige URL eingeben"
#: tw2/core/validation.py:506
msgid "Must be a valid IP address"
msgstr "Bitte eine gültige IP-Adresse eingeben"
#: tw2/core/validation.py:507
msgid "Must be a valid IP network block"
msgstr "Bitte einen gültigen IP-Netzwerkblock eingeben"
#: tw2/core/validation.py:532
msgid "Must match $other_field_str"
msgstr "Muss mit $other_field_str übereinstimmen"
Binary file not shown.
@@ -0,0 +1,112 @@
# French translations for tw2.core.
# Copyright (C) 2012 ORGANIZATION
# This file is distributed under the same license as the tw2.core project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2012.
# Christoph Zwerschke <cito@online.de>, 2012.
msgid ""
msgstr ""
"Project-Id-Version: tw2.core 2.1.2\n"
"Report-Msgid-Bugs-To: toscawidgets-discuss@googlegroups.com\n"
"POT-Creation-Date: 2012-10-02 00:21+0200\n"
"PO-Revision-Date: 2012-10-02 02:02+0200\n"
"Last-Translator: Christoph Zwerschke <cito@online.de>\n"
"Language-Team: French <toscawidgets-discuss@googlegroups.com>\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 0.9.6\n"
#: tw2/core/validation.py:181
msgid "Enter a value"
msgstr "Saisissez une valeur"
#: tw2/core/validation.py:182
msgid "Received in wrong character set; should be $encoding"
msgstr "Reçu en jeu de caractères incorrect; doit être $encoding"
#: tw2/core/validation.py:183
msgid "Form submission received corrupted; please try again"
msgstr ""
"Soumission du formulaire reçu corrompue; s'il vous plaît essayer à nouveau"
#: tw2/core/validation.py:240
msgid "Value is too short"
msgstr "Valeur est trop court"
#: tw2/core/validation.py:241
msgid "Value is too long"
msgstr "Valeur est trop longue"
#: tw2/core/validation.py:262
msgid "Must be at least $min characters"
msgstr "Doit avoir au moins $min caractères"
#: tw2/core/validation.py:264
msgid "Cannot be longer than $max characters"
msgstr "Ne doit pas dépasser $max caractères"
#: tw2/core/validation.py:275
msgid "Select at least $min"
msgstr "Choisissez au moins $min"
#: tw2/core/validation.py:276
msgid "Select no more than $max"
msgstr "Choisissez au plus $max"
#: tw2/core/validation.py:292
msgid "Must be at least $min"
msgstr "Doit être d'au moins $min"
#: tw2/core/validation.py:293
msgid "Cannot be more than $max"
msgstr "Ne doit pas être plus de $max"
#: tw2/core/validation.py:312
msgid "Must be an integer"
msgstr "Doit être un entier"
#: tw2/core/validation.py:347
msgid "You must select this"
msgstr "Vous devez sélectionner ceci"
#: tw2/core/validation.py:364 tw2/core/validation.py:462
msgid "Invalid value"
msgstr "Valeur incorrecte"
#: tw2/core/validation.py:384
msgid "Must follow date format $format_str"
msgstr "Doit respecter le format de date $format_str"
#: tw2/core/validation.py:385
msgid "Cannot be earlier than $min_str"
msgstr "Ne peut pas être antérieure à $min_str"
#: tw2/core/validation.py:386
msgid "Cannot be later than $max_str"
msgstr "Ne peut pas être postérieure à $max_str"
#: tw2/core/validation.py:440
msgid "Must follow date/time format $format_str"
msgstr "Doit respecter le format de date/heure $format_str"
#: tw2/core/validation.py:477
msgid "Must be a valid email address"
msgstr "Veuillez entrer une adresse valide"
#: tw2/core/validation.py:487
msgid "Must be a valid URL"
msgstr "Veuillez entrer une URL valide"
#: tw2/core/validation.py:506
msgid "Must be a valid IP address"
msgstr "Veuillez entrer une adresse IP valide"
#: tw2/core/validation.py:507
msgid "Must be a valid IP network block"
msgstr "Veuillez entrer un bloc des adresses IP valide"
#: tw2/core/validation.py:532
msgid "Must match $other_field_str"
msgstr "Doit correspondre à $other_field_str"
Binary file not shown.
Oops, something went wrong.

0 comments on commit a10a14e

Please sign in to comment.