I use the events Calendar Plugin and I want to change some words

Good Morning,

I use Events Calendar for our Website, now I want to change the "Now onwards" and "onwards" on top of the page, also the next and previous at the bottom of the event calendar. I already tried to change it with their documentation (and support) but it didn't work. As we are a German business without English business Connections we don't want to have some English text on our page.. Thank you in advance.

Topic the-events-calendar Wordpress

Category Web


The "Now onwards" string is translated with _x() which is different than __() because it allows context to be added to the string being translated.

Because there is context, you need to use gettext_with_context instead of gettext. Here's a simple example based on the one in the WP.org Code Reference:

function example_gettext_with_context( $translated, $text ) {
        if ( 'Now' == $text ) {
              $translated = 'Today';
         }

   return $translated;
}
add_filter( 'gettext_with_context', 'example_gettext_with_context', 10, 2 );

You can find the relavent code in the Events Calendar plugin here and here

The Events Calendar website also has some detailed examples.


For only a couple of words I would use the gettext filter e.g.

function wse_text_filter( $translated_text, $untranslated_text ) {
    switch( $untranslated_text ) {

        case 'Now onwards':
          $translated_text = __( 'Now backwards','text_domain' );
        break;

        case 'onwards':
          $translated_text = __( 'Backwards','text_domain' );
        break;

   }
   return $translated_text;
}
add_filter('gettext', 'wse_text_filter', 20, 3);

It's hopefully pretty self explanatory, you could also try language switching plugins such as Polyang or WPML.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.