After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 737497 - Some plugins are not translated
Some plugins are not translated
Status: RESOLVED FIXED
Product: gedit-plugins
Classification: Other
Component: General
3.14.x
Other Linux
: High normal
: ---
Assigned To: Gedit maintainers
Gedit maintainers
: 654186 756800 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2014-09-27 18:15 UTC by Piotr Drąg
Modified: 2019-03-23 20:54 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Python module don't import texttext (985 bytes, patch)
2015-10-24 02:14 UTC, Trần Ngọc Quân
needs-work Details | Review
Final patch (5.64 KB, patch)
2015-12-31 08:21 UTC, Trần Ngọc Quân
needs-work Details | Review
Install gettext for python module (570 bytes, patch)
2016-01-03 07:38 UTC, Trần Ngọc Quân
none Details | Review
import gettext for all python file that call _() (8.57 KB, patch)
2016-02-22 08:39 UTC, Trần Ngọc Quân
none Details | Review
plugins: Import gettext for all Python files with translations (10.00 KB, patch)
2017-08-01 21:58 UTC, Piotr Drąg
committed Details | Review

Description Piotr Drąg 2014-09-27 18:15:04 UTC
These plugins are not translated in the "Plugins" preferences tab, even though they are translated in the PO file: quickopen, snippets, sort, spell, and time. docinfo, externaltools, modelines, and pythonconsole are translated here. filebrowser has translated name, but the description is in English.

Additionally (and more importantly) the UI of quickopen, snippets, externaltools, modelines, and pythonconsole are at least partially in English.

(Locale is Polish, 100% completed)
Comment 1 Yosef Or Boczko 2014-09-27 19:15:54 UTC
The same here, in Hebrew (100% translated, the DL just think some strings are fuzzy but they are not).
Comment 2 Piotr Drąg 2015-04-04 02:19:44 UTC
In 3.16 the names and descriptions of plugins are correctly translated, but their UI is still a mix of English and Polish.
Comment 3 Sébastien Wilmet 2015-06-16 09:46:30 UTC
*** Bug 654186 has been marked as a duplicate of this bug. ***
Comment 4 Sébastien Wilmet 2015-10-19 12:07:57 UTC
*** Bug 756800 has been marked as a duplicate of this bug. ***
Comment 5 Trần Ngọc Quân 2015-10-24 02:14:41 UTC
Created attachment 313998 [details] [review]
Python module don't import texttext

Note: Don't commit this patch. It's only for review!
Comment 6 Trần Ngọc Quân 2015-12-31 08:21:42 UTC
Created attachment 318059 [details] [review]
Final patch

If the maintainers of this package don't reject, I will commit!
Thanks in advance!
Comment 7 Paolo Borelli 2015-12-31 08:59:33 UTC
Review of attachment 318059 [details] [review]:

Thanks for tracking this down. I think the approach is correct, though I wish we had a way to avoid the duplication.

I would change the code slightly to:

import gettext
try:
    gettext.bindtextdomain("gedit")
    _ = lambda s: gettext.dgettext("gedit", s);
except:
    _ = lambda s: s


This is what we do in the gedit-plugins package
Comment 8 Trần Ngọc Quân 2016-01-03 07:38:34 UTC
Created attachment 318178 [details] [review]
Install gettext for python module

This patch is only for quickopen. Other python plugins are the same.
Comment 9 Paolo Borelli 2016-01-03 08:38:38 UTC
Review of attachment 318178 [details] [review]:

I guess you used plain gettext instead of dgettext because "gedit" is already the default domain for the app. Is that correct?

If that is ok and of you tested, I am ok with committing such patch to all plugins
Comment 10 Trần Ngọc Quân 2016-01-04 01:17:41 UTC
(In reply to Paolo Borelli from comment #9)
> I guess you used plain gettext instead of dgettext because "gedit" is
> already the default domain for the app. Is that correct?
I use gettext.install, please see <https://docs.python.org/3/library/gettext.html#localizing-your-application>.
I wish we had a way to get domain from gedit instead of constant string.

> If that is ok and of you tested,
I tested with Vietnamese translation.
If you agree with this patch, I will commit or sent full version of git patch.
Comment 11 Paolo Borelli 2016-01-04 07:45:58 UTC
Sorry, I did not see the call to install()...  I am not sure if that is a good approach, it is supposed to be called once in an application, but in the case of gedit they are plugins. I think it would be better to just add the lambda to alias "_" to the correct call. I think we should try to simply alias it ti gettext() since gedit already called bindtextdomain.


In case we instead need to use dgettext, to avoid the hardcoded "gedit" domain we can generate a file from a .in file at configure time, like we do in gedit-plugins and then import it in every plugin, but honestly I think it is not worth it


Note: if someone more familiar with gettext, python etc tells me I am wrong, I am happy to change my mind.
Comment 12 Trần Ngọc Quân 2016-01-05 07:59:47 UTC
I'm really wrong! gettext.install() will effect all python plugins. If any plugin use a domain other than gedit, it will break.
I fixed it by reading python official doc[1], but I use gettext instead of lgettext. To avoid error:

Traceback (most recent call last):
  • File "/usr/lib/x86_64-linux-gnu/gedit/plugins/pythonconsole/__init__.py", line 59 in do_activate
    bottom.add_titled(self._console, "GeditPythonConsolePanel", _('Python Console'))
TypeError: Must be string, not bytes

I also tested snippet plugin with snippet domain, and it don't break others and itself.

The insert code into each __init__.py file is:

try:
    import gettext
    t = gettext.translation('gedit')
    _ = t.gettext
except:
    _ = lambda s: s


> generate a file from a .in file at configure time
I expect that we can use code like this:

from gi.repository import Gedit
domain=Gedit.domain
...
t = gettext.translation(domain)


[1] <https://docs.python.org/3/library/gettext.html#localizing-your-module>
Comment 13 Paolo Borelli 2016-01-05 11:26:54 UTC
my idea was to simply try the following:


try:
    import gettext
    _ = gettext.gettext
except:
    _ = lambda s: s



Because I expect that gedit already set "gedit" as the default domain. Can you try if this works? If yes, we would not have to do any magic for the domain.


Otherwise yes, we can try to do some magic to add the domain to the Gedit module
Comment 14 Trần Ngọc Quân 2016-01-06 07:10:18 UTC
Unfortunately, it don't work.
I recommend use as Comment 12. use gettext.translation('gedit') to avoid duplication as Comment 7.
In fact, these plugins that use gedit domain, is maintained in the same git repo with gedit, so we can use constant string for bind gettext domain. We don't need to add it into Gedit module.
Comment 15 Trần Ngọc Quân 2016-01-06 07:51:53 UTC
I retested again, and Comment 12 don't work as I expect.
We may turn back to add 

try:
    import gettext
    gettext.bindtextdomain('gedit')
    gettext.textdomain('gedit')
    _ = gettext.gettext
except:
    _ = lambda s: s

into wherever files that use _()
I will try to avoid duplication later.
Comment 16 Trần Ngọc Quân 2016-02-22 08:39:49 UTC
Created attachment 321815 [details] [review]
import gettext for all python file that call _()

Find out python files that call _() by:

$ grep '.py:' po/vi.po | cut -d: -f2 | sort | uniq

Then add following code for all of it:

+try:
+    import gettext
+    gettext.bindtextdomain('gedit')
+    gettext.textdomain('gedit')
+    _ = gettext.gettext
+except:
+    _ = lambda s: s
+

Python's import work very difference with #include in C/C++.
I've read `Dive Into Python'[1], but I can't find the way to reduce the duplication. Each Python file seem works independently (module).  
If you need our code more compact, require it in TODO. So other one may help us.

[1] <http://www.diveintopython.net>
Comment 17 Trần Ngọc Quân 2016-03-06 07:03:08 UTC
May I commit this patch to master branch?
Comment 18 Piotr Drąg 2016-09-07 14:18:17 UTC
Ping?
Comment 19 Piotr Drąg 2017-02-20 18:30:17 UTC
Any chance of landing this fix before 3.24?
Comment 20 Piotr Drąg 2017-08-01 21:58:23 UTC
Created attachment 356758 [details] [review]
plugins: Import gettext for all Python files with translations

Trần Ngọc Quân’s patch, git-formatted and with proper attribution.
Comment 21 George White 2017-08-03 18:20:57 UTC
Review of attachment 356758 [details] [review]:

Looks good, thank you Trần for providing the original patch, and Piotr for reformatting it and attributing Trần as the creator.
Comment 22 Piotr Drąg 2017-08-03 18:24:24 UTC
Comment on attachment 356758 [details] [review]
plugins: Import gettext for all Python files with translations

Thank you! Pushed:

https://git.gnome.org/browse/gedit/commit/?id=fee07ab0cb39fe81279b326280634ae989c30e09
Comment 23 Piotr Drąg 2017-08-03 18:24:45 UTC
This problem has been fixed in the unstable development version. The fix will be available in the next major software release. You may need to upgrade your Linux distribution to obtain that newer version.