Home › Forums › Calendar Products › Events Calendar PRO › Custom String Changes using tribe_custom_theme_text function
- This topic has 7 replies, 2 voices, and was last updated 8 years, 11 months ago by
Alex.
-
AuthorPosts
-
April 28, 2017 at 2:04 am #1275683
Alex
ParticipantHi Again
I need to translate all of the strings that come as part of The Events Calendar plugin. I’m not using WPML for reasons previously discussed – but I need to alter the strings that come as part of TEC when a user has set their language option to Welsh.
Within the events pages themselves, I have made an ACF area that accepts the Welsh and English content, then within all of the views there is a conditional php statement to display English or Welsh content based on a session variable. The way I had planned on doing this for the strings would be to create the tribe_custom_theme_text function and then only call it as part of a filter is the session var was set to welsh – I hope that makes sense.
My question is – is there a way to see all of the strings that are used within TCE plugin to make my life easier when it comes to translating?
Thanks,
AlexApril 28, 2017 at 7:48 pm #1276149Trisha
MemberHello, Alex!
Thank you for using The Events Calendar! I can help with this ?
Each of our plugins has a ‘language’ directory with translations and ‘.pot’ file. The .pot file is the one you’re looking for.
You can see TEC’s pot file here: https://github.com/moderntribe/the-events-calendar/blob/develop/lang/the-events-calendar.pot
Does this help answer your question? Let me know how it goes!
Cheers,
TrishaApril 29, 2017 at 4:19 am #1276218Alex
ParticipantHi Trisha
Thanks for sending me the link to that file – there are quite a few translations after all!
The function I’ve got however dosn’t seem to be working with the translations correctly though.
/This is the function to accommodate the welsh / English differences within the MT plugin. function glue_tran( $en, $cy ) { if ( $_SESSION['lang'] == 'en' ) { return $en; } else { return $cy; } } function tribe_custom_theme_text( $translation, $text, $domain ) { // Put your custom text here in a key => value pair // Example: 'Text you want to change' => 'This is what it will be changed to' // The text you want to change is the key, and it is case-sensitive // The text you want to change it to is the value // You can freely add or remove key => values, but make sure to separate them with a comma // This example changes the label "Venue" to "Location", and "Related Events" to "Similar Events" $custom_text = array( 'Upcoming %s' => glue_tran('Upcoming %s', 'Upcoming Welsh %s'), 'Related %s' => glue_tran('Related %s', 'Related Events Welsh'), 'Find out more' => glue_tran('Find out more', 'Welsh Find Out More'), 'Previous %s' => glue_tran('Previous Events', 'Welsh Previous Events'), 'Next %s' => glue_tran('Next Events', 'Welsh Next Events'), 'Past %s' => glue_tran('Past Events', 'Welsh Past Events'), '%s From' => glue_tran('Events From', 'Welsh Events From'), 'Search' => glue_tran('Search', 'Welsh Search'), 'Near' => glue_tran('Eng Near', 'Welsh Near'),//todo this one doesn't work 'Find %s' => glue_tran('Find Events', 'Welsh Find Events'), 'View As' => glue_tran('View As', 'Welsh View As'), 'List' => glue_tran('List', 'Welsh List'), 'Week' => glue_tran('Week', 'Welsh Week'),//todo this one doesn't work 'Month' => glue_tran('Month', 'Welsh Month'), 'Day' => glue_tran('Day', 'Welsh Day'), 'Map' => glue_tran('Map', 'Welsh Map'), //todo this one doesn't work 'April' => glue_tran('April', 'Welsh April'), //todo this one doesn't work 'Narrow Your Results' => glue_tran('Narrow Your Results', 'Welsh') //todo this one doesn't work ); // If this text domain starts with "tribe-", "the-events-", or "event-" and we have replacement text if ( ( strpos( $domain, 'vc-events' ) === 0 || strpos( $domain, 'the-events-' ) === 0 || strpos( $domain, 'event-' ) === 0 ) && array_key_exists( $translation, $custom_text ) ) { $translation = $custom_text[ $translation ]; } return $translation; } //Add the tribe_custom_theme_text function as a filter add_filter( 'gettext', 'tribe_custom_theme_text', 1, 3 );See all of the strings I’ve added with
//todo this one doesn't worknext to them – all of the others appear as they should in the website. I’ve only just gotten started with this (hence having no actual Welsh content in there yet) but if you could point me in the direction of where I’m going wrong that would be great.Cheers,
AlexMay 1, 2017 at 9:10 pm #1277060Trisha
MemberHi Alex,
I’m glad this file was helpful to you!
I do want to note that we are fairly limited in how much we can support custom development questions like this.
That said, I’d be happy to at least point you in the right direction as best I can.
Here are a few Knowledgebase articles that may be helpful:
https://theeventscalendar.com/knowledgebase/adding-or-updating-a-translation/
Since you say that you don’t want to use WPML, maybe you could opt for Polylang. While it is unsupported, it is free and several of our users have managed to get the results they wanted with it.
We also have a list of freelancers who we would happily recommend for this level of help.
Does this help answer your question? Let me know how it goes!
Cheers,
TrishaMay 2, 2017 at 4:06 am #1277152Alex
ParticipantHi Trisha
Thanks for getting back to me, my problem is a little complicated…
I can’t use a traditional language switcher plugin as only the events section of my website needs translating – there are no translations available for the rest of the site and all traditional plugins seem to force their translations site wide.
Thank you for the links to the information on the .po files though – I feel like I’m heading in the right direction with these. I’ve installed a plugin called Loco Translate which looks like it’ll be able to update a .po file for me, which is great, but if you could provide any information on how to allow a visitor to the site to switch .po / .mo file that would solve my problem!
Thanks,
AlexMay 2, 2017 at 8:59 pm #1277803Trisha
MemberHi Alex!
Here are a few articles on the topic:
- https://codex.wordpress.org/Function_Reference/language_attributes
- https://wordpress.stackexchange.com/questions/119495/how-do-i-change-the-value-of-lang-en-us
- https://wordpress.stackexchange.com/questions/159083/html-lang-instead-of-lang-en-us-why
It seems like if you can set the locale in your customization based on the parameter of the URL it should work.
Does this help answer your question? Let me know how it goes!
Cheers,
TrishaMay 24, 2017 at 9:35 am #1288408Support Droid
KeymasterHey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.
Thanks so much!
The Events Calendar Support Team -
AuthorPosts
- The topic ‘Custom String Changes using tribe_custom_theme_text function’ is closed to new replies.
