Last active
February 17, 2017 21:57
-
-
Save ni-le/30717613835c2136a4075076e507e606 to your computer and use it in GitHub Desktop.
The Events Calendar extended string changer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Additional functions for changing strings in the events calendar and its plugins | |
* See https://theeventscalendar.com/knowledgebase/change-the-wording-of-any-bit-of-text-or-string/ for details | |
* on the provided functions by the TEC team | |
* 1. - function for changing quantity based spelling | |
* 2. - function for changing strings with an attached context | |
*/ | |
function tribe_custom_theme_numbered_text ( $translation, $single, $plural, $number, $domain ) { | |
//put here desired customizaion of single and plural strings | |
$custom_single = array( | |
'%d RSVP' => '%d Reservierung' | |
); | |
$custom_plural = array( | |
'%d RSVPs' => '%d Reservierungen' | |
); | |
// If this text domain starts with "tribe-", "the-events-", or "event-" and we have replacement text | |
if( (strpos($domain, 'tribe-') === 0 || strpos($domain, 'the-events-') === 0 || strpos($domain, 'event-') === 0) ) { | |
// If found in the custom text array, replace it | |
if( array_key_exists($translation, $custom_single) ) { | |
$translation = $custom_single[$translation]; | |
} | |
if( 1 < $number && array_key_exists($translation, $custom_plural) ) { | |
$translation = $custom_plural[$translation]; | |
} | |
} | |
return $translation; | |
} | |
add_filter('ngettext', 'tribe_custom_theme_numbered_text', 20, 5); | |
function tribe_custom_theme_text_with_context ( $translation, $text, $context, $domain ) { | |
// example: 'context1' => [ old_translation1 => new_translation1, old_translation2 => new_translation2 ], | |
$custom_text_with_context = [ | |
'form heading' => [ | |
'RSVP' => 'Reservierung' | |
], | |
]; | |
if ( (strpos($domain, 'tribe-') === 0 || strpos($domain, 'the-events-') === 0 || strpos($domain, 'event-') === 0) ){ | |
if ( array_key_exists($context, $custom_text_with_context) && array_key_exists($translation, $custom_text_with_context[$context]) ) { | |
$translation = $custom_text_with_context[$context][$translation]; | |
} | |
} | |
return $translation; | |
} | |
add_filter('gettext_with_context', 'tribe_custom_theme_text_with_context', 20, 4); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment