Skip to content

Add localization for UI #2136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: v0.6
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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