diff --git a/bin/sugar-activity b/bin/sugar-activity index b5c796bf..a8d4246f 100644 --- a/bin/sugar-activity +++ b/bin/sugar-activity @@ -34,6 +34,7 @@ DBusGMainLoop(set_as_default=True) from sugar3.activity import activityhandle from sugar3.activity import i18n +from sugar3 import config import sugar3 from sugar3.bundle.activitybundle import ActivityBundle from sugar3 import logger @@ -107,11 +108,12 @@ def main(): os.environ['SUGAR_BUNDLE_VERSION'] = str(bundle.get_activity_version()) # must be done early, some activities set translations globally, SL #3654 - locale_path = i18n.get_locale_path(bundle.get_bundle_id()) - if locale_path: - gettext.bindtextdomain(bundle.get_bundle_id(), locale_path) - gettext.bindtextdomain('sugar-toolkit', sugar3.locale_path) - gettext.textdomain(bundle.get_bundle_id()) + activity_locale_path = os.environ.get("SUGAR_LOCALEDIR", + config.locale_path) + + gettext.bindtextdomain(bundle.get_bundle_id(), activity_locale_path) + gettext.bindtextdomain('sugar-toolkit', config.locale_path) + gettext.textdomain(bundle.get_bundle_id()) splitted_module = args[0].rsplit('.', 1) module_name = splitted_module[0] diff --git a/configure.ac b/configure.ac index e5e3d79e..64650aed 100644 --- a/configure.ac +++ b/configure.ac @@ -49,5 +49,6 @@ src/sugar3/presence/Makefile src/sugar3/datastore/Makefile src/sugar3/dispatch/Makefile src/sugar3/test/Makefile +src/sugar3/config.py po/Makefile.in ]) diff --git a/src/sugar3/Makefile.am b/src/sugar3/Makefile.am index e5e34367..9e13e8ce 100644 --- a/src/sugar3/Makefile.am +++ b/src/sugar3/Makefile.am @@ -17,6 +17,8 @@ sugar_PYTHON = \ profile.py \ util.py +nodist_sugar_PYTHON = config.py + XDG_MIME_SOURCES = \ xdgmime.c \ xdgmime.h \ diff --git a/src/sugar3/__init__.py b/src/sugar3/__init__.py index d24d665b..e69de29b 100644 --- a/src/sugar3/__init__.py +++ b/src/sugar3/__init__.py @@ -1,30 +0,0 @@ -# Copyright (C) 2006-2007, Red Hat, Inc. -# Copyright (C) 2007-2008, One Laptop Per Child -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - -import os -import gettext - - -if 'SUGAR_PREFIX' in os.environ: - prefix = os.environ['SUGAR_PREFIX'] -else: - prefix = '/usr' - -locale_path = os.path.join(prefix, 'share', 'locale') - -gettext.bindtextdomain('sugar-base', locale_path) diff --git a/src/sugar3/activity/i18n.py b/src/sugar3/activity/i18n.py index d7c515b0..8a7a2b35 100644 --- a/src/sugar3/activity/i18n.py +++ b/src/sugar3/activity/i18n.py @@ -108,53 +108,3 @@ def pgettext(context, message): if '\x04' in translation: return message return translation - - -def get_locale_path(bundle_id): - """ Returns the locale path, which is the directory where the preferred - MO file is located. - - The preferred MO file is the one with the latest translation. - - @type bundle_id: string - @param bundle_id: The bundle id of the activity in question - @rtype: string - @return: the preferred locale path or None in the - case of an error - """ - - # Note: We pre-assign weights to the directories so that if no translations - # exist, the appropriate fallbacks (eg: bn for bn_BD) can be loaded - # The directory with the highest weight is returned, and if a MO file is - # found, the weight of the directory is set to the MO's modification time - # (as described in the MO header, and _not_ the filesystem mtime) - - candidate_dirs = {} - - if 'SUGAR_LOCALEDIR' in os.environ: - candidate_dirs[os.environ['SUGAR_LOCALEDIR']] = 2 - - candidate_dirs[os.path.join(sys.prefix, 'share', 'locale')] = 0 - - default_locale = locale.getdefaultlocale()[0] - if not default_locale: - return None - - for candidate_dir in candidate_dirs.keys(): - if os.path.exists(candidate_dir): - full_path = os.path.join(candidate_dir, - default_locale, 'LC_MESSAGES', - bundle_id + '.mo') - if os.path.exists(full_path): - try: - candidate_dirs[candidate_dir] = \ - _extract_modification_time(full_path) - except (IOError, ValueError): - # The mo file is damaged or has not been initialized - # Set lowest priority - candidate_dirs[candidate_dir] = -1 - - available_paths = sorted(candidate_dirs.iteritems(), key=lambda (k, v): - (v, k), reverse=True) - preferred_path = available_paths[0][0] - return preferred_path diff --git a/src/sugar3/config.py.in b/src/sugar3/config.py.in new file mode 100644 index 00000000..848c1ee6 --- /dev/null +++ b/src/sugar3/config.py.in @@ -0,0 +1,20 @@ +# Copyright (C) 2006-2007 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +# flake8: noqa + +locale_path = '@prefix@/share/locale'