Support

Home Forums Translations Untranslated Text (2)

Untranslated Text (2)

Posted: June 21, 2015 at 4:52 pm


Gonçalo Pereira

June 21, 2015 at 4:52 pm

Hi!

Once again I get back to you looking for help with some text string that I’m unable to translate to portuguese:

The string that I’m unable to translate is – “Please note that a maximum number of %d tickets can be purchased for this event per order”. (I have translated it in the language file but it remains in English. Just to be sure I have downloaded and merged the latest language files).

Thanks,

  • This topic was modified 8 years, 9 months ago by  Lorenzo Orlando Caum.
  • This topic was modified 4 years, 1 month ago by  Garth.


Dean

June 22, 2015 at 4:20 am

Hi,

I tested with the following function and the translation seems fine:

function mycustom_filter_gettext( $translated, $original, $domain ) {
 
    // This is an array of original strings
    // and what they should be replaced with
    $strings = array(
        'Please note that a maximum number of %d tickets can be purchased for this event per order.' => 'Please note %d',
        // Add some more strings here
    );

    // See if the current string is in the $strings array
    // If so, replace its translation
    if ( isset( $strings[$original] ) ) {
        // This accomplishes the same thing as __()
        // but without running it through the filter again
        $translations = get_translations_for_domain( $domain );
        $translated = $translations->translate( $strings[$original] );
    }
 
    return $translated;
}
 
add_filter( 'gettext', 'mycustom_filter_gettext', 10, 3 );

I also tested with a random language file (Dutch) from our Glotpress account and that translated the text too.

In your translation, did you include the ending period (.)? It was missing from your question.


Gonçalo Pereira

June 22, 2015 at 10:30 am

Hi Dean!

I have checked this and got it working. The difference was in the variable value that is defined as “%d” in the language file but shows as “%1$d” in the gettext function. The missing period was a typo error in my post.

Either way, your suggestion helped me to find the issue.

Thanks.


Lorenzo Orlando Caum

  • Support Staff

June 22, 2015 at 11:03 am

Hi Gonçalo, were you able to translate this phrase in your updated language file?


Lorenzo


Gonçalo Pereira

June 22, 2015 at 4:50 pm

Hi!

I was unable to use the language file for it because the sentence isn’t equal to the one that is returned by the gettext function.

You can check it here:


Gonçalo Pereira

June 22, 2015 at 4:51 pm

Sorry,

My last reply lost the link to the language file:

http://translate.eventespresso.com/projects/event-espresso-4/pt/event-espresso-pt_PT?filters%5Bterm%5D=Please+note+that+a+maximum+&filters%5Buser_login%5D=&filters%5Bstatus%5D=current_or_waiting_or_fuzzy_or_untranslated&filter=Filter&sort%5Bby%5D=priority&sort%5Bhow%5D=desc


Josh

  • Support Staff

June 24, 2015 at 4:18 pm

Hi Gonçalo,

I checked this and “Please note that a maximum number of %d tickets can be purchased for this event per order.” is the correct string.


Gonçalo Pereira

June 26, 2015 at 10:44 am

Hi!

Sorry for the late reply,…

I have checked this also but, for some reason, the translation, using the sentence above in the language file, isn’t working.

Only when I inserted the sentence “Please note that a maximum number of %1$d tickets can be purchased for this event per order.” in the local function it worked.

Perhaps debugging it with my local language file may shed some light on this… let me know if you are interested in it.

Thanks for your help.


Lorenzo Orlando Caum

  • Support Staff

June 26, 2015 at 2:04 pm

Hello, there is a filter available for that messaging. Could you give that a try?

https://gist.github.com/lorenzocaum/38baf9ceb1188185187d


Lorenzo


Lorenzo Orlando Caum

  • Support Staff

June 30, 2015 at 11:05 am

Hello, I’ve replaced the sample function for changing the messaging. Please use this one instead:

https://gist.github.com/38baf9ceb1188185187d


Lorenzo


Gonçalo Pereira

July 1, 2015 at 4:29 pm

Hi Lorenzo!

The function you provided worked just fine.
Thank you very much for your help.

The support post ‘Untranslated Text (2)’ 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