Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OSX] AttributeError: 'module' object has no attribute 'bindtextdomain' #15

Closed
brianmay opened this issue Feb 24, 2017 · 6 comments · Fixed by #17
Closed

[OSX] AttributeError: 'module' object has no attribute 'bindtextdomain' #15

brianmay opened this issue Feb 24, 2017 · 6 comments · Fixed by #17
Assignees
Labels

Comments

@brianmay
Copy link

brianmay commented Feb 24, 2017

Hello,

Apparently this has been tested on Mac (assuming you mean OSX?), however I am not able to get past this error:

$ pympress            
2017-02-24 10:17:08.800 python2.7[49410:3172507] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead. 
Traceback (most recent call last):
  File "/tmp/virtual/bin/pympress", line 7, in <module>
    from pympress.__main__ import main
  File "/tmp/virtual/lib/python2.7/site-packages/pympress/__main__.py", line 46, in <module>
    locale.bindtextdomain('pympress', pympress.util.get_resource_path('share', 'locale'))
AttributeError: 'module' object has no attribute 'bindtextdomain'

If I try:

$ python
Python 2.7.13 (default, Feb 24 2017, 10:13:58) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.bindtextdomain
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'bindtextdomain'
>>>

I am a bit puzzled at this point, I thought that was a standard Python feature.

Regards

@Cimbali
Copy link
Owner

Cimbali commented Feb 24, 2017

Yeah some of the locale things are not really done in a portable way (there is already a special case for windows...). I don't have a Mac myself so I can't really test regularly, I might have broken something inadvertently.

Basically the problem here is that Gtk relies on the locale domain being set in the C gettext library, which the gettext module doesn't do -- which is why we do it through the locale module, which exposes the C gettext library's functions directly. A binding that doesn't work on your platform apparently.

The standard Python feature as you say, would be to do bind the text domain with the gettext module, but this results in only half the strings being translated (those dynamically used from the python code, but not those loaded by the Gtk widgets).

Let me go look for a workaround.

@Cimbali Cimbali self-assigned this Feb 24, 2017
@Cimbali Cimbali added the bug label Feb 24, 2017
Cimbali added a commit that referenced this issue Feb 28, 2017
The error is due to gettext.bindtextdomain not working for Gtk3, and
locale.bindtextdomain which works on linux not existing on Mac OS X.
See issue #15.
@Cimbali
Copy link
Owner

Cimbali commented Mar 2, 2017

@brianmay Is there a libintl.dylib ou your system? Does importing that in python with cdll allow to call bindtextdomain? something like:

import ctypes
lib = ctypes.cdll.LoadLibrary('libintl.dylib')
lib.bindtextdomain('test', '/usr/share/locale/')

@brianmay
Copy link
Author

brianmay commented Mar 2, 2017

>>> import ctypes
>>> lib = ctypes.cdll.LoadLibrary('libintl.dylib')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/brianmay/.pyenv/versions/2.7.13/lib/python2.7/ctypes/__init__.py", line 440, in LoadLibrary
    return self._dlltype(name)
  File "/Users/brianmay/.pyenv/versions/2.7.13/lib/python2.7/ctypes/__init__.py", line 362, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(libintl.dylib, 6): image not found

Looks like on my system I have a /usr/local/Cellar/gettext/0.19.8.1/lib/libintl.dylib.

Ok, this helps.

export LD_LIBRARY_PATH=/usr/local/Cellar/gettext/0.19.8.1/lib/

Now:

>>> import ctypes
>>> lib = ctypes.cdll.LoadLibrary('libintl.dylib')
>>> lib.bindtextdomain('test', '/usr/share/locale/')
1490168128

Ok, that looks better so far. Will try pympress again.

@brianmay
Copy link
Author

brianmay commented Mar 2, 2017

pympress still generates the same error.

@Cimbali
Copy link
Owner

Cimbali commented Mar 3, 2017

If you check out the fix-osx-i18n branch, this should be fixed (not crash anymore).
You can do this with (adding you favourite options, and maybe --upgrade and --force-reinstall)

pip install git+https://github.com/Cimbali/pympress.git@fix-osx-i18n

What's more, if libintl.dylib is in your library path and you set LANG to de_DE.utf-8 or fr_FR.utf-8, pympress should run in German or French respectively.

@brianmay
Copy link
Author

brianmay commented Mar 3, 2017

It works!

Thanks for your help.

@Cimbali Cimbali mentioned this issue Mar 3, 2017
Cimbali added a commit that referenced this issue Mar 31, 2017
Fixes #19; translations now more consistent; better fix for when we
don't have the C gettext API (e.g. Mac OS X, see #15).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants