Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not add string to underscore template using knockout #18012

Closed
DanielRuf opened this issue Sep 11, 2018 · 15 comments
Closed

Can not add string to underscore template using knockout #18012

DanielRuf opened this issue Sep 11, 2018 · 15 comments
Assignees
Labels
Component: Theme Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch

Comments

@DanielRuf
Copy link
Contributor

DanielRuf commented Sep 11, 2018

Preconditions

  1. Magento 2.4-develop

Steps to reproduce

  1. create custom theme based on Luma
  2. extend Magento_Theme/frontend/web/templates/breadcrumbs.html
  3. add string to breadcrumbs.html using knockout
<ul class="items">
    <!-- ko i18n: 'You are here:' --><!-- /ko -->
    <% _.each(breadcrumbs, function(crumb) { %>
        <li class="item <%- crumb.name %>">
            <% if (crumb.link) { %>
            <a href="<%= crumb.link %>" title="<%- crumb.title %>"><%- crumb.label %></a>
            <% } else if (crumb.last) { %>
            <strong><%- crumb.label %></strong>
            <% } else { %>
            <%- crumb.label %>
            <% } %>
        </li>
    <% }); %>
    </ul>

Expected result

  1. the string "You are here:"
    image

Actual result

  1. No string shown
    image
@magento-engcom-team
Copy link
Contributor

Hi @DanielRuf. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me {$VERSION} instance

where {$VERSION} is version tags (starting from 2.2.0+) or develop branches (2.2-develop +).
For more details, please, review the Magento Contributor Assistant documentation.

@DanielRuf do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Sep 11, 2018
@DanielRuf
Copy link
Contributor Author

It seems only <%= jQuery.mage.__('You are here:') %> works. <%= $.mage.__('You are here:') %> does not.

@ghost ghost self-assigned this Sep 11, 2018
@ghost ghost added the Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed label Sep 11, 2018
@ghost
Copy link

ghost commented Sep 11, 2018

Hi @DanielRuf I'm not able to reproduce by following steps you described, in my case i ovveride
breadcrumbs.phtml with this code

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php if ($crumbs && is_array($crumbs)) : ?>
    <div class="breadcrumbs">
        <ul class="items">
            <!-- ko i18n: 'You are here:' --><!-- /ko -->
            <?php foreach ($crumbs as $crumbName => $crumbInfo) : ?>
                <li class="item <?= /* @escapeNotVerified */ $crumbName ?>">
                    <?php if ($crumbInfo['link']) : ?>
                        <a href="<?= /* @escapeNotVerified */ $crumbInfo['link'] ?>" title="<?= $block->escapeHtml($crumbInfo['title']) ?>"><?= $block->escapeHtml($crumbInfo['label']) ?></a>
                    <?php elseif ($crumbInfo['last']) : ?>
                        <strong><?= $block->escapeHtml($crumbInfo['label']) ?></strong>
                    <?php else: ?>
                        <?= $block->escapeHtml($crumbInfo['label']) ?>
                    <?php endif; ?>
                </li>
            <?php endforeach; ?>
        </ul>
    </div>
<?php endif; ?>

selection_072

@DanielRuf
Copy link
Contributor Author

breadcrumbs.phtml with this code

This is wrong, I mean breadcrumbs.html, please read again.

@DanielRuf
Copy link
Contributor Author

Magento_Theme/frontend/web/templates/breadcrumbs.html

@DanielRuf
Copy link
Contributor Author

DanielRuf commented Sep 11, 2018

<ul class="items">
    <!-- ko i18n: 'You are here:' --><!-- /ko -->
    <% _.each(breadcrumbs, function(crumb) { %>
        <li class="item <%- crumb.name %>">
            <% if (crumb.link) { %>
            <a href="<%= crumb.link %>" title="<%- crumb.title %>"><%- crumb.label %></a>
            <% } else if (crumb.last) { %>
            <strong><%- crumb.label %></strong>
            <% } else { %>
            <%- crumb.label %>
            <% } %>
        </li>
    <% }); %>
    </ul>

@DanielRuf
Copy link
Contributor Author

#18012 (comment)

@ghost ghost added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Component: Theme and removed Progress: needs update labels Sep 11, 2018
@ghost
Copy link

ghost commented Sep 11, 2018

@DanielRuf , thank you for your report.
We've acknowledged the issue and added to our backlog.

@ghost ghost added the Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release label Sep 11, 2018
@ghost ghost removed their assignment Sep 11, 2018
@jayankaghosh
Copy link
Contributor

Since Magento_Theme/frontend/web/templates/breadcrumbs.html is an underscore template, wouldn't knockout bindings not work anyhow here?

And <%= $.mage.__('You are here:') %> doesn't work because the variable $ wasn't passed to the underscore templating engine while parsing the breadcrumbs template.

<%= jQuery.mage.__('You are here:') %> works since the variable jQuery is defined in the window object.

Am I missing something here?

@DanielRuf
Copy link
Contributor Author

And <%= $.mage.__('You are here:') %> doesn't work because the variable $ wasn't passed to the underscore templating engine while parsing the breadcrumbs template.

<%= jQuery.mage.__('You are here:') %> works since the variable jQuery is defined in the window object.

Am I missing something here?

Exactly.

Since Magento_Theme/frontend/web/templates/breadcrumbs.html is an underscore template, wouldn't knockout bindings not work anyhow here?

Not sure how it should look like but the docs are not clear here.
See https://devdocs.magento.com/guides/v2.0/frontend-dev-guide/translations/translate_theory.html

@jayankaghosh
Copy link
Contributor

What could be done is, under the underscore object, an i18n method could be introduced, so that translations would work if we wrote something like <%= _.i18n('You are here:') %>

@m2-assistant
Copy link

m2-assistant bot commented Dec 27, 2019

Hi @engcom-Charlie. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 2. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


@engcom-Charlie engcom-Charlie added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed and removed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development labels Dec 27, 2019
@engcom-Charlie engcom-Charlie added the Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch label Dec 27, 2019
@ghost ghost unassigned engcom-Charlie Dec 27, 2019
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-Charlie
Thank you for verifying the issue. Based on the provided information internal tickets MC-30107 were created

Issue Available: @engcom-Charlie, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Dec 27, 2019
@sergiy-v sergiy-v self-assigned this Jan 17, 2020
@m2-assistant
Copy link

m2-assistant bot commented Jan 17, 2020

Hi @sergiy-v. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 2. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


sergiy-v pushed a commit to sergiy-v/magento2 that referenced this issue Jan 17, 2020
sergiy-v pushed a commit to sergiy-v/magento2 that referenced this issue Jan 20, 2020
sergiy-v pushed a commit to sergiy-v/magento2 that referenced this issue Jan 20, 2020
sergiy-v pushed a commit to sergiy-v/magento2 that referenced this issue Jan 23, 2020
sergiy-v pushed a commit to sergiy-v/magento2 that referenced this issue Jan 23, 2020
@slavvka
Copy link
Member

slavvka commented Feb 7, 2020

@slavvka slavvka added the Fixed in 2.4.x The issue has been fixed in 2.4-develop branch label Feb 7, 2020
@slavvka slavvka closed this as completed Feb 7, 2020
magento-engcom-team added a commit that referenced this issue Feb 7, 2020
…lates for translation #26435

 - Merge Pull Request #26435 from sergiy-v/magento2:18012-add-translation-to-underscore
 - Merged commits:
   1. 819c3f2
   2. 064ee0e
   3. 3a19f17
   4. c32b643
   5. e26bbc1
   6. 69d07c1
   7. 58adcc5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Theme Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch
Projects
None yet
Development

No branches or pull requests

6 participants