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

Localize tkinter.simpledialog.Default buttons as with file dialogs. #75794

Open
jcrmatos mannequin opened this issue Sep 27, 2017 · 7 comments
Open

Localize tkinter.simpledialog.Default buttons as with file dialogs. #75794

jcrmatos mannequin opened this issue Sep 27, 2017 · 7 comments
Labels
3.7 (EOL) end of life topic-tkinter type-feature A feature request or enhancement

Comments

@jcrmatos
Copy link
Mannequin

jcrmatos mannequin commented Sep 27, 2017

BPO 31613
Nosy @terryjreedy, @serhiy-storchaka, @jcrmatos, @hisahi
PRs
  • bpo-31613: Localize tkinter.simpledialog button texts #31682
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2017-09-27.17:14:51.420>
    labels = ['3.7', 'type-feature', 'expert-tkinter']
    title = 'Localize tkinter.simpledialog.Default buttons as with file dialogs.'
    updated_at = <Date 2022-03-04.14:30:18.674>
    user = 'https://github.com/jcrmatos'

    bugs.python.org fields:

    activity = <Date 2022-03-04.14:30:18.674>
    actor = 'sampo.hippelainen'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Tkinter']
    creation = <Date 2017-09-27.17:14:51.420>
    creator = 'jcrmatos'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31613
    keywords = ['patch']
    message_count = 7.0
    messages = ['303162', '303169', '303173', '303182', '303383', '303384', '414529']
    nosy_count = 5.0
    nosy_names = ['terry.reedy', 'python-dev', 'serhiy.storchaka', 'jcrmatos', 'sampo.hippelainen']
    pr_nums = ['31682']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue31613'
    versions = ['Python 3.7']

    @jcrmatos
    Copy link
    Mannequin Author

    jcrmatos mannequin commented Sep 27, 2017

    Hello,

    tkinter.simpledialog default buttons (not buttonbox) are not localized, unlike all messagebox.

    Best regards,

    JM

    @jcrmatos jcrmatos mannequin added type-bug An unexpected behavior, bug, or error topic-tkinter labels Sep 27, 2017
    @jcrmatos
    Copy link
    Mannequin Author

    jcrmatos mannequin commented Sep 27, 2017

    Hello,

    Here is some example code:

    from tkinter import Label, Tk
    from tkinter.simpledialog import Dialog
    
    
    class CalendarDialog(Dialog):
        def __init__(self, parent, title='', year=0, month=0):
            self.year = year  # type: int
            self.month = month  # type: int
    
            Dialog.__init__(self, parent, 'Select a date')
    
        def body(self, parent):
            Label(parent, text='A label').pack()
    
    
    master = Tk()
    result = CalendarDialog(master, year=2017, month=9).result
    master.mainloop()

    Best regards,

    JM

    @serhiy-storchaka
    Copy link
    Member

    What do you expect and what do you get?

    @jcrmatos
    Copy link
    Mannequin Author

    jcrmatos mannequin commented Sep 27, 2017

    Hello,

    I would expect the same behaviour as askopenfilename from tkinter.filedialog where the buttons are localized (in my case in Portuguese).

    What I get is the buttons (in tkinter.simpledialog) are always in English.

    Best regards,

    JM

    @terryjreedy
    Copy link
    Member

    Tkinter wraps the tcl/tk gui framework. The file dialogs and messageboxes are provided by tk. When possible, the file dialogs utilize the native OS file dialogs. The localization is done the by the OS. If the messageboxes are localized, then I presume the same is true of them also.

    tkinter.simpledialog is a tkinter add-on module written in Python, using tk widgets. SimpleDialog does not have default buttons; they must be supplied in the initialization call. Dialog does provide default *example* buttons. The docstring says "override if you do not want the standard buttons".

    Tk does not provide localized [Ok] and [Cancel] buttons. AFAIK, Python does not provide access to the OS local translations. You will have to provide localization yourself.

    A reasonable enhancement request might be to add "ok='OK', cancel='Cancel'" to the signature of Dialog.__init__ so that a user could pass in local translations. These would then be passed on to buttonbox, to be used instead of the current hard-coded strings.

    @terryjreedy terryjreedy added the 3.7 (EOL) end of life label Sep 30, 2017
    @terryjreedy terryjreedy changed the title tkinter.simpledialog default buttons (not buttonbox) are not localized, unlike all messagebox Localize tkinter.simpledialog.Default buttons as with file dialogs. Sep 30, 2017
    @terryjreedy terryjreedy added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Sep 30, 2017
    @terryjreedy
    Copy link
    Member

    I would make such new paremeters keyword-only.

    @hisahi
    Copy link
    Mannequin

    hisahi mannequin commented Mar 4, 2022

    Tk does not provide localized [Ok] and [Cancel] buttons.

    This is not true. You can call ::msgcat::mc to localize core strings such as "OK" and "Cancel".

    The full tk.call becomes

        tk.call("namespace", "eval", "::tk", "::msgcat::mc", s)

    to translate a string s, such as "OK".

    I have made a custom modified version of simpledialog.py that makes use of this and indeed localizes the OK/Cancel buttons as they would be localized for tk messageboxes (which use Tcl/Tk Core localization). I submitted this now as a GitHub PR.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life topic-tkinter type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants