[Idle-dev] Forking Idle - translating menus, etc.

Andre Roberge andre.roberge at gmail.com
Mon May 27 12:42:52 EDT 2019


Sigh ... I "spoke" too soon.

Last night, as a final sanity check, I had put a hard-return in the
function that provided the translations so that it would return the
original, untranslated label.  This is the code that I just ran.  The
traceback is unfortunately still there.

André Roberge

On Mon, May 27, 2019 at 1:37 PM Andre Roberge <andre.roberge at gmail.com>
wrote:

> Hello everyone,
>
> Please ignore the traceback mentioned in the previous email. I made a few
> changes and got rid of the traceback.
>
> The good news: IDLE starts and appear to work correctly.
> The bad news: the menu items are not changed to the test "uppercase"
> language.
>
> I will try to figure out how to fix this.
>
> André Roberge
>
> On Sun, May 26, 2019 at 10:00 PM Andre Roberge <andre.roberge at gmail.com>
> wrote:
>
>> I have started working on a possible implementation for providing
>> translations for IDLE's menu.  Right now, it generates a traceback which
>> stumps me. Regardless, before I spend more time trying to figure out what
>> goes on, I thought it would be a good idea to see if the approach I have in
>> mind would be acceptable.
>>
>> Copying the docstring of the main module I wrote:
>>
>> """This module is intended to provide translations of menu items.
>>
>> Instead of trying to approve translations for inclusion in Python's
>> standard
>> library, translations would be obtained separately by the end users and
>> be located in a place from where they could be imported.
>> This could be done by having a user put a translation file in their home
>> directory or install them from Pypi.
>>
>> A translation file could have any name.  However, its content would have
>> to include a dict named "idle_translation" whose content would include
>> at least one language, with the possibility of having more, and
>> would have the following structure
>>
>> idle_translation = {
>>     "fr": { "File" : "Fichier", ...},
>>     "es": {"File": "Archivo", ...}     # not sure of the Spanish term
>> }
>>
>> The addition of a directory would be done through the configuration
>> menu and the name of the translation file would be saved in the user's
>> configuration file.
>>
>> In case it is needed, we compile a reverse dictionary; but we have not
>> gotten far enough to use it yet.
>>
>> """
>>
>> The essence of the implementation can be described as follows:
>>
>> Existing code (one example copy-pasted from editor.py)
>>
>> menu.add_command(label=label, underline=underline,
>>                                          command=command,
>>                                          accelerator=accelerator)
>>
>> New code
>>
>> label = translator.get(label)  # single line added
>>
>> menu.add_command(label=label, underline=underline,
>>                                          command=command,
>>                                          accelerator=accelerator)
>>
>> Where translator.get(label) can be thought of as a function like the
>> following:
>>
>> def get_translation(label):
>>     if translation_exists(user_language, label):
>>         return translation_of(user_language, label)
>>     else:
>>         return label
>>
>> The actual code is a bit more complicated.
>>
>> = = =
>> I admit to not really knowing how best to proceed with using git on a
>> project like this.
>> What I did is the following:
>> 1. I cloned the cpython repository;
>> 2. I created a local branch which I called "idle-translation-dev".
>> 3. Trying to run "python -m idlelib", I got a traceback as "_pickle"
>> could not be found when pickle was processed. So, I changed the name of
>> "pickle.py" so that it would import the version from Python installed from
>> my computer.  That allowed me to proceed and explain the strange file
>> renaming you might see if you look at the commit.
>>
>> What I did can be viewed in this single commit:
>>
>>
>> https://github.com/aroberge/cpython/commit/8e329288cf1e97d35ecc2b9b65fafb9e2190d361
>>
>>
>> The traceback I got (preceded by two print statement I included in an
>> attempt to figure out what went wrong) is the following:
>>
>> menu =  options index =  *Code Context state =  disabled
>> menuitem =  .!menu.options
>> Traceback (most recent call last):
>>   File "C:\Users\andre\github\cpython\Lib\runpy.py", line 193, in
>> _run_module_as_main
>>     "__main__", mod_spec)
>>   File "C:\Users\andre\github\cpython\Lib\runpy.py", line 85, in _run_code
>>     exec(code, run_globals)
>>   File "C:\Users\andre\github\cpython\Lib\idlelib\__main__.py", line 7,
>> in <module>
>>     idlelib.pyshell.main()
>>   File "C:\Users\andre\github\cpython\Lib\idlelib\pyshell.py", line 1521,
>> in main
>>     shell = flist.open_shell()
>>   File "C:\Users\andre\github\cpython\Lib\idlelib\pyshell.py", line 328,
>> in open_shell
>>     self.pyshell = PyShell(self)
>>   File "C:\Users\andre\github\cpython\Lib\idlelib\pyshell.py", line 879,
>> in __init__
>>     OutputWindow.__init__(self, flist, None, None)
>>   File "C:\Users\andre\github\cpython\Lib\idlelib\outwin.py", line 81, in
>> __init__
>>     self.update_menu_state('options', '*Code Context', 'disabled')
>>   File "C:\Users\andre\github\cpython\Lib\idlelib\editor.py", line 462,
>> in update_menu_state
>>     menuitem.entryconfig(index, state=state)
>>   File "C:\Users\andre\github\cpython\Lib\tkinter\__init__.py", line
>> 3354, in entryconfigure
>>     return self._configure(('entryconfigure', index), cnf, kw)
>>   File "C:\Users\andre\github\cpython\Lib\tkinter\__init__.py", line
>> 1627, in _configure
>>     self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
>> _tkinter.TclError: bad menu entry index "*Code Context"
>>
>>
>> I *suspect* that it is because other places required translations to my
>> fictitious uppercase language
>> before reaching that point, resulting in some inconsistencies ...
>>  but it seemed like a good place to stop to get some feedback
>> as to whether or not this approach would be acceptable.
>>
>>
>> André Roberge
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/idle-dev/attachments/20190527/190e459d/attachment-0001.html>


More information about the IDLE-dev mailing list