1

I'm using a modal to show conditions for subscribing to a newsletter list. But I'm having trouble translating the title when initializing the modal inside a phtml file.

The modal opens normally, but seems the mage/translate component doesn't successfully translate the title.

If I use title: <?php echo _('Test string') ?> it will translate normally, but shouldn't using $.mage.__('Test string') also work?

This is what I have in phtml:

    <script>
    require([
        'jquery',
        'Magento_Ui/js/modal/modal',
        'mage/translate'
    ], function ($, modal) {
        var options = {
            type: 'popup',
            modalClass: 'newsletter-conditions-modal',
            responsive: true,
            innerScroll: true,
            title: $.mage.__('Test string'),
            buttons: []
        };
        $(function () {
            $('.newsletter-conditions').on('click',function() {
                $(".newsletter-conditions-content").modal(options).modal('openModal');
            })
        });
    });
    </script>

And this is what I have in my csv translate file:

Test string,Test string 2,module,Magento_Ui

Can anyone tell me why this isn't working?

1

Came here for the same issue. But found out you will need to use php to get it translated.

title: "<?php echo __('Test string')?>"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.