r1 - 20 Jul 2006 - 17:47:55 - BrianKirschYou are here: OSAF >  Projects Web  >  DevelopmentHome > InternationalizationProject > ChandlerEggI18nIntegrationProposal

Chandler I18n Egg Integration Proposal

Egg Architecture reworking

My proposal is to redesign the API submitted by Markku to a class, EggResourceManager?. I have kept Markku's original intent of having the API be useable for general resource loading purposes in addition to its localization features. I have also added or want to add the following features:

    1. Delay loading pkg_resources.add_activation_listener to the classes initial method. This allows the specification of a locale set, resource file, and fallback logic before the installed eggs are searched for resource and gettext definitions.

    2. Added a Gettext locale fallback mechanism as well as country code fallback features. Country fallback feature adds only the language code as a fallback to a language country code definition. If no resources or gettext translations are available for the fr_CA locale then fr locale will also be searched.

    3. Gettext mo files are only loaded for locales in the locale set. This reduces memory requirements and startup time. Returned values for resource and gettext lookups are cached by the EggResourceManager? for performance. The cache is flushed and the gettext fallback order regenerated if the locale set of the EggResourceManager? changes.

    4. Created an EggTranslations class which extended gettext.GNUTranslations. The EggTranslations.ugettext method can take an optional default value which will be returned if no localization is found for the txt key passed.
    5. The egg_i18n.py Python file which contains the localization logic contained should be rename to something that better reflects its use for all types of resources localized and non-localized. Some names that come to mind are egg_resource.py, resource_manager.py, resource_loader.py.

EggResourceManager? Overview

EggResourceManager? API

class EggResourceManager? (object):

def __init__(self):

def initialize(self, localeSet, resourceFile="resources.info", fallback=True):
"""
@param localeSet: A String or List containing locale country and language codes
@type localeSet: c{str} or c{unicode} or c{List} containing c{str} or c{unicode} values

@param resourceFile: The name of the resource ini file in the egg's info directory.
This file contains the location of localized and non-localized resources
as well as translation files in gettext mo format. The default value for this file is "resources.info".

@type resourceFile: c{str} or c{unicode}

@param fallback: Indicates where locale set fallback should take place.
If set to True the EggResourceManager? will search
all locales in the locale set till a resource or gettext mo translation
file is found. If set to False the EggResourceManager? will only try to
locate a resource or gettext mo translation file for the current locale
which is the first locale in the locale set.

@type fallback: c{boolean}
The initilize method performs the following operations:
1. Calls the EggResourceManager?'s setLocaleSet method passing the localeSet param. See the setLocaleSet method
documentaiton for more info.

          1. Calls pkg_resources.add_activation_listener method passing the EggResourceManager?'s parseEggResourceFiles method as a callback. See the parseEggResourceFiles method for more info.
            3.

"""

#returns the value contained in the ini file
#for the given key or None if not fount
getValueForKey(domain, name, locale=None)
hasKey(domain, name, locale=None)
isDirectory(domain, name, locale=None)
listDirectory(domain, name, locale=None)

#This would test for the existence of a file
#matching the value
hasResource(domain, resourceName, locale=None) #optional locale
getResourceAsStream(domain, name, locale=None)
getResourceAsLines(domain, name, locale=None) #don't think we need this
getResourceAsString(domain, name, locale=None)
runResourceAsScript(domain, name, locale=None)
#if import wx works it loads a #ResourceFileSystemHandler on the class
#so can load translations in wx as paths
wx.FileSystem.AddHandler(i18n.ResourceFileSystem())
getText(domain, name, txt, default="IGNORE")

parseEggResourceFiles(self, dist):

getLocaleSet() #returns a list of locales in fallback order

setLocaleSet(self, localeSet) #One or more locales #Array or string

"""
Sets the EggResourceManagers? locale set and adds the language code as a fallback for language code county code locale definitions when fallback is set to True.

"""

getDebugString(domain=None)
__flushCache()
__hasCountryCode(locale)
__stripCountryCode(locale)

-- BrianKirsch - 20 Jul 2006

Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r1 | More topic actions
 
Open Source Applications Foundation
Except where otherwise noted, this site and its content are licensed by OSAF under an Creative Commons License, Attribution Only 3.0.
See list of page contributors for attributions.