-
Notifications
You must be signed in to change notification settings - Fork 4
translate bone params category and tooltip in json renderer #180
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very awesome and useful feature. I would recommend it for ViUR 2.5.1, if possible.
Please check the other places I've marked.
render/json/default.py
Outdated
if not isinstance(params, dict): | ||
return params | ||
|
||
res = params.copy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ok, but the whole function can also be solved in one-liner
params = {key: _(value) for key, value in params.items() if key in ["category", "tooltip"]}
with the copy-stuff, it would be a three liner ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one-line will only create a dictionary with the keys category/tooltip. Others will be ignored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I said it's incomplete.
Here's the full code:
def preprocessParams(self, params):
"""
Translate params to support multilingual categories and tooltips.
:param params: Params dictionary which values should be translated. If we get no dictionary, we do nothing.
:type params: dict
:return: Params dictionary with translated values.
:rtype: dict
"""
if not isinstance(params, dict):
return params
params = params.copy()
params.update({key: _(value) for key, value in params.items() if key in ["category", "tooltip"]}
return params
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return {key: (_(value) if key in ["category", "tooltip"] else value) for key, value in params.items() }
? 😄
No seriously, this can break a lot of stuff. None of this had been ever translated (also not from jinja2 render) and i've seen a lot of code in projects that depends on the category being stable. This is probably a bigger issue we've have to address in Py3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return {key: (_(value) if key in ["category", "tooltip"] else value) for key, value in params.items() }
? smile
Perfect!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No seriously, this can break a lot of stuff. None of this had been ever translated (also not from jinja2 render) and i've seen a lot of code in projects that depends on the category being stable. This is probably a bigger issue we've have to address in Py3.
Why should this break stuff? I don't know any case where translating category or tooltip would break something. If a project has other special cases in relation to tooltip or category naming, the feature can be switched-off by overriding the function. This just a little improvement which is very useful for many of our projects. I totally agree with it.
dd948b5
to
e65aa2d
Compare
We should discus this on the next ViUR meeting. If we merge this we'll introduce a mismatch between json and every other render. If we patch the html render also we'll probably break something. You could also patch this in your project if needed. We'll definitely have to address this in Py3, for Py2 i'm unsure what to do. Patching json only would probably be safe (and i could live with the inconsistency for the remaining livespan of Py2). |
No description provided.