summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2021-08-17 01:57:27 +0200
committerDaniel Schadt <kingdread@gmx.de>2021-08-17 01:57:27 +0200
commitda34930854d0759ada6fe2727f2e1a159f6b4fdb (patch)
tree1f0aeac3b63fd1a48977284b4ecc55df3d48a534
parent1543a13c880bf22037466109cbd77b2d0c9f21c3 (diff)
downloadwikimini-da34930854d0759ada6fe2727f2e1a159f6b4fdb.tar.gz
wikimini-da34930854d0759ada6fe2727f2e1a159f6b4fdb.tar.bz2
wikimini-da34930854d0759ada6fe2727f2e1a159f6b4fdb.zip
add {{lang-XX}}, {{IPA-XX}} and {{XXX}} templates
-rw-r--r--setup.py1
-rw-r--r--wikimini/templates/language.py41
2 files changed, 42 insertions, 0 deletions
diff --git a/setup.py b/setup.py
index 5af6a59..645d023 100644
--- a/setup.py
+++ b/setup.py
@@ -11,5 +11,6 @@ setuptools.setup(
"requests",
"mwparserfromhell",
"tabulate",
+ "pycountry",
],
)
diff --git a/wikimini/templates/language.py b/wikimini/templates/language.py
index 052b7f0..e8ab738 100644
--- a/wikimini/templates/language.py
+++ b/wikimini/templates/language.py
@@ -1,6 +1,8 @@
"""Language related templates."""
from . import registry
+import pycountry
+
def tmpl_ipa(wikimini, obj):
"""Renders the ``{{IPA|...}}`` template."""
@@ -17,3 +19,42 @@ def tmpl_lang(wikimini, obj):
registry.insert("lang", tmpl_lang)
registry.insert("script", tmpl_lang)
+
+
+def tmpl_lang_code(language_name):
+ """Creates a template renderer for a ``{{lang-xx|...}}`` template."""
+ def inner(wikimini, obj):
+ return "{}: {}".format(
+ language_name, wikimini._convert(obj.params[0].value)
+ )
+ return inner
+
+
+def tmpl_ipa_code(language_name):
+ """Creates a template renderer for a ``{{IPA-xx|...}}`` template."""
+ def inner(wikimini, obj):
+ return "{} pronunciation: [{}]".format(
+ language_name, wikimini._convert(obj.params[0].value)
+ )
+ return inner
+
+
+for language in pycountry.languages:
+ if hasattr(language, "alpha_2"):
+ registry.insert(
+ f"lang-{language.alpha_2}", tmpl_lang_code(language.name)
+ )
+ registry.insert(
+ f"IPA-{language.alpha_2}", tmpl_ipa_code(language.name)
+ )
+
+
+def tmpl_country_flag(country):
+ """Creates a template renderer for ``{{BRA}}`` country flags."""
+ def inner(wikimini, obj):
+ return country
+ return inner
+
+
+for country in pycountry.countries:
+ registry.insert(country.alpha_3, tmpl_country_flag(country.name))