magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.54k stars 9.32k forks source link

Theme translation is not respected in rest requests #26333

Closed bernd-reindl closed 7 months ago

bernd-reindl commented 4 years ago

Preconditions (*)

  1. Magento 2.3.3

Steps to reproduce (*)

  1. configure de_DE als store language
  2. add de_DE.csv to template localization (app/design/Vendor/base/i18n/de_DE.csv)
  3. Add "The coupon code isn't valid. Verify the code and try again.","Der Gutscheincode ist nicht gültig. Überprüfen Sie den Code und versuchen Sie es erneut." to de_DE.csv
  4. Add a product to cart
  5. goto checkout page
  6. enter an invalid coupon code

Expected result (*)

  1. the error message should be in german

Actual result (*)

  1. the error message is english
  2. If the translation is in a module folder (app/code/Vendor/Package/i18n/de_DE.csv) the translation work.
  3. Also the translation of an language package works
m2-assistant[bot] commented 4 years ago

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

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 give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

@bernd-reindl do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?


bernd-reindl commented 4 years ago

i confirm

m2-assistant[bot] commented 4 years ago

Hi @engcom-Charlie. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

magento-engcom-team commented 4 years ago

:white_check_mark: Confirmed by @engcom-Charlie Thank you for verifying the issue. Based on the provided information internal tickets MC-30382 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.

ghost commented 4 years ago

Same here. M 2.3.2

stkrelax commented 4 years ago

Same here. M 2.3.3

duckchip commented 4 years ago

@magento-engcom-team When can this ticket be picked up?

CIT-SW commented 4 years ago

Just a workaround but you can force the theme translations in a custom rest endpoint by using the frontend store emulation with the force param set to true. This way the translations are reloaded with the respective theme.

$this->emulation->startEnvironmentEmulation($storeId, 'frontend', true);

cyildirim commented 4 years ago

Cart request on checkout is coming from web api. So theme translation is not in the scope of API. You can either add the translation under some other module or you can add it to under app/i18n/de_DE

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

sactor commented 3 years ago

This issue is still relevant. I want to use the Finnish language pack, but there are a lot of translations in it that are non-translated (they are still English to English) and because they exist in the language pack, I can't override them in a module. I can override them in theme, but as mention earlier, API requests don't use translations from a theme.

I could copy the language pack and modify it manually, but that's going to make it very cumbersome to update it later.

I have already submitted all the translation changes I need via the usual channels to update the language packs, but it seems the language pack updating process is basically dead as well.

magento-engcom-team commented 3 years ago

Unfortunately, we are archiving this ticket now as it did not get much attention from both Magento Community and Core developers for an extended period. This is done in an effort to create a quality, community-driven backlog which will allow us to allocate the required attention more easily.

Please feel free to comment or reopen according to the Issue reporting guidelines the ticket if you are still facing this issue on the latest 2.x-develop branch. Thank you for collaboration.

clicks-kodet commented 3 years ago

Still valid on 2.4.3

jellesiderius commented 3 years ago

Adding a frontend emulation around the exception works for me as a workaround.

# magento/module-quote/Model/CouponManagement.php

$this->emulation->startEnvironmentEmulation($quote->getStoreId(), 'frontend', true);
throw new NoSuchEntityException(__("The coupon code isn't valid. Verify the code and try again."));
$this->emulation->stopEnvironmentEmulation();
TomashKhamlai commented 2 years ago

@stale

TomashKhamlai commented 2 years ago

@magento-probot-user

TomashKhamlai commented 2 years ago

@magento-probot-user unstale

Minirock commented 2 years ago

Seems to be still valid in 2.4.1 and above.

Any updates ?

convenient commented 2 years ago

Thanks for reopening. We're seeing the exact same scenario on 2.4.2

AngelBS commented 2 years ago

Any update on this one? we are having the same issue on 2.4.2, two years with the same issue....

igi8819 commented 2 years ago

Any update on this one? same error on 2.4.3... :(

adding emulation into rest api functions is resolve the problem...

$emulation = ObjectManager::getInstance()->get('\Magento\Store\Model\App\Emulation');
$emulation->startEnvironmentEmulation($storeId, 'frontend', true);

// function content

$emulation->stopEnvironmentEmulation();
Lain818 commented 2 years ago

Is there anyone who could offer a fix for this problem?

hostep commented 2 years ago

To me it makes sense that a REST request does not use theme translations, because a theme has nothing to do with a REST request, no? A REST request is aware of a storeview, but not about themes, because that makes little sense.

If you want custom translations that are loaded both by the theme and the REST api, it will probably work when you put them in app/i18n/... like explained over here or like @cyildirim already suggested earlier.

Lain818 commented 2 years ago

To me it makes sense that a REST request does not use theme translations, because a theme has nothing to do with a REST request, no? A REST request is aware of a storeview, but not about themes, because that makes little sense.

If you want custom translations that are loaded both by the theme and the REST api, it will probably work when you put them in app/i18n/... like explained over here or like @cyildirim already suggested earlier.

got it - thanks!! Its finally translated.

jellesiderius commented 11 months ago

Just dropping this here...

--- a/vendor/magento/module-quote/Model/CouponManagement.php
+++ b/vendor/magento/module-quote/Model/CouponManagement.php
@@ -25,15 +25,22 @@
      */
     protected $quoteRepository;

+    /**
+     * \Magento\Store\Model\App\Emulation
+     */
+    protected $emulation;
+
     /**
      * Constructs a coupon read service object.
      *
      * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository Quote repository.
      */
     public function __construct(
-        \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
+        \Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
+        \Magento\Store\Model\App\Emulation $emulation
     ) {
         $this->quoteRepository = $quoteRepository;
+        $this->emulation = $emulation;
     }

     /**
@@ -73,7 +80,9 @@
             );
         }
         if ($quote->getCouponCode() != $couponCode) {
+            $this->emulation->startEnvironmentEmulation($quote->getStoreId(), 'frontend', true);
             throw new NoSuchEntityException(__("The coupon code isn't valid. Verify the code and try again."));
+            $this->emulation->stopEnvironmentEmulation();
         }
         return true;
     }
m2-assistant[bot] commented 8 months ago

Hi @engcom-Dash. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:


engcom-Dash commented 8 months ago

Hi @bernd-reindl

Thanks for reporting and collaboration.

Verified the issue in magento 2.4 dev instance but the issue is not reproducable.

We are seeing the error message in german.

Please refer the screenshots attached , please verify the issue in latest magneto instance and let us know if we missed anything.

Screenshot 2024-03-06 at 2 40 04 PM
engcom-Dash commented 7 months ago

Hi @bernd-reindl

We have noticed that this issue has not been updated since long time.
Hence we assume that this issue is fixed now, so we are closing it. Please feel to raise a fresh ticket or reopen this ticket if you need more assistance on this.

Thanks.

webloft commented 1 month ago

@engcom-Dash Did you test this with V1/carts/mine/totals-information too?

A theme translation is not working there. A translation from app/i18n does.

hostep commented 1 month ago

@webloft, have you read the discussion? Like these comments for example:

webloft commented 1 month ago

@hostep yes we read that. We just not agree.

The request is loaded into a theme by default operation in frontend, so it has to deal with translations by the theme too. It can see the storefront, so where is the problem?