resolve TypeError in DNS resolution popup formatting by Biaogo · Pull Request #1353 · evilsocket/opensnitch (original) (raw)

Thanks for looking into this @Biaogo @AngelSherry !

This is a problem of the translation files, where the formatting modifier (%s, %d, ...) is changed from the expected position, for example:

opensnitch-zh_TW.ts:        <source>is attempting to resolve &lt;b&gt;%s&lt;/b&gt; via %s, %s port %d</source>
opensnitch-zh_TW.ts-        <translation>正試圖透過 %s,%s 連接埠 %d 解析 &lt;b&gt;%s&lt;/b&gt;</translation>

opensnitch-hi_IN.ts:        <source>is attempting to resolve &lt;b&gt;%s&lt;/b&gt; via %s, %s port %d</source>
opensnitch-hi_IN.ts-        <translation>%2$s, %3$s पोर्ट %4d के माध्यम से &lt;b&gt;%1$s&lt;/b&gt; को हल करने का प्रयास कर रहा है</translation>

We expect the integer value on the last position, but in some translations we receive it in another place.
I can reproduce it if I change the GUI language to hi_IN or zh_TW.

Instead of casting dst_port to str we could use:

            msg_action = QC.translate(
                "popups", "is attempting to resolve <b>{0}</b> via {1}, {2} port {3}".format(
                con.dst_host,
                con.dst_ip,
                con.protocol.upper(),
                con.dst_port,
            ))

(previous calls above that one should be updated as well).

We already had this problem in the past, my fault for not updating all the QC.translate() calls.