Created
April 17, 2024 20:37
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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