GNOME Bugzilla – Bug 737497
Some plugins are not translated
Last modified: 2019-03-23 20:54:31 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)
The same here, in Hebrew (100% translated, the DL just think some strings are fuzzy but they are not).
In 3.16 the names and descriptions of plugins are correctly translated, but their UI is still a mix of English and Polish.
*** Bug 654186 has been marked as a duplicate of this bug. ***
*** Bug 756800 has been marked as a duplicate of this bug. ***
Created attachment 313998 [details] [review] Python module don't import texttext Note: Don't commit this patch. It's only for review!
Created attachment 318059 [details] [review] Final patch If the maintainers of this package don't reject, I will commit! Thanks in advance!
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
Created attachment 318178 [details] [review] Install gettext for python module This patch is only for quickopen. Other python plugins are the same.
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
(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.
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.
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):
+ Trace 235870
bottom.add_titled(self._console, "GeditPythonConsolePanel", _('Python Console'))
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>
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
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.
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.
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>
May I commit this patch to master branch?
Ping?
Any chance of landing this fix before 3.24?
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.
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 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
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.