0

I am working on pdp page (mobile view), in drop down i need to show out of stock if qty is out of stock and low stock if qty is low stock, it is working as expected but it is not getting translated to other language (translation issue). My file is SwatchRenderer.js (D:app\design\frontend\Alshaya\mcmenablank\Magento_Swatches\web\js\SwatchRenderer.js)

define(['jquery', 'underscore', 'jquery/ui', 'mage/translate'], function ($, _) {
    'use strict';
     //code here
     .......
     .......
                if (stockStatus === undefined) {
                    label += ' - ' + $.mage.__('Out of stock');
                }
                if (stockStatus) {
                    /* Display Low stock message */
                    if (stockStatus['qty'] <= stockStatus['notifyQty']) {
                        label += ' - ' + $.mage.__('low stock');
                    }
                }
        ............................
        ...............................
2
  • Delete js-translation.json in pub/static/frontend/VendorTheme and try to run static content deploy again. Sep 15, 2016 at 10:28
  • "Out of stock":"\u0646\u0641\u062f\u062a \u0627\u0644\u0643\u0645\u064a\u0629" coming in js-translation.json but it is not fetching in frontend. Sep 15, 2016 at 11:14

1 Answer 1

0

Try to add the code below to your phtml file.

<?php
$_data = array(
    'Out of stock' => __('Out of stock'),
);
?>
<script type="text/javascript">
    require(["jquery", "mage/translate"], 
    function ($) {
        $.mage.translate.add(<?php echo Zend_Json::encode($_data) ?>)
    });
</script>
1
  • Remember - Zend_Json::encode would need to be updated to \Laminas\Json\Json::decode for Magento 2.4.6 onwards
    – elfling
    Mar 12 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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