Skip to content

Commit

Permalink
Modify locale default behaviour in StepDefaults 5.0 and 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterKraus committed Aug 21, 2024
1 parent 3dbdf61 commit cae7e21
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/dgbowl_schemas/yadg/dataschema_5_0/stepdefaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,12 @@ def timezone_resolve_localtime(cls, v):
@classmethod
def locale_set_default(cls, v):
if v is None:
v = ".".join(locale.getlocale())
for loc in (locale.getlocale(), locale.getlocale(locale.LC_NUMERIC)):
try:
v = ".".join(loc)
break
except TypeError:
pass
else:
v = "en_GB.UTF-8"
return v
13 changes: 8 additions & 5 deletions src/dgbowl_schemas/yadg/dataschema_5_1/stepdefaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ def timezone_resolve_localtime(cls, v):
@classmethod
def locale_set_default(cls, v):
if v is None:
v = locale.getlocale(locale.LC_NUMERIC)[0]
try:
v = str(Locale.parse(v))
except (TypeError, UnknownLocaleError):
v = "en_GB"
for loc in (locale.getlocale(locale.LC_NUMERIC), locale.getlocale()):
try:
v = str(Locale.parse(loc[0]))
break
except (TypeError, UnknownLocaleError):
pass
else:
v = "en_GB"
return v

0 comments on commit cae7e21

Please sign in to comment.