mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
Handle invalid locale configuration graciously during startup (#6517)
This commit is contained in:
parent
769c319ffd
commit
dfc1e742f8
@ -22,8 +22,9 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
FRESH_INSTALL_LOCALE = "en-US"
|
||||||
current_locale = ContextVar("current_locale")
|
current_locale = ContextVar("current_locale")
|
||||||
current_locale_default = "en-US"
|
current_locale_default = FRESH_INSTALL_LOCALE
|
||||||
current_regional_format = ContextVar("current_regional_format")
|
current_regional_format = ContextVar("current_regional_format")
|
||||||
current_regional_format_default = None
|
current_regional_format_default = None
|
||||||
|
|
||||||
|
|||||||
@ -115,7 +115,7 @@ class Red(
|
|||||||
owner=None,
|
owner=None,
|
||||||
whitelist=[],
|
whitelist=[],
|
||||||
blacklist=[],
|
blacklist=[],
|
||||||
locale="en-US",
|
locale=_i18n.FRESH_INSTALL_LOCALE,
|
||||||
regional_format=None,
|
regional_format=None,
|
||||||
embeds=True,
|
embeds=True,
|
||||||
color=15158332,
|
color=15158332,
|
||||||
@ -1145,9 +1145,28 @@ class Red(
|
|||||||
self.owner_ids.add(self._owner_id_overwrite)
|
self.owner_ids.add(self._owner_id_overwrite)
|
||||||
|
|
||||||
i18n_locale = await self._config.locale()
|
i18n_locale = await self._config.locale()
|
||||||
_i18n.set_global_locale(i18n_locale)
|
try:
|
||||||
|
_i18n.set_global_locale(i18n_locale)
|
||||||
|
except ValueError:
|
||||||
|
log.warning(
|
||||||
|
"The bot's global locale was set to an invalid value (%r)"
|
||||||
|
" and will be reset to default (%s).",
|
||||||
|
i18n_locale,
|
||||||
|
_i18n.FRESH_INSTALL_LOCALE,
|
||||||
|
)
|
||||||
|
i18n_locale = _i18n.FRESH_INSTALL_LOCALE
|
||||||
|
await self._config.locale.clear()
|
||||||
i18n_regional_format = await self._config.regional_format()
|
i18n_regional_format = await self._config.regional_format()
|
||||||
_i18n.set_global_regional_format(i18n_regional_format)
|
try:
|
||||||
|
_i18n.set_global_regional_format(i18n_regional_format)
|
||||||
|
except ValueError:
|
||||||
|
log.warning(
|
||||||
|
"The bot's global regional format was set to an invalid value (%r)"
|
||||||
|
" and will be reset to default (which is to inherit global locale, i.e. %s).",
|
||||||
|
i18n_regional_format,
|
||||||
|
i18n_locale,
|
||||||
|
)
|
||||||
|
await self._config.regional_format.clear()
|
||||||
|
|
||||||
async def _pre_connect(self) -> None:
|
async def _pre_connect(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user