Add a filter for getting language name from code

This adds a requirement on the Babel module in python.
This commit is contained in:
Magnus Hagander
2020-10-27 13:22:09 +01:00
parent bc1c7fa1ea
commit f4d7c746fd
2 changed files with 10 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import os
from pathlib import Path
import json
import pynliner
import babel
register = template.Library()
@ -113,6 +114,14 @@ def list_templates(value):
yield f.stem
@register.filter()
def languagename(lang):
try:
return babel.Locale(lang).english_name
except Exception:
return lang
@register.simple_tag(takes_context=True)
def git_changes_link(context):
return mark_safe('<a href="https://git.postgresql.org/gitweb/?p=pgweb.git;a=history;f=templates/{}">View</a> change history.'.format(context.template_name))

View File

@ -8,3 +8,4 @@ cvss==2.1
pytidylib==0.3.2
pycodestyle==2.4.0
pynliner==0.8.0
Babel=2.6.0