Skip to content

Commit

Permalink
Fix deprecation of getdefaultlocale in python 3.11 (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
liang2kl committed Apr 28, 2023
1 parent 8c801e6 commit 6ef2719
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@ jobs:
python-version: "3.6.7"
- run: pip install -r requirements.txt
- run: python -m unittest

test-3.11:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: "3.11.0"
- run: pip install -r requirements.txt
- run: python -m unittest
7 changes: 5 additions & 2 deletions mkdocs_blogging_plugin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
)

from babel.dates import format_date, format_datetime
import locale
import locale, sys
from datetime import datetime
from functools import lru_cache

Expand Down Expand Up @@ -142,7 +142,10 @@ def get_localized_date(timestamp: float, day_only: bool, format: str=None, _loca
return datetime.strftime(time, format)
else:
if not _locale:
_locale = locale.getdefaultlocale()[0]
if sys.version_info[0] < (3, 11):
_locale = locale.getdefaultlocale()[0]
else:
_locale = locale.getlocale()[0]

if day_only:
return format_date(time.date(), format="short", locale=_locale)
Expand Down

0 comments on commit 6ef2719

Please sign in to comment.