Skip to content

Commit

Permalink
Add localization for UI
Browse files Browse the repository at this point in the history
  • Loading branch information
osamacis committed Jan 4, 2023
1 parent 3fb6ada commit c6d367d
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/bitmessagekivy/base_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"""
Base class for Navigation Drawer
"""

import gettext
import os
from kivy.lang import Observable

from kivy.properties import (
Expand Down Expand Up @@ -35,9 +36,35 @@ def __init__(self, defaultlang):
self.ugettext = None
self.lang = defaultlang

@staticmethod
def _(text):
return text
def _(self, text):
return self.ugettext(text)

def fbind(self, name, func, args, **kwargs):
"""Function for binding to observers """
if name == "_":
self.observers.append((func, args, kwargs))
else:
return super(BaseLanguage, self).fbind(name, func, *args, **kwargs)

def funbind(self, name, func, args, **kwargs):
"""Function for unbinding to observers """
if name == "_":
key = (func, args, kwargs)
if key in self.observers:
self.observers.remove(key)
else:
return super(BaseLanguage, self).funbind(name, func, *args, **kwargs)

def switch_lang(self, lang):
"""Function language switching """
# get the right locales directory, and instanciate a gettext
locale_dir = os.path.join(os.path.dirname(__file__), 'translations', 'locales')
locales = gettext.translation('langapp', locale_dir, languages=[lang])
self.ugettext = locales.gettext

# update all the kv rules attached to this text
for func, largs, in self.observers:
func(largs, None, None)


class BaseNavigationItem(OneLineAvatarIconListItem):
Expand Down

0 comments on commit c6d367d

Please sign in to comment.