Translating Download Confirmation Pop-up Text

Hello, I’m trying to translate this text “You`re entitled to UNLIMITED downloads though (so, no worries).” using Quick Translation (https://s2member.com/kb-article/quick-translation-changing-wordsphrases/). I’ve been successful in translating other phrases, but when I copy and paste this phrase exactly as it is in the s2member.pot file into my s2member-o.php file and upload it to the mu-plugins folder, my site crashes. Here is the code in my s2member-o.php file:

if($original === 'You`re entitled to UNLIMITED downloads though (so, no worries).')
                    $translated = 'You are entitled to UNLIMITED downloads.';

Does the issue have something to do with the grave accent used as the apostrophe? I tried putting a \before it, but that didn’t work. Does anyone know what I’m doing wrong?

I found the text I want to change in the s2member.js file, so I’m thinking I can just change it there, but if I modify the js, do I need to put that file in my child theme? And if so, where would I put it?

Thanks in advance!

Or maybe it’s something else with my s2member-o.php file. Whenever I upload the file, it seems like it’s working for a little bit (some of the text changes), then all of a sudden my site won’t load and gives me various errors. This most recent time it was a 403.

Here is my entire file:

<?php
add_filter('gettext_with_context', function ($translated, $original, $context, $text_domain)
    {
        if($context === 's2member-front' && $text_domain === 's2member')
            {
                if($original === '<strong>Thank you.</strong> Your account has been approved.<br />&mdash; Please <a href="%s" rel="nofollow">login</a>.')
                    $translated = '<strong>Thank you for subscribing! </strong> To access the Magickal Library, <a href="%s" rel="nofollow">login here</a>.<br />You will also receive a receipt and an account confirmation via email.';

                else if($original === '<strong>Billing termination confirmed.</strong> Your account has been cancelled.')
                    $translated = 'Your Magickal Library subscription has been cancelled. You will continue to have access for the remainder of your billing period. You will also receive an e-mail confirmation.';
			
			else if($original === 'Nothing to cancel. You have NO recurring fees.')
                    $translated = 'You are not currently subscribed to the Magickal Library.';
			
			else if($original === 'Nothing to cancel. You\'re NOT a paid Member.')
                    $translated = 'You are not currently subscribed to the Magickal Library.';
			
			else if($original === '<strong>Thank you.</strong> Your account has been updated :-)')
                    $translated = '<strong>Thank you for subscribing! </strong> To access the Magickal Library, <a href="%s" rel="nofollow">login here</a>.<br />You will also receive a receipt and an account confirmation via email.';
			
			else if($original === 'Youre entitled to UNLIMITED downloads though (so, no worries).')
                    $translated = 'You are entitled to UNLIMITED downloads.';
            }
        return $translated; // Return final translation.
    }, 10, 4);

Your return $translated; needs to be inside the if statement brace brackets AND you need to initialise it on the way in since you are always returning it.

Also keep in mind that this $original text has already been $translated before this function is called so you should refer to your internal translation as $my_translated for clarity.

<?php
add_filter('gettext_with_context', function ($translated, $original, $context, $text_domain)
    {
        if($context === 's2member-front' && $text_domain === 's2member')
            {
                $my_translated = $original;

                if($original === '<strong>Thank you.</strong> Your account has been approved.<br />&mdash; Please <a href="%s" rel="nofollow">login</a>.')
                    $my_translated = '<strong>Thank you for subscribing! </strong> To access the Magickal Library, <a href="%s" rel="nofollow">login here</a>.<br />You will also receive a receipt and an account confirmation via email.';

                else if($original === '<strong>Billing termination confirmed.</strong> Your account has been cancelled.')
                    $my_translated = 'Your Magickal Library subscription has been cancelled. You will continue to have access for the remainder of your billing period. You will also receive an e-mail confirmation.';
			
			else if($original === 'Nothing to cancel. You have NO recurring fees.')
                    $my_translated = 'You are not currently subscribed to the Magickal Library.';
			
			else if($original === 'Nothing to cancel. You\'re NOT a paid Member.')
                    $my_translated = 'You are not currently subscribed to the Magickal Library.';
			
			else if($original === '<strong>Thank you.</strong> Your account has been updated :-)')
                    $my_translated = '<strong>Thank you for subscribing! </strong> To access the Magickal Library, <a href="%s" rel="nofollow">login here</a>.<br />You will also receive a receipt and an account confirmation via email.';
			
			else if($original === 'Youre entitled to UNLIMITED downloads though (so, no worries).')
                    $my_translated = 'You are entitled to UNLIMITED downloads.';

                return $my_translated; // Return my modified translation.
            }
    }, 10, 4);
1 Like

It worked! Thank you Tim! Tim for president!

I copied and pasted that code from this page https://s2member.com/kb-article/quick-translation-changing-wordsphrases/. Would there be any way to update that page with the working version so others don’t have the same problem?

Thanks again!

I’m just a user like you. I don’t have access to modify s2member document / code source. Good idea though :slight_smile:

Makes sense, but too bad!

When I just tested the checkout process, this translation didn’t work (text stayed the same):

 if($original === '<strong>Thank you.</strong> Your account has been approved.<br />&mdash; Please <a href="%s" rel="nofollow">login</a>.')
                    $my_translated = '<strong>Thank you for subscribing! </strong>To access the Magickal Library, <a href="%s" rel="nofollow">login here</a>.<br />You will also receive a receipt and an account confirmation via email.';

In the .pot file, the text is this:
<strong>Thank you.</strong> Your account has been approved.<br />&mdash; Please <a href=\"%s\" rel=\"nofollow\">log in</a>.

But when I try just pasting that in the file, it crashed my site.

Do you know why this one didn’t work?

Thanks!

Did you wrapper it with single quotes?

You can always try the original but do the comparison using == rather than ===. The former means equivalent, the latter means identical.

I think I figured out what it was, the text says “log in” but I had “login”. :man_facepalming:

However, I think my s2member-o file is still crashing my site. It’s subtle, but something’s not right. After uploading the file, there are things in my dashboard that are missing (see below). There are three items that don’t show up on the left and then my comments are all messed up and my Jetpack stats are gone. I’m certain it’s the s2member-o file because after I delete and purge all, all of this stuff returns.


This is the code of my file:

<?php
add_filter('gettext_with_context', function ($translated, $original, $context, $text_domain)
    {
        if($context === 's2member-front' && $text_domain === 's2member')
            {
                $my_translated = $original;

                if($original === '<strong>Thank you.</strong> Your account has been approved.<br />&mdash; Please <a href="%s" rel="nofollow">log in</a>.')
                    $my_translated = '<strong>Thank you for subscribing! </strong> To access the Magickal Library, <a href="%s" rel="nofollow">login here</a>.<br />You will also receive a receipt and an account confirmation via email.';

                else if($original === '<strong>Billing termination confirmed.</strong> Your account has been cancelled.')
                    $my_translated = 'Your Magickal Library subscription has been cancelled. You will continue to have access for the remainder of your billing period. You will also receive an email confirmation.';
			
			else if($original === 'Nothing to cancel. You have NO recurring fees.')
                    $my_translated = 'You are not currently subscribed to the Magickal Library.';
			
			else if($original === 'Nothing to cancel. You\'re NOT a paid Member.')
                    $my_translated = 'You are not currently subscribed to the Magickal Library.';
			
			else if($original === '<strong>Thank you.</strong> Your account has been updated :-)')
                    $my_translated = '<strong>Thank you for subscribing! Your account has been updated and you can now access the <a href="https://www.schooloflifedesign.com/magickal-library/">Magickal Library</a>.<br />You will also receive a receipt and an account confirmation via email.';
			
			else if($original === 'You`re entitled to UNLIMITED downloads though (so, no worries).')
                    $my_translated = 'You are entitled to UNLIMITED downloads.';

                return $my_translated; // Return my modified translation.
            }
    }, 10, 4);

Do you know where I went wrong? I copied and pasted your code from above, and it’s basically the same save a couple minor edits: the addition of the accent in “You`re entitled”, changed “login” to “log in” as previously mentioned, and the translation for “Your account has been updated :-)” is slightly different.

Let’s make the evaluation explicit and return the original translated string if unmodified.

<?php
add_filter('gettext_with_context', function ($translated, $original, $context, $text_domain)
    {

        if ( !empty( $translated ) )
           $my_translated = $translated;
        else
           $my_translated = $original;

        if( ( $context === 's2member-front' ) && ( $text_domain === 's2member' ) )
            {
                if($original === '<strong>Thank you.</strong> Your account has been approved.<br />&mdash; Please <a href="%s" rel="nofollow">log in</a>.')
                    $my_translated = '<strong>Thank you for subscribing! </strong> To access the Magickal Library, <a href="%s" rel="nofollow">login here</a>.<br />You will also receive a receipt and an account confirmation via email.';

                else if($original === '<strong>Billing termination confirmed.</strong> Your account has been cancelled.')
                    $my_translated = 'Your Magickal Library subscription has been cancelled. You will continue to have access for the remainder of your billing period. You will also receive an email confirmation.';
			
			else if($original === 'Nothing to cancel. You have NO recurring fees.')
                    $my_translated = 'You are not currently subscribed to the Magickal Library.';
			
			else if($original === 'Nothing to cancel. You\'re NOT a paid Member.')
                    $my_translated = 'You are not currently subscribed to the Magickal Library.';
			
			else if($original === '<strong>Thank you.</strong> Your account has been updated :-)')
                    $my_translated = '<strong>Thank you for subscribing! Your account has been updated and you can now access the <a href="https://www.schooloflifedesign.com/magickal-library/">Magickal Library</a>.<br />You will also receive a receipt and an account confirmation via email.';
			
			else if($original === 'You`re entitled to UNLIMITED downloads though (so, no worries).')
                    $my_translated = 'You are entitled to UNLIMITED downloads.';
            }
        return $my_translated; // Return modified / unmodified translation.
    }, 10, 4);