enable live-serving of i18n_static tag in debug (#1560)

* enable live-serving of i18n_static tag in debug

* style repair
This commit is contained in:
Matthias Mair 2021-05-07 15:18:06 +02:00 committed by GitHub
parent 5ed17022f2
commit bdd61fdb2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -200,18 +200,28 @@ class I18nStaticNode(StaticNode):
return ret
@register.tag('i18n_static')
def do_i18n_static(parser, token):
"""
Overrides normal static, adds language - lookup for prerenderd files #1485
# use the dynamic url - tag if in Debugging-Mode
if settings.DEBUG:
usage (like static):
{% i18n_static path [as varname] %}
"""
bits = token.split_contents()
loc_name = settings.STATICFILES_I18_PREFIX
@register.simple_tag()
def i18n_static(url_name):
""" simple tag to enable {% url %} functionality instead of {% static %} """
return reverse(url_name)
# change path to called ressource
bits[1] = f"'{loc_name}/{{lng}}.{bits[1][1:-1]}'"
token.contents = ' '.join(bits)
return I18nStaticNode.handle_token(parser, token)
else:
@register.tag('i18n_static')
def do_i18n_static(parser, token):
"""
Overrides normal static, adds language - lookup for prerenderd files #1485
usage (like static):
{% i18n_static path [as varname] %}
"""
bits = token.split_contents()
loc_name = settings.STATICFILES_I18_PREFIX
# change path to called ressource
bits[1] = f"'{loc_name}/{{lng}}.{bits[1][1:-1]}'"
token.contents = ' '.join(bits)
return I18nStaticNode.handle_token(parser, token)