From f8f1ad2a27d27861fab9103f1cce075a684891c2 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 19 Apr 2019 13:47:16 -0700 Subject: [PATCH] closes #399 - missing translation of default groups (+ correcting subgroup layouts) --- README.md | 9 +-------- gooey/gui/components/config.py | 21 +++++++++++++++------ gooey/python_bindings/argparse_to_json.py | 4 ++-- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index d742126..894a4e8 100644 --- a/README.md +++ b/README.md @@ -236,18 +236,11 @@ Gooey is international ready and easily ported to your host language. Languages All program text is stored externally in `json` files. So adding new langauge support is as easy as pasting a few key/value pairs in the `gooey/languages/` directory. -Thanks to some awesome [contributers](https://github.com/chriskiehl/Gooey/graphs/contributors), Gooey currently comes pre-stocked with the following language sets: - -- English -- Dutch -- French -- Portuguese +Thanks to some awesome [contributers](https://github.com/chriskiehl/Gooey/graphs/contributors), Gooey currently comes pre-stocked with over 18 different translations! Want to add another one? Submit a [pull request!](https://github.com/chriskiehl/Gooey/compare) - - ------------------------------------------- diff --git a/gooey/gui/components/config.py b/gooey/gui/components/config.py index 433af1f..d260f67 100644 --- a/gooey/gui/components/config.py +++ b/gooey/gui/components/config.py @@ -4,7 +4,7 @@ from wx.lib.scrolledpanel import ScrolledPanel from gooey.gui.components.util.wrapped_static_text import AutoWrappedStaticText from gooey.gui.util import wx_util from gooey.util.functional import getin, flatmap, compact, indexunique - +from gooey.gui.lang.i18n import _ class ConfigPage(ScrolledPanel): def __init__(self, parent, rawWidgets, buildSpec, *args, **kwargs): @@ -22,6 +22,16 @@ class ConfigPage(ScrolledPanel): ## of (a) not being nearly granular enough (for instance, `-v` could represent totally different ## things given context/parser position), and (b) cannot identify positional args. + def getName(self, group): + """ + retrieve the group name from the group object while accounting for + legacy fixed-name manual translation requirements. + """ + name = group['name'] + return (_(name) + if name in {'optional_args_msg', 'required_args_msg'} + else name) + def firstCommandIfPresent(self, widget): commands = widget._meta['commands'] @@ -82,7 +92,6 @@ class ConfigPage(ScrolledPanel): self.makeGroup(self, sizer, item, 0, wx.EXPAND | wx.ALL, 10) self.SetSizer(sizer) - def makeGroup(self, parent, thissizer, group, *args): ''' Messily builds the (potentially) nested and grouped layout @@ -96,13 +105,13 @@ class ConfigPage(ScrolledPanel): # determine the type of border , if any, the main sizer will use if getin(group, ['options', 'show_border'], False): - boxDetails = wx.StaticBox(parent, -1, group['name'] or '') + boxDetails = wx.StaticBox(parent, -1, self.getName(group) or '') boxSizer = wx.StaticBoxSizer(boxDetails, wx.VERTICAL) else: boxSizer = wx.BoxSizer(wx.VERTICAL) boxSizer.AddSpacer(10) if group['name']: - groupName = wx_util.h1(parent, group['name'] or '') + groupName = wx_util.h1(parent, self.getName(group) or '') groupName.SetForegroundColour(getin(group, ['options', 'label_color'])) boxSizer.Add(groupName, 0, wx.TOP | wx.BOTTOM | wx.LEFT, 8) @@ -138,8 +147,8 @@ class ConfigPage(ScrolledPanel): hs.AddSpacer(5) # self.makeGroup(parent, hs, subgroup, 1, wx.ALL | wx.EXPAND, 5) - if e % getin(group, ['options', 'columns'], 2) \ - or e == len(group['groups']): + itemsPerColumn = getin(group, ['options', 'columns'], 2) + if e % itemsPerColumn or (e + 1) == len(group['groups']): boxSizer.Add(hs, *args) hs = wx.BoxSizer(wx.HORIZONTAL) diff --git a/gooey/python_bindings/argparse_to_json.py b/gooey/python_bindings/argparse_to_json.py index c6a16f6..458a7c5 100644 --- a/gooey/python_bindings/argparse_to_json.py +++ b/gooey/python_bindings/argparse_to_json.py @@ -199,9 +199,9 @@ def apply_default_rewrites(spec): contents = getin(spec, path) for group in contents: if group['name'] == 'positional arguments': - group['name'] = 'Required Arguments' + group['name'] = 'required_args_msg' if group['name'] == 'optional arguments': - group['name'] = 'Optional Arguments' + group['name'] = 'optional_args_msg' return spec