-
Notifications
You must be signed in to change notification settings - Fork 36
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
Skip empty attributes to translate. #38
Conversation
Sounds sensible to me. |
I briefly looked at the code (though I don't pretend to fully understand the translation mechanics) and it looks to me as if your patch just prevents the translated value to be inserted in the final HTML, right? So the empty string will be extracted but the translation won't be inserted? My idea was that empty strings might be skipped during extraction (not sure if that is feasible in Genshi currently).
|
Yes.
Yes.
I temporarily added the following test, but it passes without my patch: + def test_extract_included_empty_attribute_text(self):
+ tmpl = MarkupTemplate(u"""<html>
+ <span title="">...</span>
+ </html>""")
+ translator = Translator()
+ messages = list(translator.extract(tmpl.stream))
+ self.assertEqual([], messages)
+ Investigating the source, Genshi (0.7.5) skips empty attributes at https://github.com/edgewall/genshi/blob/0.7.5/genshi/filters/i18n.py#L918-L921. Also, I noticed spaces in string are stripped during the extraction. I think we should strip spaces in string during the translation, too. |
Root cause is that For example, Workaround is preventing the translation by using expression in attribute, e.g. |
@@ -711,8 +711,9 @@ def __call__(self, stream, ctxt=None, translate_text=True, | |||
for name, value in attrs: | |||
newval = value | |||
if isinstance(value, six.string_types): | |||
if translate_attrs and name in include_attrs: | |||
newval = gettext(value) | |||
text = value.strip() |
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.
It took me awhile to understand why value.strip()
is needed (because the value is stripped by Genshi during extraction) and why and text
is needed (because gettext
doesn't support being passed empty strings), so thank you very much to everyone who supplied explanations in the comments.
@jun66j5 Thank you for the patch! |
I encountered that Genshi generates placeholder with *.po header for empty placeholder like this:
to:
Another example of empty
alt
attribute in https://trac.edgewall.org/ticket/10108#comment:2.I think we should skip empty attributes to translate.