Feature Requests item #1649329, was opened at 2007-02-01 03:20
Message generated for change (Comment added) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1649329&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Shannon -jj Behrens (jjinux)
Assigned to: Nobody/Anonymous (nobody)
Summary: gettext.py incompatible with eggs

Initial Comment:
If you distribute your code in a zipped egg, you can't use translation catalogs 
stored in that egg.  That's because gettext.py only knows how to find the 
translation catalogs in the actual filesystem.

This wouldn't be so bad if the "find" function didn't serve double duty.  On 
the one hand, it implements the "find" algorithm to pick the right languages 
and fallbacks.  On the other hand, it actually resolves the files in the 
filesystem.  It would be nice if these were separate.  It seems like people in 
projects like Pylons are stuck copying code from the find function in order to 
work around this problem.

Perhaps gettext can be updated to know about eggs.  Perhaps setting localedir 
to something like "egg://..." would enable this functionality.

----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2007-02-08 09:27

Message:
Logged In: YES 
user_id=21627
Originator: NO

Ok, I see how this fixes find(). What about translation() (which calls
find, then also performs open())? Wouldn't this need to be fixed as well?

Also, what about os.path.join? It might depend on the structure of the
storage, as well (suppose you have the .mo data stored in a relational
database)?

In principle, I'm willing to fix this. I just want to avoid adding a
hack.

For example, it might be sensible to come up with a MOOpener interface,
that has an .exists method, taking a list of strings, a .join method,
taking a list of strings and returning something that can be passed to the
.open method, which would take something that .join returned and returning
a file-like object. It might be possible to extend the meaning of the
localedir parameter to be either a string (understood as a directory name),
or a MOOpener object.

In any case, people *will* have to duplicate find for the moment, as any
changes we discuss will only appear in 2.6.

----------------------------------------------------------------------

Comment By: Shannon -jj Behrens (jjinux)
Date: 2007-02-08 01:52

Message:
Logged In: YES 
user_id=30164
Originator: YES

Ok, I've uploaded a patch with a possible way to refactor the code.  I'm
okay if you mark this bug as WONTFIX.  I'm raising it as a concern because
I know there are a lot of people out there using Web frameworks such as
Pylons, Turbo Gears, etc. that are going to have to duplicate the code in
"find" in order to use eggs.  I hate to have see them do that. :-/

----------------------------------------------------------------------

Comment By: Shannon -jj Behrens (jjinux)
Date: 2007-02-08 01:49

Message:
Logged In: YES 
user_id=30164
Originator: YES

File Added: gettext.patch

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2007-02-07 07:45

Message:
Logged In: YES 
user_id=21627
Originator: NO

Do you have a proposal on how to do the refactoring? It would be fine to
split find into two parts; it would not be acceptable (to me) to teach it
egg: URLs.

----------------------------------------------------------------------

Comment By: Shannon -jj Behrens (jjinux)
Date: 2007-02-06 23:28

Message:
Logged In: YES 
user_id=30164
Originator: YES

Sorry, yes, this is a feature request.  The most important thing that I'm
requesting is to refactor the code.  That "find" function implements a
certain algorithm that has nothing to do with the filesystem.

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2007-02-06 20:43

Message:
Logged In: YES 
user_id=21627
Originator: NO

I fail to see the bug. gettext.find behaves as specified; if you want
something else, don't use that function.

If you want to load a .mo file from a zip file, you should be able to
create a GNUTranslation object directly, from a file-like object.

I don't think that gettext should support eggs directly. If you want it to
do things other than loading from file systems, you should generalize that
appropriately. One appropriate generalization could be the introduction of
a directory-like object, where you can do .exists(relpath), and
.open(relpath). However, introduction of directory-like objets is PEP
material.

Reclassifying this as a feature request.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1649329&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to