aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2011-08-10 10:51:44 -0500
committerChristopher Allan Webber <cwebber@dustycloud.org>2011-08-10 10:51:44 -0500
commitc22d624af3cc473d3b31baaf6f1a32a498a949e0 (patch)
tree40cc9bbe9c6df4851e0e5f07fe747e7afa29665c
parentff0e4fd52b680a13ac75756ec3f8a883bed9f535 (diff)
parentdb3e0583494f201c663c7d037410011da951666b (diff)
downloadmediagoblin-c22d624af3cc473d3b31baaf6f1a32a498a949e0.tar.lz
mediagoblin-c22d624af3cc473d3b31baaf6f1a32a498a949e0.tar.xz
mediagoblin-c22d624af3cc473d3b31baaf6f1a32a498a949e0.zip
Merge branch 'mergeme'
-rw-r--r--mediagoblin/templates/mediagoblin/utils/wtforms.html10
-rw-r--r--mediagoblin/util.py48
2 files changed, 52 insertions, 6 deletions
diff --git a/mediagoblin/templates/mediagoblin/utils/wtforms.html b/mediagoblin/templates/mediagoblin/utils/wtforms.html
index 1d2f8619..e3d8e137 100644
--- a/mediagoblin/templates/mediagoblin/utils/wtforms.html
+++ b/mediagoblin/templates/mediagoblin/utils/wtforms.html
@@ -19,9 +19,9 @@
{# Generically render a field #}
{% macro render_field_div(field) %}
<div class="form_field_box">
- <div class="form_field_label">{{ field.label }}</div>
+ <div class="form_field_label">{{ _(field.label.text) }}</div>
{% if field.description -%}
- <div class="form_field_description">{{ field.description }}</div>
+ <div class="form_field_description">{{ _(field.description) }}</div>
{%- endif %}
<div class="form_field_input">{{ field }}</div>
{%- if field.errors -%}
@@ -38,9 +38,9 @@
# ... mostly the same thing except it includes rows and cols #}
{% macro render_textarea_div(field, rows=8, cols=20) %}
<div class="form_field_box">
- <div class="form_field_label">{{ field.label }}</div>
+ <div class="form_field_label">{{ _(field.label.text) }}</div>
{% if field.description -%}
- <div class="form_field_description">{{ field.description }}</div>
+ <div class="form_field_description">{{ _(field.description) }}</div>
{%- endif %}
<div class="form_field_input">{{ field(rows=rows, cols=cols) }}</div>
{%- if field.errors -%}
@@ -64,7 +64,7 @@
{% macro render_table(form) -%}
{% for field in form %}
<tr>
- <th>{{field.label}}</th>
+ <th>{{ _(field.label.text) }}</th>
<td>
{{field}}
{% if field.errors %}
diff --git a/mediagoblin/util.py b/mediagoblin/util.py
index ed7be841..b46c65d9 100644
--- a/mediagoblin/util.py
+++ b/mediagoblin/util.py
@@ -28,11 +28,13 @@ import copy
import wtforms
from babel.localedata import exists
+from babel.support import LazyProxy
import jinja2
import translitcodec
from webob import Response, exc
from lxml.html.clean import Cleaner
import markdown
+from wtforms.form import Form
from mediagoblin import mg_globals
from mediagoblin import messages
@@ -94,7 +96,7 @@ def get_jinja_env(template_loader, locale):
template_env.install_gettext_callables(
mg_globals.translations.ugettext,
- mg_globals.translations.ngettext)
+ mg_globals.translations.ungettext)
# All templates will know how to ...
# ... fetch all waiting messages and remove them from the queue
@@ -494,6 +496,50 @@ def pass_to_ugettext(*args, **kwargs):
*args, **kwargs)
+def lazy_pass_to_ugettext(*args, **kwargs):
+ """
+ Lazily pass to ugettext.
+
+ This is useful if you have to define a translation on a module
+ level but you need it to not translate until the time that it's
+ used as a string.
+ """
+ return LazyProxy(pass_to_ugettext, *args, **kwargs)
+
+
+def pass_to_ngettext(*args, **kwargs):
+ """
+ Pass a translation on to the appropriate ngettext method.
+
+ The reason we can't have a global ngettext method is because
+ mg_globals gets swapped out by the application per-request.
+ """
+ return mg_globals.translations.ngettext(
+ *args, **kwargs)
+
+
+def lazy_pass_to_ngettext(*args, **kwargs):
+ """
+ Lazily pass to ngettext.
+
+ This is useful if you have to define a translation on a module
+ level but you need it to not translate until the time that it's
+ used as a string.
+ """
+ return LazyProxy(pass_to_ngettext, *args, **kwargs)
+
+
+def fake_ugettext_passthrough(string):
+ """
+ Fake a ugettext call for extraction's sake ;)
+
+ In wtforms there's a separate way to define a method to translate
+ things... so we just need to mark up the text so that it can be
+ extracted, not so that it's actually run through gettext.
+ """
+ return string
+
+
PAGINATION_DEFAULT_PER_PAGE = 30
class Pagination(object):