the-djmaze / snappymail

Simple, modern & fast web-based email client
https://snappymail.eu
GNU Affero General Public License v3.0
1.03k stars 122 forks source link

Not able to get transaltion in unordered list #865

Closed avinash-0007 closed 1 year ago

avinash-0007 commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior: i have created a plugin but somehow transaltion is not getting called

<ul data-bind="foreach: aliases">
    <li>
        <span class="inputBox">
            <span class="inputText" style="user-select:text" data-bind="text: $data,attr: {id: 'alias' + $index()}"> </span>
            <span class="btncopy" data-bind="click: function ($data) { navigator.clipboard.writeText($data);var elementid='aliasbtn' + $index(); document.getElementById(elementid).innerHTML='COPIED';setTimeout(function() {document.getElementById(elementid).innerHTML = 'COPY';}, 2000) },attr: {id: 'aliasbtn' + $index()}" data-i18n="HIDE_MY_EMAIL/COPY"></span>
        </span>
    </li>
</ul>

this line data-i18n="HIDE_MY_EMAIL/COPY" is not showing the translated text inside ul but working outside ul

Expected behavior Should show the translation text

avinash-0007 commented 1 year ago

Also how to move javscript inside js folder @the-djmaze

the-djmaze commented 1 year ago

Try with i18nUpdate

<div data-bind="i18nUpdate: aliases">
    <ul data-bind="foreach: aliases">
        <li>
            <span class="inputBox">
                <span class="inputText" style="user-select:text" data-bind="text: $data,attr: {id: 'alias' + $index()}"> </span>
                <span class="btncopy" data-bind="click: function ($data) { navigator.clipboard.writeText($data);var elementid='aliasbtn' + $index(); document.getElementById(elementid).innerHTML='COPIED';setTimeout(function() {document.getElementById(elementid).innerHTML = 'COPY';}, 2000) },attr: {id: 'aliasbtn' + $index()}" data-i18n="HIDE_MY_EMAIL/COPY"></span>
            </span>
        </li>
    </ul>
</div>

how to move javscript inside js folder

You can look here for example https://github.com/the-djmaze/snappymail/tree/master/plugins/nextcloud

avinash-0007 commented 1 year ago

@the-djmaze thank you!! i will use the example. How can i use translation in js?

the-djmaze commented 1 year ago

How can i use translation in js?

I think it is rl.i18n but i should document everything from console.dir(rl)

avinash-0007 commented 1 year ago

@the-djmaze I tried moving the code in js

(rl => { if (rl) {

        class HMESettings
        {
                constructor()
                {
                        this.aliases = ko.observableArray();
                }
                copyMail($data)
                {
                   navigator.clipboard.writeText($data);
                   var elementid='aliasbtn' + $index();
                   document.getElementById(elementid).innerHTML=rl.i18n('HIDE_MY_EMAIL//COPIED');
                   setTimeout(function() {
                     document.getElementById(elementid).innerHTML = rl.i18n('HIDE_MY_EMAIL/COPY');
                   }, 2000);
                 }

                onBuild()
                {

                        rl.pluginRemoteRequest((iError, oData) => {
                                if (!iError) {

                                        this.aliases.push(JSON.parse(oData.Result.aliases));
                                }
                        }, 'JsonGetHMEAliases');

                }

        }
        rl.addSettingsViewModel(HMESettings, 'HMESectionTab',
                'HIDE_MY_EMAIL/TAB_NAME', 'hide-my-email');

        addEventListener('rl-view-model.create', e => {
                if ('SystemDropDown' === e.detail.viewModelTemplateID) {
                        document
                                .getElementById('SystemDropDown')
                                .content
                                .querySelector('menu .dividerbar + li + li')
                                .before(Element.fromHTML(`<li role="presentation">
                                                <a href="#/settings/hide-my-email" tabindex="-1" data-icon="✉" data-i18n="HIDE_MY_EMAIL/TAB_NAME"></a>
                                        </li>`));
                }
        });
}})(window.rl);

but it didnot work <span class="btncopy" data-bind="attr: {id: 'aliasbtn' + $index()},click: copyMail($data)" data-i18n="HIDE_MY_EMAIL/COPY"></span>

the-djmaze commented 1 year ago

Your code seems to work here. afbeelding

avinash-0007 commented 1 year ago

@the-djmaze this click function is not getting called

copyMail($data) { navigator.clipboard.writeText($data); var elementid='aliasbtn' + $index(); document.getElementById(elementid).innerHTML=rl.i18n('HIDE_MY_EMAIL//COPIED'); setTimeout(function() { document.getElementById(elementid).innerHTML = rl.i18n('HIDE_MY_EMAIL/COPY'); }, 2000); }

avinash-0007 commented 1 year ago

i want to call copy mail button on clicking this

<span class="btncopy" data-bind="attr: {id: 'aliasbtn' + $index()},click: copyMail($data)" data-i18n="HIDE_MY_EMAIL/COPY"></span>

the-djmaze commented 1 year ago

Because copyMail is inside the foreach, the scope is the alias. Use click: $root.copyMail" or click: $parent.copyMail".

More info at https://knockoutjs.com/documentation/click-binding.html

the-djmaze commented 1 year ago

Is your plugin working now?

avinash-0007 commented 1 year ago

YES