Skip to content

Instantly share code, notes, and snippets.

@bmispelon
Created April 17, 2024 20:37
Show Gist options
  • Save bmispelon/a203f65f9498bef6f997bf0d792126c8 to your computer and use it in GitHub Desktop.
Save bmispelon/a203f65f9498bef6f997bf0d792126c8 to your computer and use it in GitHub Desktop.
Get a table of month names in various languages, using Django translation machinery
import django
django.setup()
from django.utils import translation
from django.utils.dates import MONTHS
def monthstr(i, lang):
translation.activate(lang)
return str(MONTHS[i])
LANGUAGES = ["en", "fr", "nn", "ro"]
if __name__ == '__main__':
print("<table>")
print(" <thead>")
print(" <tr>")
for langcode in LANGUAGES:
lang = translation.get_language_info(langcode)["name"]
print(f" <th>{lang} (<code>{langcode}</code>)</th>")
print(" </tr>")
print(" </thead>")
print(" <tbody>")
for month in range(1, 13):
print(" <tr>")
for langcode in LANGUAGES:
print(f" <td lang=\"{langcode}\">{monthstr(month, langcode)}</td>")
print(" </tr>")
print(" </tbody>")
print("</table>")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment