Created
August 6, 2018 19:00
-
-
Save Kwpolska/3c0d1af8bd641229d4ab64f1b98d88de to your computer and use it in GitHub Desktop.
Babel locale tester
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
#!/usr/bin/env python3 | |
from __future__ import print_function | |
import sys | |
import datetime | |
try: | |
import babel.dates | |
except ImportError: | |
print("Failed to import Babel. Did you run `pip install Babel`?") | |
sys.exit(1) | |
if sys.version_info[0] == 2: | |
# not recommended, but eh | |
lang = raw_input("Language code (as used in Nikola): ") | |
else: | |
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 = datetime.date.today() | |
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='') | |
print() | |
months = [babel.dates.format_date(datetime.date(1970, i, 1), | |
'MMMM', lang) for i in range(1, 13)] | |
lonths = [babel.dates.format_date(datetime.date(1970, 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