diff options
author | Daniel Schadt <kingdread@gmx.de> | 2021-08-17 01:57:27 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2021-08-17 01:57:27 +0200 |
commit | da34930854d0759ada6fe2727f2e1a159f6b4fdb (patch) | |
tree | 1f0aeac3b63fd1a48977284b4ecc55df3d48a534 | |
parent | 1543a13c880bf22037466109cbd77b2d0c9f21c3 (diff) | |
download | wikimini-da34930854d0759ada6fe2727f2e1a159f6b4fdb.tar.gz wikimini-da34930854d0759ada6fe2727f2e1a159f6b4fdb.tar.bz2 wikimini-da34930854d0759ada6fe2727f2e1a159f6b4fdb.zip |
add {{lang-XX}}, {{IPA-XX}} and {{XXX}} templates
-rw-r--r-- | setup.py | 1 | ||||
-rw-r--r-- | wikimini/templates/language.py | 41 |
2 files changed, 42 insertions, 0 deletions
@@ -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)) |