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

Translation in html files using $t() broken? #2056

Closed
amenk opened this issue Oct 8, 2015 · 47 comments
Closed

Translation in html files using $t() broken? #2056

amenk opened this issue Oct 8, 2015 · 47 comments
Labels
bug report Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@amenk
Copy link
Contributor

amenk commented Oct 8, 2015

I use beta4 and switched the store language to de_DE. While many strings are just not yet translated to DE, there is a translation in app/code/Magento/Checkout/i18n/de_DE.csv for example for

"Shipping Address",Lieferungsadresse

If I am getting it correctly, this is referenced in app/code/Magento/Checkout/view/frontend/web/template/shipping.html:8

<div class="step-title" data-bind="text: $t('Shipping Address')" data-role="title"></div>

But still the English text is shown.

Is the Javascript translation currently broken?

@chicgeek
Copy link
Contributor

chicgeek commented Oct 8, 2015

Just want to add another example where I've experienced the same issue, though the string is not in a template file. In my case trying to translate a string in a core JS file (no override):

 app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js

String example:

$t('Adding...')

Translation in app/design/frontend/Project/default/i18n/en_GB.csv as:

"Adding...","foo…"

Other translations in this theme locale file work fine for in-template translations.

@amenk
Copy link
Contributor Author

amenk commented Oct 10, 2015

Translation seems to run via static/frontend/Vendor/theme/de_DE/js-translation.json - some strings are just not there. Have to find out, how this is generated.

@amenk
Copy link
Contributor Author

amenk commented Oct 10, 2015

Translation is fetched in \Magento\Translation\Model\Js\DataProvider::getData and \Magento\Translation\Model\Js\DataProvider::getPhrases. Magento fetches a list of all JS files and then does a preg_match for currently only the pattern ~\$\.mage\.__\([\'|\"](.+?)[\'|\"]\)~.
What has to be fixed:

  • include .html templates to the list of files
  • match also for $t('...')

@amenk
Copy link
Contributor Author

amenk commented Oct 10, 2015

I will try to make a PR...

@amenk
Copy link
Contributor Author

amenk commented Oct 10, 2015

It is already fixed in the develop branch by a commit from July https://github.com/magento/magento2/blob/develop/app/code/Magento/Translation/Model/Js/DataProvider.php#L96 - I am wondering why this is not yet in master.

@gordonknoppe
Copy link
Member

Internal issue MAGETWO-43935

@Zatara7
Copy link

Zatara7 commented Oct 13, 2015

Is this the part that wasn't being translated? @amenk If so, then it still hasn't been fixed because this is the latest develop and we still need to fix it. If it isn't the part you're talking about then could you please point out how to get there?
Also, if it's been fixed in develop then please use develop for now until the next release when we merge everything to master.

screen shot 2015-10-13 at 1 47 50 pm

@amenk
Copy link
Contributor Author

amenk commented Oct 13, 2015

I did not followup this. But I checked the js-translate.json and it looked good. I can currently use develop, because I use composer and do not want to mess with that process at the moment. I hope there will soon be another composer release?

@Zatara7
Copy link

Zatara7 commented Oct 13, 2015

@amenk Yes there is going to be a release soon. But could you please confirm if my screenshot is looking at the correct place in the frontend where you were having this issue?

@amenk
Copy link
Contributor Author

amenk commented Oct 13, 2015

Should roughly be the correct place. But I am using the blank theme and I think there is no such popup.

@Zatara7
Copy link

Zatara7 commented Oct 13, 2015

Okay let me switch themes and try again

@Zatara7
Copy link

Zatara7 commented Oct 13, 2015

Popup still there with the new theme. We'll get the translation fixed for the popup. Thanks

@arkadiych
Copy link
Contributor

@chicgeek, thank you for reporting of the translation issue.
The issue, that you've mentioned in
app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js
relates to different from $t() problem.
Internal issue MAGETWO-44263 has been created.

@chicgeek
Copy link
Contributor

@arkadiych Okay, is there an internal ticket / further discussion for my issue with $t()? I should note also that this is not isolated to catalog-add-to-cart.js: it affects all JS files and KO templates.

@arkadiych
Copy link
Contributor

@chicgeek, MAGETWO-44263 should cover all entries of such type of untranslatable phrases.

@debuysserk
Copy link

Is this already fixed in the rc master? How can we fix it? We need it urgently.

@chicgeek
Copy link
Contributor

chicgeek commented Nov 6, 2015

There was a hypothetically a fix included in beta 6, however we're still seeing the bug after upgrading. The changelog for CE:

  • Fixed an issue with translation in html files using $t()

Here is one example that does not translate (similar to the first posted here):

  • Template:
    code/Magento/Checkout/view/frontend/web/template/shipping.html
  • L8:
    <div class="step-title" data-bind="text: $t('Shipping Address')" data-role="title"></div>
  • In CSV (which works for PHP translations):
    "Shipping Address","Delivery Address"

@arkadiych
Copy link
Contributor

@debuysserk, the issue with $t() should be fixed in RC

@arkadiych
Copy link
Contributor

@chicgeek, Have you executed next action before check:

  1. Cache Storage should be flushed (basically var/cache and var/view_preprocessed folders should be cleared)
  2. Static files should be redeployed (delete all folders inside pub/static and run bin/magento setup:static-content:deploy en_GB)

If it doesn't help, could you provide a full relative path to *.csv file?

@SilvanLaroo
Copy link

I'm also facing this problem, for example the Add to Cart button has three phases. The Add to Cart, Adding... and Added. These cannot be translated. I believe translations are done via js-translation.json, but this file is empty by default. When I manually add translations (just for testing) to this file, some translations are used. The Add to Cart button unfortunately not. I'm running Magento 2.0.0.

@hellsanos
Copy link

Hi folks!

This issues still seems to be unresolved...we installed the newest version of Mage 2 a few weeks ago. I created our own theme according to the http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/bk-frontend-dev-guide.html
Translations are working for PHP strings. Sadly everything that is done in JS/KO isn't translated at all.

For example:

  • Strings in (Adding..., Added, Add to Cart)
app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js:23-25
  • All pop-ups, like the minicart
  • Order Summary, place order button etc. during the checkout process...

Translation file is placed in:

app/design/frontend/{VENDOR}/{THEME}/i18n/de_DE.csv

A fix would be nice 'cause the majority of our clients speak german...

@hellsanos
Copy link

Okay, it is somehow working for me now.
I was told that the js-translation.json file (which obviously holds all JS/KO translations) is generated only if there is a language package for the current language.

Even though I failed creating my own language package with the magento commands, I "found out a simple solution".
I just moved my language file from the theme folder

app/design/frontend/{VENDOR}/{THEME}/i18n/de_DE.csv

to the already existing language package folder

app/i18n/magento/de_de/de_DE.csv

Flushed cache and now it is working...

@SilvanLaroo
Copy link

Although my js-translation.json file is filled with translations now, the Adding... string is still not translated on the storefront.

@alankent
Copy link

Hi @hellsanos! Moving your CSV file to an official Magento directory is not an acceptable solution for the product. You should not have to modify a Magento delivered language pack. (This is not a complaint of what you did, just saying for the Magento folks that this is a workaround, not a solution to the problem.)

@thomvanderboon
Copy link

I just found that if the js-translation.json is already present, if you redeploy the contents the js-translation.json is not regenerated.

After deleting the js-translation.json files and a redeployment of the static files the js-translation.json files are generated correctly

@niclashoyer
Copy link

the js-translation.json is generated correctly. Using the JavaScript debugger we just discovered that $t seems to be called before any translations are loaded.

@IceReaper
Copy link

Joining in, in my case the "js-translation.json" file only contains"[]" and i cannot figure out why.

@niclashoyer
Copy link

@IceReaper I didn't figure out why, either. As a workaround you can just delete it and rebuild for your locale, e.g.:

rm pub/static/frontend/Magento/luma/de_DE/js-translation.json
php bin/magento setup:static-content:deploy de_DE

@IceReaper
Copy link

@niclashoyer thanks for the hint, but that also generated an empty array in the js-translation.json file. Magento 2.0.2 PHP 7.0, unmodified magento.

@thomvanderboon
Copy link

@IceReaper Try this explanation: http://www.vanderboon.net/wiki/Install_Test_Magento_2_Translation

You also need an symbolic link

@IceReaper
Copy link

Did not work :/ As a workaround i manualy converted the de_DE.csv to the json - works till the bug is fixed.

@rgoncharuk rgoncharuk added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development PS labels Mar 17, 2016
@thomvanderboon
Copy link

I am running up-to-date development branch.

From the product list and the product compare list, the actions of the "add to cart" button are translated correctly

From the product view the actions of the "add to cart" button are NOT translated correctly

weird.......

@hshar7
Copy link
Contributor

hshar7 commented Apr 6, 2016

@thomvanderboon I tried this out and it worked correctly for me on latest develop branch. This thread is getting too broad with translation issues and the original issue with $t is already fixed. I will close this now. Please open new issue with specific translation examples if you find any. Thank you guys for reporting this!

@cjohansson
Copy link

cjohansson commented Oct 20, 2016

Tried all solutions in this thread and others on the internet without solving the issue with $t() not working. My frontend js-translation.json is empty (located at pub/static/frontend/<Vendor>/<theme>/sv_SE/js-translation.json even though I have non-empty translations at /app/i18n/magento/sv_se/sv_SE.csv and /app/design/frontend/<Vendor>/<theme>/i18n/sv_SE.csv that works on PHP level, I clear caches with bin/magento cache:clean and bin/magento cache:flush and find pub/static -name js-translation.json -exec rm -rf {} \; and run bin/magento setup:static-content:deploy sv_SE on latest Magento 2.1.2.

@MidnightDesign
Copy link

@cjohansson Did you find a solution? I have the exact same problem.

@cjohansson
Copy link

Yes @MidnightDesign, we found a work-around. You can manually edit the js-translation.json file. In our case pub/static/frontend/<Vendor>/<theme>/sv_SE/js-translation.json and then change the files file-permissions to disallow overwrite from the Magento 2 application. If you don't change permissions on the file it seems Magento 2 will truncate the file daily.

@MidnightDesign
Copy link

Manually?? But how do I know which translations are needed in there? So is this actually a bug? Is there an open issue for this?

@cjohansson
Copy link

cjohansson commented Nov 10, 2016

I think they should re-open this ticket because the issue remains. @hshar7

@crantron
Copy link

crantron commented Dec 8, 2016

Same issue here, magento 2.1.2. Having to resort to a CSS :After content solution, for something permanent. please fix.

@cjohansson
Copy link

Just want to share our permanent solution to this Magento 2 issue.

We use a nginx web-server and add server logic to walk-around the Magento 2 problem like this:

location ~* js-translation.json$ {
alias /ROOT/app/design/frontend/VENDOR/THEME/js-translation.json;
expires modified +1w;
}

Replace ROOT, VENDOR and THEME with your values.

So we have a js-translation.json file in our theme and configures web-server to bypass Magento 2 bug to make client-side translations work.

magento-engcom-team pushed a commit that referenced this issue Feb 8, 2018
Bugs
- MAGETWO-69496 Impossible specify Bundle option title on store view level with changes to more than one store view
- MAGETWO-66793 [Backport] Merchant can't unsubscribe Customer from Newsletter in Admin
- MAGETWO-80643 Cannot create orders in the admin for stores other than the default when using Paypal Payflow Pro
- MAGETWO-65534 RED BUILD [2.1-develop] [L4] Unstable Tests in L4 Functional Tests EE build on mainline develop: AddToCartCrossSellTest, NavigateUpSellProductsTest, NavigateRelatedProductsTest
@MidoAhmed
Copy link

cjohansson how did yo resolve that plz

@BenSpace48
Copy link
Contributor

This is still an issue I have data-bind="text: isVirtual ? $t('Enter your billing address to get a tax estimate.') : $t('Enter your destination to get a delivery estimate.')" which does not get added to a CSV when running collect-phrases and trying to manually translate it doesn't work.

@iget-master

This comment was marked as abuse.

@MidoAhmed
Copy link

MidoAhmed commented Sep 25, 2018 via email

@penglongyun
Copy link

use text/x-magento-template, .phtml file, $t not working. not be collected into ...././js-translate.json

@lfluvisotto
Copy link
Contributor

Workaround, tested in magento 2.2.6

Copy the file: vendor/magento/module-checkout/view/frontend/web/template/cart/shipping-estimation.html

To your theme: app/design/frontend/<your_vendor_name>/<your_theme_name>/Magento_Checkout/web/template/cart/shipping-estimation.html

Then the strings are going to be translated:

$t('Estimate Tax')
$t('Estimate Shipping and Tax')
$t('Enter your billing address to get a tax estimate.')
$t('Enter your destination to get a shipping estimate.')

@kunzi
Copy link

kunzi commented Mar 26, 2020

I needed to copy the shipping-estimation.html file to my theme's folder even in 2.3.3. About five years after this problem has been reported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests