Add support to read linfo.
Refactor locale to actually use gettext.
This commit is contained in:
parent
a11809cccc
commit
d17e733677
@ -8,5 +8,4 @@ sugar_PYTHON = \
|
||||
activityservice.py \
|
||||
bundle.py \
|
||||
bundlebuilder.py \
|
||||
bundleregistry.py \
|
||||
locale.py
|
||||
bundleregistry.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")
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user