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 🙂

You must be logged in to reply to this support post. Sign In or Register for an Account

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3 Documentation for Event Espresso 4

Status: publish

Updated by  Tony 1 month ago ago

Topic Tags

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!
[gravityform id=80 title=false description=false ajax=false]
<div class='gf_browser_unknown gform_wrapper' id='gform_wrapper_80' ><form method='post' enctype='multipart/form-data' id='gform_80' action='/topic/is-there-a-list-of-the-gettext-filter-codes-that-are-used-within-the-strings/'> <div class='gform_body'><ul id='gform_fields_80' class='gform_fields top_label form_sublabel_below description_below'><li id='field_80_1' class='gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible' ><label class='gfield_label' for='input_80_1' >First name<span class='gfield_required'>*</span></label><div class='ginput_container ginput_container_text'><input name='input_1' id='input_80_1' type='text' value='' class='medium' aria-required="true" aria-invalid="false" /></div></li><li id='field_80_2' class='gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible' ><label class='gfield_label' for='input_80_2' >Email address<span class='gfield_required'>*</span></label><div class='ginput_container ginput_container_email'> <input name='input_2' id='input_80_2' type='email' value='' class='medium' aria-required="true" aria-invalid="false" /> </div></li><li id='field_80_3' class='gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible' ><label class='gfield_label' >GDPR Agreement<span class='gfield_required'>*</span></label><div class='ginput_container ginput_container_checkbox'><ul class='gfield_checkbox' id='input_80_3'><li class='gchoice_80_3_1'> <input name='input_3.1' type='checkbox' value='I consent to have this website store my submitted information so they can respond to my inquiry.' id='choice_80_3_1' /> <label for='choice_80_3_1' id='label_80_3_1'>I consent to have this website store my submitted information so they can respond to my inquiry.</label> </li></ul></div></li><li id='field_80_4' class='gfield gform_validation_container field_sublabel_below field_description_below gfield_visibility_visible' ><label class='gfield_label' for='input_80_4' >Comments</label><div class='ginput_container'><input name='input_4' id='input_80_4' type='text' value='' autocomplete='off'/></div><div class='gfield_description' id='gfield_description_80_4'>This field is for validation purposes and should be left unchanged.</div></li> </ul></div> <div class='gform_footer top_label'> <input type='submit' id='gform_submit_button_80' class='gform_button button' value='Download Now' onclick='if(window["gf_submitting_80"]){return false;} if( !jQuery("#gform_80")[0].checkValidity || jQuery("#gform_80")[0].checkValidity()){window["gf_submitting_80"]=true;} ' onkeypress='if( event.keyCode == 13 ){ if(window["gf_submitting_80"]){return false;} if( !jQuery("#gform_80")[0].checkValidity || jQuery("#gform_80")[0].checkValidity()){window["gf_submitting_80"]=true;} jQuery("#gform_80").trigger("submit",[true]); }' /> <input type='hidden' class='gform_hidden' name='is_submit_80' value='1' /> <input type='hidden' class='gform_hidden' name='gform_submit' value='80' /> <input type='hidden' class='gform_hidden' name='gform_unique_id' value='' /> <input type='hidden' class='gform_hidden' name='state_80' value='WyJbXSIsIjBiNjdjZjkyMDUzOWUxOWY5Y2NiZjIwMzM4YjA1Mjk4Il0=' /> <input type='hidden' class='gform_hidden' name='gform_target_page_number_80' id='gform_target_page_number_80' value='0' /> <input type='hidden' class='gform_hidden' name='gform_source_page_number_80' id='gform_source_page_number_80' value='1' /> <input type='hidden' name='gform_field_values' value='' /> </div> </form> </div><script type='text/javascript'> jQuery(document).bind('gform_post_render', function(event, formId, currentPage){if(formId == 80) {} } );jQuery(document).bind('gform_post_conditional_logic', function(event, formId, fields, isInit){} );</script><script type='text/javascript'> jQuery(document).ready(function(){jQuery(document).trigger('gform_post_render', [80, 1]) } ); </script>
[i]
[i]