{"id":1194455,"date":"2016-11-18T07:36:03","date_gmt":"2016-11-18T15:36:03","guid":{"rendered":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/additional-string-changing-functions\/"},"modified":"2016-11-18T07:40:38","modified_gmt":"2016-11-18T15:40:38","slug":"additional-string-changing-functions","status":"closed","type":"topic","link":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/additional-string-changing-functions\/","title":{"rendered":"Additional string changing functions"},"content":{"rendered":"<p>Hello there,<\/p>\n<p>i just wanted to point out, that the gist on the bottom of the<a href=\"https:\/\/theeventscalendar.com\/knowledgebase\/change-the-wording-of-any-bit-of-text-or-string\/\">&#8220;Change the wording of any bit of text or string&#8221;<\/a> post is somewhat limited in its usability, as it does not include the respective solutions for the <strong>ngettext<\/strong> and <strong>gettext_with_context<\/strong> filter hooks.<br \/>\nAs i found it very handy for the average user to change specific terms and spellings without the need to fiddle around with translation files and the follow-up work of keeping them up to date on the one hand and the fact that one can keep his modifications in one place ( e.g. themes <em>functions.php<\/em> ) on the other hand, i post below some additional functions similar to the ones provided by the TEC team for the above mentioned filter hooks.<br \/>\nThey do work for my case, but if maybe someone (e.g. the TEC team) wants to improve them, feel free to do so.<br \/>\nMaybe its worth to put them also on the respective knowledgebase post.<\/p>\n<p>Regards<br \/>\nNiels<br \/>\n<a href=\"https:\/\/gist.github.com\/destruktomatik\/30717613835c2136a4075076e507e606\">https:\/\/gist.github.com\/destruktomatik\/30717613835c2136a4075076e507e606<\/a><\/p>\n<pre><code>&lt;?php\n\/* Additional functions for changing strings in the events calendar and its plugins\n * See https:\/\/theeventscalendar.com\/knowledgebase\/change-the-wording-of-any-bit-of-text-or-string\/ for details \n * on the provided functions by the TEC team\n * 1. - function for changing quantity based spelling\n * 2. - function for changing strings with an attached context\n *\/\n\nfunction tribe_custom_theme_numbered_text ( $translation, $single, $plural, $number, $domain ) {\n\t\/\/put here desired customizaion of single and plural strings \n\t$custom_single = array(\n\t\t&#039;%d RSVP&#039; =&gt; &#039;%d Reservierung&#039;\n\t);\n\t$custom_plural = array(\n\t\t&#039;%d RSVPs&#039; =&gt; &#039;%d Reservierungen&#039;\n\t);\n\t\/\/ If this text domain starts with &quot;tribe-&quot;, &quot;the-events-&quot;, or &quot;event-&quot; and we have replacement text\n    \tif( (strpos($domain, &#039;tribe-&#039;) === 0 || strpos($domain, &#039;the-events-&#039;) === 0 || strpos($domain, &#039;event-&#039;) === 0) ) {\n\t\t\/\/ If found in the custom text array, replace it\n\t\t\tif( array_key_exists($translation, $custom_single) ) {\n\t\t\t\t$translation = $custom_single[$translation];\n\t\t\t}\n\t\t\tif( 1 &lt;  $number &amp;&amp; array_key_exists($translation, $custom_plural) ) {\n\t\t\t\t$translation = $custom_plural[$translation];\n\t\t\t}\n\t}\n    return $translation;\n}\nadd_filter(&#039;ngettext&#039;, &#039;tribe_custom_theme_numbered_text&#039;, 20, 5);\n\nfunction tribe_custom_theme_text_with_context ( $translation, $text, $context, $domain ) {\n\t\/\/ example: &#039;context1&#039;  =&gt; [ old_translation1 =&gt; new_translation1, old_translation2 =&gt; new_translation2  ],\n\t$custom_text_with_context = [\n\t\t&#039;form heading&#039;\t=&gt;\t[\n\t\t\t\t\t\t&#039;RSVP&#039; =&gt; &#039;Reservierung&#039;\n\t\t\t\t\t],\t\t\t\t\t\n\t];\n\t\n\tif ( (strpos($domain, &#039;tribe-&#039;) === 0 || strpos($domain, &#039;the-events-&#039;) === 0 || strpos($domain, &#039;event-&#039;) === 0) ){\n\t\tif ( array_key_exists($context, $custom_text_with_context) &amp;&amp; array_key_exists($translation, $custom_text_with_context[$context]) ) {\n\t\t\t\t$translation = $custom_text_with_context[$context][$translation];\n\t\t}\n\t}\n    return $translation;\n}\nadd_filter(&#039;gettext_with_context&#039;, &#039;tribe_custom_theme_text_with_context&#039;, 20, 4);\n?&gt;<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-1194455","topic","type-topic","status-closed","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Additional string changing functions -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/additional-string-changing-functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Additional string changing functions -\" \/>\n<meta property=\"og:description\" content=\"Hello there, i just wanted to point out, that the gist on the bottom of the&#8220;Change the wording of any bit of text or string&#8221; post is somewhat limited in its usability, as it does not include the respective solutions for the ngettext and gettext_with_context filter hooks. As i found it very handy for the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/additional-string-changing-functions\/\" \/>\n<meta property=\"article:modified_time\" content=\"2016-11-18T15:40:38+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/additional-string-changing-functions\/\",\"url\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/additional-string-changing-functions\/\",\"name\":\"Additional string changing functions -\",\"isPartOf\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\"},\"datePublished\":\"2016-11-18T15:36:03+00:00\",\"dateModified\":\"2016-11-18T15:40:38+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/additional-string-changing-functions\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/additional-string-changing-functions\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/additional-string-changing-functions\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/theeventscalendar.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Topics\",\"item\":\"https:\/\/theeventscalendar.com\/support\/topics\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Additional Help\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/others\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Translations\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/others\/translation\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Additional string changing functions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\",\"url\":\"https:\/\/theeventscalendar.com\/support\/\",\"name\":\"\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Additional string changing functions -","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/additional-string-changing-functions\/","og_locale":"en_US","og_type":"article","og_title":"Additional string changing functions -","og_description":"Hello there, i just wanted to point out, that the gist on the bottom of the&#8220;Change the wording of any bit of text or string&#8221; post is somewhat limited in its usability, as it does not include the respective solutions for the ngettext and gettext_with_context filter hooks. As i found it very handy for the [&hellip;]","og_url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/additional-string-changing-functions\/","article_modified_time":"2016-11-18T15:40:38+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/additional-string-changing-functions\/","url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/additional-string-changing-functions\/","name":"Additional string changing functions -","isPartOf":{"@id":"https:\/\/theeventscalendar.com\/support\/#website"},"datePublished":"2016-11-18T15:36:03+00:00","dateModified":"2016-11-18T15:40:38+00:00","breadcrumb":{"@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/additional-string-changing-functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/theeventscalendar.com\/support\/forums\/topic\/additional-string-changing-functions\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/additional-string-changing-functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/theeventscalendar.com\/support\/"},{"@type":"ListItem","position":2,"name":"Topics","item":"https:\/\/theeventscalendar.com\/support\/topics\/"},{"@type":"ListItem","position":3,"name":"Additional Help","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/others\/"},{"@type":"ListItem","position":4,"name":"Translations","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/others\/translation\/"},{"@type":"ListItem","position":5,"name":"Additional string changing functions"}]},{"@type":"WebSite","@id":"https:\/\/theeventscalendar.com\/support\/#website","url":"https:\/\/theeventscalendar.com\/support\/","name":"","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1194455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1194455\/revisions"}],"predecessor-version":[{"id":1194458,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1194455\/revisions\/1194458"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/media?parent=1194455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}