Search code examples
eclipsepydevgettext

Is there a quick way to add gettext() calls to strings in PyDev?


Is there a quick way to add a gettext() call to a literal string in the PyDev editor running under Eclipse? I.e. when I place the cursor on any literal 'string' in a Python file, I want to turn this into _('string') with a single keypress. Can I use macros or something like that to add such functions?


Solution

  • It should be possible to do that with some simple Python scripting inside PyDev.

    Take a look at: http://pydev.org/manual_articles_scripting.html (you can use https://github.com/aptana/Pydev/blob/master/plugins/org.python.pydev.jython/jysrc/pyedit_import_to_string.py as an example).

    For the text selection, the PySelection implementation may be found at: https://github.com/aptana/Pydev/blob/master/plugins/org.python.pydev.core/src/org/python/pydev/core/docutils/PySelection.java (so, you can see how getSelectedText and work your own version to get the text you want).