Skip to content

Commit

Permalink
improvements added
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Aug 20, 2023
1 parent d7ccec6 commit c769926
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 207 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ sdist/
*.egg-info/
.installed.cfg
*.egg
.local

# Generated from Docker Instance
.bash_history
Expand Down
27 changes: 15 additions & 12 deletions apprise/AppriseLocale.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,13 @@ def __init__(self, language=None):
return

# Add language
if not (self.lang and self.add(self.lang)):
# Fall back to our default
self.add(self._default_language)
self.add(self.lang)

def add(self, lang, set_default=True):
def add(self, lang=None, set_default=True):
"""
Add a language to our list
"""
lang = lang if lang else self._default_language
if lang not in self._gtobjs:
# Load our gettext object and install our language
try:
Expand All @@ -132,19 +131,18 @@ def add(self, lang, set_default=True):
'Could not load translation path: %s',
join(self._locale_dir, lang))

# Fallback
if None not in self._gtobjs:
self._gtobjs[None] = gettext
self.__fn_map = getattr(self._gtobjs[None], self._fn)
if set_default:
self.lang = None
# Fallback (handle case where self.lang does not exist)
if self.lang not in self._gtobjs:
self._gtobjs[self.lang] = gettext
self.__fn_map = getattr(self._gtobjs[self.lang], self._fn)

return False

logger.trace('Loaded language %s', lang)

if set_default:
logger.debug('Language set to %s', self.lang)
self.lang = self._default_language
logger.debug('Language set to %s', lang)
self.lang = lang

return True

Expand Down Expand Up @@ -249,16 +247,21 @@ def __getstate__(self):
Pickle Support dumps()
"""
state = self.__dict__.copy()

# Remove the unpicklable entries.
del state['_gtobjs']
del state['_AppriseLocale__fn_map']
return state

def __setstate__(self, state):
"""
Pickle Support loads()
"""
self.__dict__.update(state)
# Our mapping to our _fn
self.__fn_map = None
self._gtobjs = {}
self.add(state['lang'], set_default=True)


#
Expand Down
Loading

0 comments on commit c769926

Please sign in to comment.