Edgewall Software

Changes between Version 28 and Version 29 of CookBook/PluginL10N


Ignore:
Timestamp:
Mar 20, 2014, 11:58:19 AM (10 years ago)
Author:
Jun Omae
Comment:

added handling KeyError from resource_filename(__name__, 'locale')

Legend:

Unmodified
Added
Removed
Modified
  • CookBook/PluginL10N

    v28 v29  
    186186{{{#!python
    187187    def __init__(self):
    188         import pkg_resources # here or with the other imports
     188        import pkg_resources  # here or with the other imports
    189189        # bind the 'foo' catalog to the specified locale directory
    190         locale_dir = pkg_resources.resource_filename(__name__, 'locale')
    191         add_domain(self.env.path, locale_dir)
     190        try:
     191            locale_dir = pkg_resources.resource_filename(__name__, 'locale')
     192        except KeyError:
     193            pass  # no locale directory in plugin if Babel is not installed
     194        else:
     195            add_domain(self.env.path, locale_dir)
    192196}}}
    193197assuming that folder `locale` will reside in the same folder as the file containing the code above, referred to as `<path>` below (as can be observed inside the Python egg after packaging).