luci-app-commands: use client side translation in JavaScript blocks
authorJo-Philipp Wich <redacted>
Sat, 27 Jul 2024 23:06:25 +0000 (01:06 +0200)
committerJo-Philipp Wich <redacted>
Sat, 27 Jul 2024 23:08:01 +0000 (01:08 +0200)
Do not interpolate translated strings on the server side, use browser
side translation calls instead to avoid potential quote escaping issues.

Fixes: #7213
Fixes: 119fd22ebf ("luci-app-commands: replace i18n single quotes with double-quotes")
Signed-off-by: Jo-Philipp Wich <redacted>
applications/luci-app-commands/ucode/template/commands.ut

index 8e5ce0b4862de7f75cdd97ec9f116be576a2b62c..48850598d7a33beb11a286b87533ef1650b2ee3e 100644 (file)
@@ -45,7 +45,7 @@
                {
                        output.innerHTML =
                                '<img src="{{ resource }}/icons/loading.gif" alt="{{ _('Loading') }}" style="vertical-align:middle" /> ' +
-                               '{{ _('Waiting for command to complete...') }}'
+                               _('Waiting for command to complete...')
                        ;
 
                        legend.parentNode.style.display = 'block';
                                        if (st)
                                        {
                                                if (st.binary)
-                                                       st.stdout = '[{{ _('Binary data not displayed, download instead.') }}]';
+                                                       st.stdout = '[' + _('Binary data not displayed, download instead.') + ']';
 
                                                legend.style.display = 'none';
                                                output.innerHTML = String.format(
                                                        '<pre><strong># %h\n</strong>%h<span style="color:red">%h</span></pre>' +
-                                                       '<div class="alert-message warning">%s ({{ _('Code:') }} %d)</div>',
+                                                       '<div class="alert-message warning">%h (%h %d)</div>',
                                                        st.command, st.stdout, st.stderr,
-                                                       (st.exitcode == 0) ? '{{ _('Command successful') }}' : '{{ _('Command failed') }}',
-                                                       st.exitcode);
+                                                       (st.exitcode == 0) ? _('Command successful') : _('Command failed'),
+                                                       _('Code:'), st.exitcode);
                                        }
                                        else
                                        {
                                                legend.style.display = 'none';
-                                               output.innerHTML = '<span class="error">{{ _('Failed to execute command!') }}</span>';
+                                               output.innerHTML = '<span class="error">%h</span>'.format(_('Failed to execute command!'));
                                        }
 
                                        location.hash = '#output';
                        legend.style.display = 'none';
                        output.parentNode.style.display = 'block';
                        output.innerHTML = String.format(
-                               '<div class="alert-message"><p>{{ _('Download execution result') }} <a href="%s">%s</a></p><p>{{ _('Or display result') }} <a href="%s">%s</a></p></div>',
-                               link, link, link_nodownload, link_nodownload
+                               '<div class="alert-message"><p>%h <a href="%s">%s</a></p><p>%h <a href="%s">%s</a></p></div>',
+                               _('Download execution result'), link, link,
+                               _('Or display result'), link_nodownload, link_nodownload
                        );
 
                        location.hash = '#output';
git clone https://git.99rst.org/PROJECT