Unless there’s a function to get all the translated category terms the only way to make this work is to turn off translation of category terms.
If you know of a function in WPML that can get all the translated category terms I might be able to fix this.
Thread Starter
jvier
(@jvier)
Hi, sorry for the delayed response.
I’m not sure what you mean by “a function that can get all the translated category terms”.
Do you mean it as in “a function that lets you edit the translated category themes”. Because in that case there is one.
Take a look at https://wordpress.org/support/topic/colors-disappear-with-wpml-multi-language-site/
What I would need is a function like get_terms()
but that would also return the translated terms that WPML produces.
If you have a listing of all the translated terms you could use the filter hook 'teccc_get_terms'
to add the translated terms.
Something like,
add_filter( 'teccc_get_terms', 'wpml_translated_tec_category_slugs' );
function wpml_translated_tec_category_slugs( $all_terms ) {
$translated_terms = array( 'translated_term1', 'translated_term2', ... );
$merged_terms = array_merge( $all_terms, $translated_terms );
return $merged_terms;
}
Thread Starter
jvier
(@jvier)
I tried applying the code you sent me (putting the category slugs in the ‘translated_termx’ slots) and it does spread the colors to the translations but the calendar disappears completely from the frontend only leaving the legend categories.
I entered the code as follows,
add_filter( 'teccc_get_terms', 'wpml_translated_tec_category_slugs' );
function wpml_translated_tec_category_slugs( $all_terms ) {
$translated_terms = array( 'atelier-cuisine-en-anglais', 'atelier-cuisine-en-espagnol', 'atelier-cuisine-en-francais', 'cooking-classes-in-english', 'cooking-classes-in-french', 'cooking-classes-in-spanish' );
$merged_terms = array_merge( $all_terms, $translated_terms );
return $merged_terms;
}
Can you provide the contents of all the variables? It would help in troubleshooting.
Thread Starter
jvier
(@jvier)
I’m afraid I don’t know how to get the variables from the plugin. If you could reference me to a tutorial or plugin that does this I’ll provide the variables.
I think I’ve been able to update the plugin to add category terms via a filter. This should bring WPML compatibility.
I’ve done some testing locally but it would be nice if someone could test my code. You can do this by downloading my develop branch from https://github.com/afragen/the-events-calendar-category-colors/archive/develop.zip and install it.
You will need to deactivate the current version.
Once installed, you can add your translations using code similar to the following.
add_filter( 'teccc_add_terms', function(){
$translated_terms = array(
'atelier-cuisine-en-anglais',
'atelier-cuisine-en-espagnol',
'atelier-cuisine-en-francais',
'cooking-classes-in-english',
'cooking-classes-in-french',
'cooking-classes-in-spanish',
);
return $translated_terms;
});
You can remove terms either from the Event Categories page or from using another similar filter.
add_filter( 'teccc_delete_terms', function(){
$translated_terms = array(
'atelier-cuisine-en-anglais',
'atelier-cuisine-en-espagnol',
'atelier-cuisine-en-francais',
'cooking-classes-in-english',
'cooking-classes-in-french',
'cooking-classes-in-spanish',
);
return $translated_terms;
});
Don’t use both filters at the same time.
Thread Starter
jvier
(@jvier)
Using the updated plugin and the add_terms filter don’t seem to have changed anything besides the fact that the add_terms filter keeps adding categories everytime the calendar page is loaded.
It doesn’t seem to keep adding more and more for me. Can you delete all the added categories then check the Event Categories page to make sure they are gone and then try again.
I’ll keep testing too.
Thread Starter
jvier
(@jvier)
It keeps adding regardless.
I think maybe it’s because I add the filter to the wrong file, what file are you editing it in?
I think I need to put in a check to see if the term already exists. I’ll see about adding this tonight.
If you download, install, and activate. GitHub Updater you will get an update notification for the develop branch when I fix this.
https://github.com/afragen/github-updater/archive/master.zip
I just pushed a commit to check for the existence of the term before it adds it. This should take care of the duplicate issue.
Can you confirm?
Thread Starter
jvier
(@jvier)
Yes, it works perfectly now both the categories and the colors. Thank you.
Thanks so much for testing. I’ll push out a release.
Be sure to leave a review!
-
This reply was modified 7 years, 3 months ago by Andy Fragen.