isso icon indicating copy to clipboard operation
isso copied to clipboard

Overriding translation string fails for count.min.js

Open ScootRay opened this issue 3 years ago • 1 comments

Hi,

I'm trying to adjust the capitalization of One Comment to One comment & 0 Comments to 0 comments by inserting this line in the client embed code:

    <script data-isso="//comments.test.com/" src="//comments.test.com/js/count.min.js"
    data-isso-num-comments-text-en="One comment\n{{ n }} comments"></script>

This doesn't work, the browser shows it verbatim, i.e. "One comment\n{{ n }} comments" so I'm guessing this isn't possible where variables are involved, right?

Any ideas for a workaround?

Thanks! Ray

ScootRay avatar Jul 03 '22 23:07 ScootRay

You've found a valid bug, thank you. The core issue is that HTML literal \n attribute strings get escaped to \\n in Javascript land.

My idea for a fix would be:

--- a/isso/js/app/i18n.js
+++ b/isso/js/app/i18n.js
@@ -131,7 +131,8 @@ if (!plural || !translations) {
 }
 
 var translate = function(msgid) {
-    return config[msgid + '-text-' + lang] ||
+    return (config[msgid + '-text-' + lang]
+            && config[msgid + '-text-' + lang].replace("\\n", "\n")) ||
       translations[msgid] ||
       en[msgid] ||
       "[?" + msgid + "]";

I'm still working on tests though. You can tackle this issue as well if you like.

ix5 avatar Jul 06 '22 22:07 ix5