Create set_thread_locale and use it.
Setting up a new template env should not directly touch the translation tools, but go through a function in translations.py.
This commit is contained in:
parent
c82a8ba54f
commit
50cb512220
@ -14,7 +14,6 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from math import ceil
|
|
||||||
|
|
||||||
import jinja2
|
import jinja2
|
||||||
from jinja2.ext import Extension
|
from jinja2.ext import Extension
|
||||||
@ -27,7 +26,7 @@ from mediagoblin import mg_globals
|
|||||||
from mediagoblin import messages
|
from mediagoblin import messages
|
||||||
from mediagoblin import _version
|
from mediagoblin import _version
|
||||||
from mediagoblin.tools import common
|
from mediagoblin.tools import common
|
||||||
from mediagoblin.tools.translate import get_gettext_translation
|
from mediagoblin.tools.translate import set_thread_locale
|
||||||
from mediagoblin.tools.pluginapi import get_hook_templates
|
from mediagoblin.tools.pluginapi import get_hook_templates
|
||||||
from mediagoblin.tools.timesince import timesince
|
from mediagoblin.tools.timesince import timesince
|
||||||
from mediagoblin.meddleware.csrf import render_csrf_form_token
|
from mediagoblin.meddleware.csrf import render_csrf_form_token
|
||||||
@ -44,7 +43,7 @@ def get_jinja_env(template_loader, locale):
|
|||||||
(In the future we may have another system for providing theming;
|
(In the future we may have another system for providing theming;
|
||||||
for now this is good enough.)
|
for now this is good enough.)
|
||||||
"""
|
"""
|
||||||
mg_globals.thread_scope.translations = get_gettext_translation(locale)
|
set_thread_locale(locale)
|
||||||
|
|
||||||
# If we have a jinja environment set up with this locale, just
|
# If we have a jinja environment set up with this locale, just
|
||||||
# return that one.
|
# return that one.
|
||||||
|
@ -112,6 +112,11 @@ def get_gettext_translation(locale):
|
|||||||
return this_gettext
|
return this_gettext
|
||||||
|
|
||||||
|
|
||||||
|
def set_thread_locale(locale):
|
||||||
|
"""Set the current translation for this thread"""
|
||||||
|
mg_globals.thread_scope.translations = get_gettext_translation(locale)
|
||||||
|
|
||||||
|
|
||||||
def pass_to_ugettext(*args, **kwargs):
|
def pass_to_ugettext(*args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Pass a translation on to the appropriate ugettext method.
|
Pass a translation on to the appropriate ugettext method.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user