Make errors properly translatable
This commit is contained in:
@@ -16,12 +16,12 @@ class FriendlyError(Exception):
|
|||||||
@property
|
@property
|
||||||
def title(self) -> str:
|
def title(self) -> str:
|
||||||
"""Get the gettext translated error title"""
|
"""Get the gettext translated error title"""
|
||||||
return _(self.title_format).format(self.title_args)
|
return self.title_format.format(self.title_args)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def subtitle(self) -> str:
|
def subtitle(self) -> str:
|
||||||
"""Get the gettext translated error subtitle"""
|
"""Get the gettext translated error subtitle"""
|
||||||
return _(self.subtitle_format).format(self.subtitle_args)
|
return self.subtitle_format.format(self.subtitle_args)
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -101,7 +101,13 @@ class Source(Iterable):
|
|||||||
|
|
||||||
def __iter__(self) -> SourceIterator:
|
def __iter__(self) -> SourceIterator:
|
||||||
"""Get an iterator for the source"""
|
"""Get an iterator for the source"""
|
||||||
for location_name in ("data", "cache", "config"):
|
for location_name in (
|
||||||
|
locations := {
|
||||||
|
"data": _("data"),
|
||||||
|
"cache": _("cache"),
|
||||||
|
"config": _("configuration"),
|
||||||
|
}.keys()
|
||||||
|
):
|
||||||
location = getattr(self, f"{location_name}_location", None)
|
location = getattr(self, f"{location_name}_location", None)
|
||||||
if location is None:
|
if location is None:
|
||||||
continue
|
continue
|
||||||
@@ -109,9 +115,9 @@ class Source(Iterable):
|
|||||||
location.resolve()
|
location.resolve()
|
||||||
except UnresolvableLocationError as error:
|
except UnresolvableLocationError as error:
|
||||||
raise FriendlyError(
|
raise FriendlyError(
|
||||||
# The variable is the source's name
|
# The variables are the type of location (eg. cache) and the source's name
|
||||||
f"Invalid {location_name} location for {{}}",
|
_("Invalid {} location for {{}}").format(locations[location_name]),
|
||||||
"Change it or disable the source in the preferences",
|
_("Change it or disable the source in the preferences"),
|
||||||
(self.name,),
|
(self.name,),
|
||||||
(self.name,),
|
(self.name,),
|
||||||
) from error
|
) from error
|
||||||
|
|||||||
@@ -44,6 +44,6 @@ class SGDBManager(AsyncManager):
|
|||||||
# If invalid auth, cancel all SGDBManager tasks
|
# If invalid auth, cancel all SGDBManager tasks
|
||||||
self.cancellable.cancel()
|
self.cancellable.cancel()
|
||||||
raise FriendlyError(
|
raise FriendlyError(
|
||||||
"Couldn't authenticate SteamGridDB",
|
_("Couldn't authenticate SteamGridDB"),
|
||||||
"Verify your API key in preferences",
|
_("Verify your API key in preferences"),
|
||||||
) from error
|
) from error
|
||||||
|
|||||||
Reference in New Issue
Block a user