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

gettext.translation error while running with Python3.6 #2

Closed
wimstefan opened this issue May 20, 2019 · 8 comments · Fixed by #3
Closed

gettext.translation error while running with Python3.6 #2

wimstefan opened this issue May 20, 2019 · 8 comments · Fixed by #3

Comments

@wimstefan
Copy link

I'm getting the following error when I try to run PyTone under Python3.6:

Traceback (most recent call last):
  File "src/pytone.py", line 41, in <module>
    gettext.translation("PyTone", locallocaledir).install()
  File "/usr/lib64/python3.6/gettext.py", line 514, in translation
    raise OSError(ENOENT, 'No translation file found for domain', domain)
FileNotFoundError: [Errno 2] No translation file found for domain: 'PyTone'

Is the Python3 port already usable or am I just too early with my wishful thinking? ;-)

@wimstefan
Copy link
Author

Sorry for coming back to this but is there anybody out there who got PyTone working with python3?

@joerg-lehmann
Copy link
Owner

It seems that your locales are missing. Try adjusting the paths and then running the gettext.sh script in the top level directory of the repository. In a properly released version, the generated files are contained. When running directly from the repository, however, you need to do this translation by yourself.

@wimstefan wimstefan changed the title Error runing with Python3.6 Error running with Python3.6 Nov 17, 2019
@wimstefan
Copy link
Author

That's good to know! I'm indeed running PyTone directly from the repository and had no idea that I have to create the locales myself ;-)
I've modified the paths in both scripts gettext.sh and msgfmt.sh and ran both scripts.
gettext.sh first ended with an error and I had to modify src/pytone.py to run it successfully. Not that I understand a thing about Python but the script ran afterwards ... ;-)
Here are the changes that I made:

  diff --git a/src/pytone.py b/src/pytone.py
  index 6462dbf..a380182 100755
  --- a/src/pytone.py
  +++ b/src/pytone.py
  @@ -138,7 +138,7 @@ try:
                   config.finishconfigsection(pluginconfig)
                   pluginconfig = pluginconfig()
               plugins.append((pluginmodule, pluginconfig))
  -            log.info(_("Plugin '%s' loaded" % name))
  +            log.info(_("Plugin '%s' loaded") % name)
           except Exception as e:
                log.error(_("Cannot load plugin '%s': %s") % (name, e))
                log.debug_traceback()

But I still get the same error message as above 🤔

altendky added a commit to altendky/PyTone that referenced this issue Nov 25, 2019
@altendky
Copy link
Contributor

diff --git a/gettext.sh b/gettext.sh
index 7cb9ca5..da1d38f 100755
--- a/gettext.sh
+++ b/gettext.sh
@@ -4,8 +4,10 @@ POTFILE=locale/PyTone.pot
 LOCALES="de it pl fr"
 
 # Adjust the following paths as necessary
-PYGETTEXTPATH=/Library/Frameworks/Python.framework/Versions/3.7/share/doc/python3.7/examples/Tools/i18n
-GETTEXTPATH=/usr/local/opt/gettext/bin
+# PYGETTEXTPATH=/Library/Frameworks/Python.framework/Versions/3.7/share/doc/python3.7/examples/Tools/i18n
+PYGETTEXTPATH=/home/altendky/.pyenv/source/3.8.0/Python-3.8.0/Tools/i18n
+# GETTEXTPATH=/usr/local/opt/gettext/bin
+GETTEXTPATH=/usr/bin
 
 $PYGETTEXTPATH/pygettext.py -o $POTFILE src/*.py src/services/*.py src/services/songdbs/*.py src/services/players/*.py
 for locale in $LOCALES; do
diff --git a/src/pytone.py b/src/pytone.py
index 6462dbf..4e044cc 100755
--- a/src/pytone.py
+++ b/src/pytone.py
@@ -38,7 +38,7 @@ import importlib, importlib.util
 
 import gettext
 locallocaledir = os.path.join(os.path.dirname(sys.argv[0]), "../locale")
-gettext.translation("PyTone", locallocaledir).install()
+gettext.translation("PyTone", locallocaledir, languages=['it']).install()
 
 ##############################################################################
 # locale initialization

Above patch to 7bb928f got past the error for me. My machine would be setup for English and I do not know my way around gettext. But, it seems to just be a matter of getting a default language set or somesuch.

Note that gettext.translate() was just deprecated with 3.8.
https://docs.python.org/3/library/gettext.html#gettext.translation

Looks like maybe fallback=True is what is wanted. I'll file a PR and reference this issue so others can easily try it out.

@wimstefan
Copy link
Author

Adding fallback=True resolves indeed the problem with the gettext.translation error I've reported.

But a new problem arises: the bufferedao extension. If I keep it enabled in setup.py and run python3 ./setup.py build_ext -i I get a segfault running the application. The logfile for the segfault is attached below.

2019-11-26-segfault-with-bufferedao.log

@joerg-lehmann
Copy link
Owner

Some notes on the previous comments.

  • gettext.sh and msgftm.sh are part of my pre-release scripts that I added for Stefan's convenience to the repository. They were actually never intended to be run by users.
  • gettext.translation() is not deprecated in Python 3.8, only one of its arguments.
  • Fallback=true is a reasonable solution if no locale corresponding to the locale settings is available. I am a bit surprised that this issue only pops up now, but maybe there was a change in the gettext module that I am not aware of.
  • Please open separate, specific issues for unrelated problems. Thanks!

@altendky
Copy link
Contributor

Wow, I did read that deprecation much too quickly. Thank you for the correction. And yes, it is odd that fallback=True hasn't been needed before unless this has only been run with de/fr/it/pl locales and never en etc. I looked and a quick glance over the py2 docs for gettext.translation() at least showed the same option and default. But, I've never actually used gettext so I have no real knowledge in the area.

@wimstefan wimstefan changed the title Error running with Python3.6 gettext.translation error while running with Python3.6 Nov 27, 2019
@wimstefan
Copy link
Author

Oh I wasn't aware that those scripts where in place for me - thank you for that!

And sorry for mentioning the problem with the bufferedao extension. I wasn't sure indeed whether to place it in this issue (with the title "Error running with Python 3.6") or open another issue for it. I've changed the title for this issue to make it more specific and I will open another issue for the bufferedao extension.

Thank you so much guys for keeping this (for me so precious) app alive!!! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants