Support

Home Forums Event Espresso Premium Is there a list of the "gettext" filter codes that are used within the strings?

Is there a list of the "gettext" filter codes that are used within the strings?

Posted: September 18, 2020 at 10:54 am


mbeede@tracom.com

September 18, 2020 at 10:54 am

Greetings – I have a “gettext” filter in my plugin php code used to change some of the text on the EE pages. The text strings seem to support certain codes to do things like start a new line, add an asterisk, etc. Do you have a list of all these code that are supported?

I am trying to add a blank line, add bold, and add underlining to one of my text strings and can’t get any of them to work. At a minimum can you tell me what codes I need to insert for these OR give me a complete list of the codes that gettext supports?

Thanks in advance – Mark


Tony

  • Support Staff

September 21, 2020 at 9:09 am

Hi Mark,

It’s not gettext that is providing those string replacements, its sprintf() but again, its not the function itself that support specific strings, it’s whatever is passed into the function as part of the call.

To explain a little better, here’s an example I’ve just pulled from EE’s codebase:

sprintf(
    esc_html__(
        '%sStep 1%s: Visit your %sOrganization Settings%s and add/update your details.',
        'event_espresso'
    ),
    '<strong>',
    '</strong>',
    '<a href="admin.php?page=espresso_general_settings">',
    '</a>'
)

The only thing there that is passed to gettext is %sStep 1%s: Visit your %sOrganization Settings%s and add/update your details. it doesn’t know what the %s or other places holders are for, just that they are there.

Then sprint off parses the string and replaces the placesholders for the the strings (we use HTML but it doesn’t need to be) in the order the places holders are in the string (or you can define the order yourself).

So in this example, the first placeholder is %s before ‘Step 1’ then the second is again %s right after it.

The 1st string passed to sprintf is <strong>, and the second is </strong> meaning it changes that to be <strong>Step 1</strong> and so on.

This is basically an easier way to allow translations to include HTML in the string without translations breaking the HTML itself.

So to answer your question:

At a minimum can you tell me what codes I need to insert for these OR give me a complete list of the codes that gettext supports?

No, because that’s no how it works.

If you have a string that already has those strings passed into it in a different order than you want you can use them in different locations within the string but you can’t pass anything into the string itself to automatically create them, unless you add the HTML tags into the string itself.

Which specific string is this?


mbeede@tracom.com

September 21, 2020 at 12:31 pm

The specific string that I am trying to get to display correctly is this one:

FROM THIS:
‘In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.’ =>

TO THIS
‘In order to initiate a profile, please complete all of the fields below. Refer to the instructions in Success Factors for the code. The code is CaSe SeNsItIvE.”

BUT I want a blank line between the 1st sentence and the 2nd/3rd sentence AND I would like the 2nd/3rd sentences to be in Bold.

So I want it to look like this on-screen:

In order to initiate a profile, please complete all of the fields below.

Refer to the instructions in Success Factors for the code. The code is CaSe SeNsItIvE.

Make sense?


Tony

  • Support Staff

September 21, 2020 at 12:47 pm

So if you search for that original string in the codebase you’ll get:

echo apply_filters(
    'FHEE__registration_page_attendee_information__attendee_information_pg',
    sprintf(
        __(
            'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.',
            'event_espresso'
        ),
        '<br />',
        '<span class="asterisk">*</span>'
    )
);

The first additional parameter passed to sprintf() is <br/> so you can use %1$s as a placeholder for <br/>, then for the strong tags you’ll need to include them yourself, so something like:

'In order to initiate a profile, please complete all of the fields below.%1$s%1$s<strong>Refer to the instructions in Success Factors for the code. The code is CaSe SeNsItIvE.</strong>'

Note the above is untested.


mbeede@tracom.com

September 21, 2020 at 1:13 pm

Close. The blank line is now displaying but the strong tags are printing out literally like this:

*********
In order to initiate a profile, please complete all of the fields below.

Refer to the instructions in Success Factors for the code. The code is CaSe SeNsItIvE.
*********

I don’t see any info on the net about putting html tags in sprintf statements.
Any more ideas?


mbeede@tracom.com

September 21, 2020 at 1:23 pm

So to find these original strings do you always just look in the source code for them? For example for this one I did a search and found it in the file EE_SPCO_Reg_step_Attendee_Information.class.php on line 72 in the method translate_js_strings(). There is shows the extra space in the beginning (which I did not think needed to be included, but it does obviously.

Is this how you do it? That worked by the way THANKS!!!


Tony

  • Support Staff

September 21, 2020 at 1:59 pm

The blank line is now displaying but the strong tags are printing out literally

In that case you wont be able to use them in that string.

I don’t see any info on the net about putting html tags in sprintf statements.

Huh? Why would you find info on it with sprintf?

So to find these original strings do you always just look in the source code for them?

Yes, I search for a partial string and find it from there.

There is shows the extra space in the beginning (which I did not think needed to be included, but it does obviously.

The string you input for translation must match exactly, it’s the reason I prefer to search the source for them as you can easily spot spaces etc.

Is this how you do it? That worked by the way THANKS!!!

Yep and you’re welcome 🙂

The support post ‘Is there a list of the "gettext" filter codes that are used within the strings?’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso