The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

labels for checkout payments are not getting translated

fileeefileee Member
in Bugs & Feature Requests edited February 2016
Can you look into the following bug? The labels for the payment methods are not translated, everything else is.

image

In my checkout config i have set all strings let's e.g. take this one

'checkout_pay_with_paypal': '<span class="fc-payment-method-logo"><img
src="https://www.paypalobjects.com/webstatic/mktg/logo/pp_cc_mark_74x46.jpg"
alt="PayPal" /></span>Bezahlen mit Ihrem PayPal-Konto oder per Kreditkarte.',


Now i saw on github that this is definitely the correct string that is used for that, see https://github.com/FoxyCart/2.0-templates/blob/master/checkout.inc.twig#L530

Why is it not translated? Again, everything else works so i'm pretty sure this might be because those strings are somehow maybe dynamically generated?


Or is maybe hosted_gateway.lang_pay_with used for that? https://github.com/FoxyCart/2.0-templates/blob/master/checkout.inc.twig#L560
if so, how can i translate hosted_gateway array?
Tagged:
Comments
  • fc_adamfc_adam FoxyCart Team
    @fileee,

    Sorry to hear you're running into that. Those two payment options are indeed within the hosted payment options block - we'll take a look at what changes need to be made to the snippet to allow for that and get back to you as quickly as we can.
  • Hey adam,

    I don't want to annoy you, but do you have a solution for me? I'm also fine with an ugly hack by extending the hosted_gateway json object myself in the twig template (similiar how we currently do it with the translations).

    The thing is that this payment information is really crucial and the fact it is not translated basically renders your solution unaccessible for non-english speakers. So... it is really important to solve this, not only for me :P
  • fc_adamfc_adam FoxyCart Team
    @fileee,

    Thanks for bumping the ticket. I don't have a solution yet - but I am working on it. I'll hopefully get back to you very soon!
  • fc_adamfc_adam FoxyCart Team
    @fileee,

    I've just updated the wiki page with a new addition to step 2 - give that a try: https://wiki.foxycart.com/v/2.0/snippets/enable_multiple_languages
  • wuhu thx! In order to say thx i can maybe provide an updated german translation file(the current one you link is.... well.... nobody should use that *G*)
  • fileeefileee Member
    edited March 2016
    Just wanted to say that it works. However as we customized the whole checkout template, there is no embedded checkout.twig anymore (i basically copied it manually from github to the position inside the checkout master template)

    So if anyone wants to use it just include the following code AFTER your custom language snippet

    {% set new_hosted_gateways = {} %}
    {% for hosted_gateway in hosted_payment_gateways %}
    {% set new_gateway = hosted_gateway %}
    {% set custom_strings = {
    lang_pay_with: config.lang['checkout_pay_with_'~hosted_gateway.type],
    lang_payment_method: config.lang['checkout_payment_method_'~hosted_gateway.type]
    } %}
    {% set new_gateway = [new_gateway|merge(custom_strings)] %}
    {% set new_hosted_gateways = new_hosted_gateways|merge(new_gateway) %}
    {% endfor %}
    {% set hosted_payment_gateways = new_hosted_gateways %}


    btw: make sure you have both strings in your language json
    'checkout_pay_with_paypal' and 'checkout_pay_with_paypal_ec'

    Because now the latter one is used. Although this means that you need to adapt the original english language file, as this string is not known by default (otherwise it works on an translated page but not for the english page). How to do this, see here https://forum.foxycart.com/discussion/10667/tip-how-to-add-new-strings-when-using-translations


    @adam

    Maybe you should also check if the custom lang field is set, and only execute this code if so. Then one doesn't need to add new strings to the english field because WITH the code snippet it uses different strings (that are currently not there)
    e.g.
    {% for key, item in custom_fields %}
    {% if key == "lang" %}
    {% set new_hosted_gateways = {} %}.......
    {% set hosted_payment_gateways = new_hosted_gateways %}
    break

  • Okay forget the first part of the post above, it is not working like that.

    However after lot of testing the following works:

    If one included the checkout.inc.twig in the template directly, then just copy the code like that
    Insert After that line -> {% block payment_method %}

    {% if "lang" in custom_fields|keys %}
    {% set new_hosted_gateways = {} %}
    {% for hosted_gateway in hosted_payment_gateways %}
    {% set new_gateway = hosted_gateway %}
    {% set custom_strings = {
    lang_pay_with: config.lang['checkout_pay_with_'~hosted_gateway.type],
    lang_payment_method: config.lang['checkout_payment_method_'~hosted_gateway.type]
    } %}
    {% set new_gateway = [new_gateway|merge(custom_strings)] %}
    {% set new_hosted_gateways = new_hosted_gateways|merge(new_gateway) %}
    {% endfor %}
    {% set hosted_payment_gateways = new_hosted_gateways %}
    {% endif %}


    Also make sure to NOT have a custom language snippet in the checkout template, because it injects the cart_include template, so it is sufficient to just include your custom language snippet in the cart_include template.

    The
    {% if "lang" in custom_fields|keys %}
    makes sure that it is only executed for non-english sessions. Otherwise i had massive problems.
  • fc_adamfc_adam FoxyCart Team
    @fileee,
    Also make sure to NOT have a custom language snippet in the checkout template, because it injects the cart_include template, so it is sufficient to just include your custom language snippet in the cart_include template.
    You will need to include it in both the checkout and the cart include templates. Just including the custom language snippet in the cart include and not in the checkout doesn't correctly translate the checkout. It needs to be included in the checkout template still to properly convert all the strings, which is why the documentation instructs you to include it in all four templates.

    In terms of the language strings - great catch there. I had neglected to test the default language with that script, and missed that the hosted gateway strings weren't included in the general language strings for the store language on the checkout. I've updated the wiki to include the if statement you noted, but expanded on it to also check for the lang attribute being a blank string - which resets back to the default store language but would have evaluated as true by just checking for it's presence.
  • sry you are right, i should have testet better. In my head it made sense :) I guess this thread is closed now.
  • fc_adamfc_adam FoxyCart Team
    @fileee,

    No worries - it's a bulky snippet to work with - and while not pretty it does get the job done pretty well until we get native support. Thanks for the testing you've done and feedback you've provided!
  • fileeefileee Member
    edited March 2016
    Sry i need to open this thread again (we planning to launch our shop tomorrow).

    I think one string is still missing. it's 'checkout_payment_method_paypal_confirmed'. It is the string that is display when coming back from paypal to foxycart checkout: Under admin UI it says in english: "Your Paypal account information has been confirmed. The account to be charged is: %s"

    I will try it myself, but please look into that one, i guess you have more luck to find a solution
  • fileeefileee Member
    edited March 2016
    Got it :) [You should hire me :P ]

    {% if "lang" in custom_fields|keys and custom_fields.lang.value != "" %}
    {% set new_hosted_gateways = {} %}
    {% for hosted_gateway in hosted_payment_gateways %}
    {% set new_gateway = hosted_gateway %}

    {% if "token" in hosted_gateway_vars|keys and hosted_gateway_vars.token != "" %}
    {% set custom_strings = {
    lang_pay_with: config.lang['checkout_pay_with_'~hosted_gateway.type],
    lang_payment_method: config.lang['checkout_payment_method_'~hosted_gateway.type~'_confirmed']~hosted_gateway_vars.PayerEmail
    } %}
    {% else %}
    {% set custom_strings = {
    lang_pay_with: config.lang['checkout_pay_with_'~hosted_gateway.type],
    lang_payment_method: config.lang['checkout_payment_method_'~hosted_gateway.type]
    } %}
    {% endif %}


    {% set new_gateway = [new_gateway|merge(custom_strings)] %}
    {% set new_hosted_gateways = new_hosted_gateways|merge(new_gateway) %}
    {% endfor %}
    {% set hosted_payment_gateways = new_hosted_gateways %}
    {% endif %}


    However please look over it to make sure that actually works. Also i'm not sure if this is bulletproof for every gateway or just for paypal.

    Another important hint: Whoever wants to translate has to make sure that the following strings are in his translations (wasn't for me when i copied your defaults)
    checkout_pay_with_paypal_ec
    checkout_payment_method_paypal_ec
    checkout_payment_method_paypal_ec_confirmed
  • fc_adamfc_adam FoxyCart Team
    @fileee,

    Great job! Your approach was pretty spot on - I made a couple changes based on how it works on our side.

    In working on this though, I noticed a small issue with our translations for checkout_payment_method_paypal_ec_confirmed. The english translation has a %s at the end - to act as the reference point for where the email will be added. None of the other translations feature that though, but our server-side code is expecting it to be there. I've created a ticket to get that fixed in the near future, so you'll want to alter your approach to the one I've updated on the wiki to work with that as well. You'll also want to adjust the translations to include that string at the end of the translation for the ones you're using.

    Unfortunately the approach isn't perfect - we don't store a value of what the pre-authed payment method is that can be used reliably, so it can end up in false positives for displaying the confirmed text. If you're just using PayPal though - you should be fine.
    Another important hint: Whoever wants to translate has to make sure that the following strings are in his translations (wasn't for me when i copied your defaults)
    I believe you may have been using old translations in that instance - the ones I updated the wiki with over the last couple days all include those strings, but the ones previous did not.
  • one more thing there is a } too much in your solution

    {% if "lang" in custom_fields|keys and custom_fields.lang.value != "" %}
    {% set new_hosted_gateways = {} %}
    {% for hosted_gateway in hosted_payment_gateways %}
    {% set new_gateway = hosted_gateway %}
    {% set custom_strings = {
    lang_pay_with: config.lang['checkout_pay_with_' ~ hosted_gateway.type],
    lang_payment_method: config.lang['checkout_payment_method_' ~ hosted_gateway.type]
    } %}
    {% if "token" in hosted_gateway_vars|keys and hosted_gateway_vars.token != "" %}
    {% set lang_payment_method_confirmed = config.lang.checkout_payment_method_hosted_confirmed %}
    {% if 'checkout_payment_method_' ~ hosted_gateway.type ~ '_confirmed' in config.lang|keys %}
    {% set lang_payment_method_confirmed = config.lang['checkout_payment_method_' ~ hosted_gateway.type ~ '_confirmed'] %}}<--------------remove that one
    {% if hosted_gateway.type == "paypal_ec" %}
    {% set lang_payment_method_confirmed = lang_payment_method_confirmed|replace({ '%s': hosted_gateway_vars.PayerEmail }) %}
    {% endif %}
    {% endif %}
    {% set custom_strings = custom_strings|merge({ lang_payment_method: lang_payment_method_confirmed }) %}
    {% endif %}

    {% set new_gateway = [new_gateway|merge(custom_strings)] %}
    {% set new_hosted_gateways = new_hosted_gateways|merge(new_gateway) %}
    {% endfor %}
    {% set hosted_payment_gateways = new_hosted_gateways %}
    {% endif %}
  • fc_adamfc_adam FoxyCart Team
    @fileee,

    Great catch - thanks for letting us know.
Sign In or Register to comment.