Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

translate bone params category and tooltip in json renderer #180

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

sveneberth
Copy link
Member

No description provided.

Copy link
Member

@phorward phorward left a 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.

CHANGELOG.md Outdated Show resolved Hide resolved
render/json/default.py Show resolved Hide resolved
if not isinstance(params, dict):
return params

res = params.copy()
Copy link
Member

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 ;-)

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Contributor

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.

Copy link
Member

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!

@sveneberth sveneberth requested a review from phorward August 1, 2019 09:39
phorward
phorward previously approved these changes Aug 1, 2019
Copy link
Member

@phorward phorward left a 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.

modules/user.py Outdated Show resolved Hide resolved
render/json/default.py Show resolved Hide resolved
@tsteinruecken
Copy link
Contributor

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).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants