From d17e7336775de93eef81932082b9f0605ddbecbd Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 23 Mar 2007 17:27:31 +0100 Subject: [PATCH] Add support to read linfo. Refactor locale to actually use gettext. --- sugar/activity/Makefile.am | 3 +-- sugar/activity/activityfactory.py | 5 +++++ sugar/activity/bundle.py | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/sugar/activity/Makefile.am b/sugar/activity/Makefile.am index 885f62e3..d11a3474 100644 --- a/sugar/activity/Makefile.am +++ b/sugar/activity/Makefile.am @@ -8,5 +8,4 @@ sugar_PYTHON = \ activityservice.py \ bundle.py \ bundlebuilder.py \ - bundleregistry.py \ - locale.py + bundleregistry.py diff --git a/sugar/activity/activityfactory.py b/sugar/activity/activityfactory.py index 6662ccbf..7d49ffb9 100644 --- a/sugar/activity/activityfactory.py +++ b/sugar/activity/activityfactory.py @@ -20,6 +20,7 @@ import logging import dbus import gobject import gtk +import gettext from sugar.presence import PresenceService from sugar.activity import bundleregistry @@ -69,6 +70,10 @@ class ActivityCreationHandler(gobject.GObject): registry = bundleregistry.get_registry() bundle = registry.get_bundle(service_name) + gettext.bindtextdomain(self._service_name, + os.path.join(bundle.get_path(), "locale")) + gettext.textdomain(self._service_name) + bus = dbus.SessionBus() proxy_obj = bus.get_object(service_name, bundle.get_object_path(), follow_name_owner_changes=True) factory = dbus.Interface(proxy_obj, "com.redhat.Sugar.ActivityFactory") diff --git a/sugar/activity/bundle.py b/sugar/activity/bundle.py index c4f85030..8dcd33ce 100644 --- a/sugar/activity/bundle.py +++ b/sugar/activity/bundle.py @@ -1,4 +1,5 @@ import logging +import locale import os from ConfigParser import ConfigParser @@ -23,6 +24,10 @@ class Bundle: else: self._valid = False + linfo_path = self._get_linfo_path() + if linfo_path and os.path.isfile(linfo_path): + self._parse_locale_info(linfo_path) + def _parse_info(self, info_path): cp = ConfigParser() cp.read([info_path]) @@ -65,6 +70,28 @@ class Bundle: if cp.has_option(section, 'activity_version'): self._activity_version = int(cp.get(section, 'activity_version')) + def _parse_linfo(self, linfo_path): + cp = ConfigParser() + cp.read([linfo_path]) + + if cp.has_option('Activity', 'name'): + self._name = cp.get(section, 'name') + + def _get_linfo_path(self): + path = None + lang = locale.getdefaultlocale()[0] + if lang != None: + path = os.path.join(self._path, 'locale', lang) + if os.path.isdir(path): + path = os.path.join(self._path, 'locale', lang[:2]) + if not os.path.isdir(path): + path = None + + if path: + return os.path.join(path, 'activity.linfo') + else: + return None + def is_valid(self): return self._valid