add BabelTowerError
This commit is contained in:
parent
73d3088d86
commit
d30e1086f3
3 changed files with 13 additions and 2 deletions
|
|
@ -8,7 +8,7 @@
|
|||
+ Add module `calendar` with `want_*` date type conversion utilities and `age_and_days()`
|
||||
+ Move obsolete stuff to `obsolete` package (includes configparse 0.3 as of now)
|
||||
+ Add `redact` module with `redact_url_password()`
|
||||
+ Add more exceptions: `NotFoundError()`
|
||||
+ Add more exceptions: `NotFoundError()`, `BabelTowerError()`
|
||||
|
||||
## 0.4.0
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,13 @@ class NotFoundError(LookupError):
|
|||
"""
|
||||
The requested item was not found.
|
||||
"""
|
||||
# Werkzeug et al.
|
||||
code = 404
|
||||
|
||||
class BabelTowerError(NotFoundError):
|
||||
"""
|
||||
The user requested a language that cannot be understood.
|
||||
"""
|
||||
|
||||
__all__ = (
|
||||
'MissingConfigError', 'MissingConfigWarning', 'LexError', 'InconsistencyError', 'NotFoundError'
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import os
|
|||
import toml
|
||||
from typing import Mapping
|
||||
|
||||
from .exceptions import BabelTowerError
|
||||
|
||||
class IdentityLang:
|
||||
'''
|
||||
|
|
@ -81,7 +82,10 @@ class I18n(metaclass=ABCMeta):
|
|||
def load_lang(self, name: str, filename: str | None = None) -> I18nLang:
|
||||
if not filename:
|
||||
filename = self.filename_tmpl.format(lang=name, ext=self.EXT)
|
||||
data = self.load_file(filename)
|
||||
try:
|
||||
data = self.load_file(filename)
|
||||
except OSError as e:
|
||||
raise BabelTowerError(f'unknown language: {name}') from e
|
||||
l = self.langs.setdefault(name, I18nLang())
|
||||
l.update(data[name] if name in data else data)
|
||||
if name != self.default_lang:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue