magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Invoice pdf generation not in proper language

Open ksz2013 opened this issue 10 years ago • 28 comments

Summary (*)

We are using a store with 3 store views, each store view a different language. Everything is ok on frontend, proper languages are displayed. The problem is on the backend when we are generating the invoice pdf, (also shipping) the generated pdf is in the language of the admin logged in user. It is not taking in consideration the language of the store view where the order was placed. (If i select the desired language from backend for the logged in admin user the invoice pdf is generated in the atlanguage, but from what i am aware it should be translated to the store view language)

Preconditions (*)

  1. Magento 2.2.x & 2.3.x

Steps to reproduce (*)

  1. Place order(on ENG store view)
  2. Change locale of admin for any language (Danish in my case)
  3. Go to the order and invoice
  4. Download invoice PDF

Expected result (*)

Generated PDF is in the language of the store view where the order was placed like in email image

Actual result (*)

Generated PDF is in the language of the admin logged in user image


The emulation on the invoice pdf is set:

Magento\Sales\Model\Order\Pdf\Invoice

Lines :130, 131

$this->_localeResolver->emulate($invoice->getStoreId());
$this->_storeManager->setCurrentStore($invoice->getStoreId());

echo $this->_localeResolver->getLocale(); <-- The proper locale is returned, but nothing gets translated: Ex: __('Invoice # ') -> is still english Invoice instead of the proper language translation

-> On the frontend proper language translation is returned

It this a bug, or some different setup needs to be done for backend translations,

Thanks, Szabi

ksz2013 avatar May 05 '16 13:05 ksz2013

Hi guys,

Any update on this?

Thanks

ksz2013 avatar May 06 '16 05:05 ksz2013

Same happens on the latest 2.0.5 version, they are not translated. (This functionality worked well on magento 1). Any feedback would be appreciated.

Best regards

ksz2013 avatar May 06 '16 07:05 ksz2013

Meanwhile made a fix for it, pull request was submitted.

ksz2013 avatar May 10 '16 12:05 ksz2013

Hi @ksz2013 , thanks for reporting this issue and making PR. Please see comments in your PR and only after your changes we can start to process it.

NadiyaS avatar May 11 '16 11:05 NadiyaS

According to contributor guide, tickets without response for two weeks should be closed. Please feel free to reopen if it's needed.

palamar avatar Jul 07 '16 14:07 palamar

i just check on magento 2.1.2 and i have the same issue is there a update for this ticket ?

dankocrama avatar Nov 08 '16 15:11 dankocrama

i am also having this issue in 2.1.2

hezide avatar Dec 08 '16 15:12 hezide

+1

zsoerenm avatar Jan 25 '17 21:01 zsoerenm

still a problem in v2.1.3

Update: here's a workaround that requires nothing but an entry into DI:

<type name="\Magento\Framework\Locale\ResolverInterface">
	<plugin name="mage_localeresolver_reload" type="Magento\Framework\Translate\Locale\Resolver\Plugin" sortOrder="1" disabled="false"/>
</type>

BlitzInternet avatar Feb 01 '17 13:02 BlitzInternet

Hi @BlitzInternet, your workaround works, except for the invoice head like: Order #, Order Date: or Invoice #. Any ideas how to fix this? Should the lines be added at the bottom or at the top of the di.xml? Does this change anything? Best regards.

diybook avatar Feb 28 '17 22:02 diybook

This is because of a strange issue in the translation. In the PDF they don't use the string Order #, but Order #(SPACE) (there is an extra space at the end). The same goes for Invoice # and Shipment # . For example:

"Order # ","Bestelling # "
"Invoice # ","Factuur # "
"Shipment # ","Verzending # "

kanduvisla avatar Nov 16 '17 15:11 kanduvisla

@BlitzInternet : are there any known side-effects of this workaround? It seems like something is manipulated on a global scale now to address a very specific issue.

kanduvisla avatar Nov 16 '17 15:11 kanduvisla

@kanduvisla we haven't experienced any up to now (in 2.1.4)

BlitzInternet avatar Nov 20 '17 09:11 BlitzInternet

https://github.com/magento/magento2/issues/4409#issuecomment-276654512

in which di.xml?

lucscu avatar Jan 04 '18 11:01 lucscu

@BlitzInternet Can you please mention in which di.xml we need to add that code?

deepak-netwin avatar Jun 29 '18 11:06 deepak-netwin

You can add this code in following file. vendor/magento/module-sales/etc/di.xml

<type name="\Magento\Framework\Locale\ResolverInterface">
	<plugin name="mage_localeresolver_reload" type="Magento\Framework\Translate\Locale\Resolver\Plugin" sortOrder="1" disabled="false"/>
</type>

DeepParekhDev avatar Jul 20 '18 05:07 DeepParekhDev

Hi, i have this issue in 2.2.6.

vlauria avatar Mar 11 '19 14:03 vlauria

Hi, i have this issue in 2.2.6.

try this

<plugin name="mage_localeresolver_reload" type="Magento\Framework\Translate\Locale\Resolver\Plugin" sortOrder="1" disabled="false"/>

Dharmeshvaja91 avatar Mar 12 '19 04:03 Dharmeshvaja91

haha magento still hasn't fixed this issue after 3 years :)

eugenbg avatar Apr 15 '19 08:04 eugenbg

I confirmed there is still issue with translation in Magento 2.2.9

quyend-vn avatar Sep 20 '19 07:09 quyend-vn