Skip to content

Instantly share code, notes, and snippets.

Created August 6, 2018 19:00
What would you like to do?
Babel locale tester
#!/usr/bin/env python3
from __future__ import print_function
import sys
import datetime
import babel.dates
except ImportError:
print("Failed to import Babel. Did you run `pip install Babel`?")
if sys.version_info[0] == 2:
# not recommended, but eh
lang = raw_input("Language code (as used in Nikola): ")
lang = input("Language code (as used in Nikola): ")
# Babel uses a slightly different name for sr_latin
if lang == 'sr_latin':
lang = 'sr_Latn'
date =
print("Posts from {month_year} : ",
babel.dates.format_skeleton('yMMMM', date, locale=lang), sep='')
print("Posts from {month_day_year}: ",
babel.dates.format_date(date, 'long', lang), sep='')
print("MMMM month : ",
babel.dates.format_date(date, 'MMMM', lang), sep='')
print("LLLL month : ",
babel.dates.format_date(date, 'LLLL', lang), sep='')
months = [babel.dates.format_date(, i, 1),
'MMMM', lang) for i in range(1, 13)]
lonths = [babel.dates.format_date(, i, 1),
'LLLL', lang) for i in range(1, 13)]
print("MMMM months:", ', '.join(months))
print("LLLL months:", ', '.join(lonths))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment