Re: catching translation problems with pylint

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/05/2013 04:37 PM, Chris Lumens wrote:
I'm working on a pylint plugin that will allow us to enforce our
translation checks.  For instance, one we're all guilty of is doing
_("blah blah %s blah" % "blah") which of course results in bad
translations.  It turns out, we have all the technology needed to catch
that.  I've written a brief piece of code that does so.

What I'm wondering is what else along these lines I could catch.

* x = _("blah blah blah") at the module level?
* _("%s fs on %s") instead of _("%(fsType)s fs on %(deviceName)")?
If we can detect these, then yeah, catch 'em. For the first one, that would also apply to the class-level strings, which we have a lot of in the GUI spokes. I think they're all N_, but it'd be nice to be sure.
* Your favorite ideas here.

Would it be appropriate to check for markup strings through pylint? This one's a little complicated since sometimes we want markup, but only if it's applied to a part of the translatable string. I think the regex we'd want to reject as a bad translatable string is something like (here comes some angle brackets): '^(<[^>]*>)+[^<]*(</[^>]*>)+$' It's not perfect, but anything that looks that much like a markup string probably has something going wrong, anyway. The idea being:

>> print re.match('^(<[^>]*>)+[^<]*(</[^>]*>)+$', '<span font-desc="whatever">Markup applies to whole string</span>')
<_sre.SRE_Match object at 0x7f0ff33db360>
>>> print re.match('^(<[^>]*>)+[^<]*(</[^>]*>)+$', '<span font-desc="whatever"><b>Markup still applies to whole string</b></span>')
<_sre.SRE_Match object at 0x7f0ff33db3e8>
>>> print re.match('^(<[^>]*>)+[^<]*(</[^>]*>)+$', '<span font-desc="whatever">Markup applies to <b>part</b> of the string</span>')
None

Also don't forget the other translate functions for the _("blah blah %s" % "blah") check: C_ and CN_ would work the same way (you can just ignore the context argument), and for P_ and CP_ the rule applies to both the msgid and msgplural arguments (first and second args on P_, second and third args on CP_).

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list




[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux