[Resolved] How to display FacetWP translations in secondary language
This thread is resolved. Here is a description of the problem and solution.
Problem:
FacetWP filters not displaying translation correctly. Solution:
Add the following code to the functions.php file:
// WPML Workaround for compsupp-6751
function wpml_compsupp6751_translate_facet_display_value( $label, $args ) {
if ( class_exists('Sitepress') ) {
$wpml_default_lang = apply_filters('wpml_default_language', NULL );
$wpml_current_lang = apply_filters( 'wpml_current_language', NULL );
if ($wpml_default_lang == $wpml_current_lang ) {
do_action( 'wpml_register_single_string', 'FacetWP', 'Facet Display Value : '.substr($label, 0, 10), $label );
}
// Apply the translation to the string
$label = apply_filters('wpml_translate_single_string', $label , 'FacetWP', 'Facet Display Value : '.substr($label, 0, 10) );
}
return $label;
}
add_filter( 'facetwp_facet_display_value', 'wpml_compsupp6751_translate_facet_display_value', 10, 2 );
Then, visit the page with the FacetWP filters in the default language.
Finally, go to WPML -> String Translation and search for strings containing "Facet Display Value: ".
After translating them, the FacetWP filters will display correctly in the secondary languages.
This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
I did as you wrote, the translated colors are now displayed in the Admin panel.
I didn't mention what I need it for.
I use these colors in filters, via FacetWP. Apparently it's important 🙂
On the pages, these filters remained untranslated. Here are examples of one page in different languages: hidden link hidden link
I have a solution for your issue. It seems like this issue with FacetWP has already come up and our developers have a workaround.
I tested it on your site and it works.
The issue was that the translated labels of the ACF fields are not being used correctly on the frontend, so what we did was register the correct strings. Then it is simply using WPML -> String Translation to translate a new set of labels, which will show up on the frontend.
This is the code I added to the *functions.php* file that registers the correct strings for translation:
// WPML Workaround for compsupp-6751
function wpml_compsupp6751_translate_facet_display_value( $label, $args ) {
if ( class_exists('Sitepress') ) {
$wpml_default_lang = apply_filters('wpml_default_language', NULL );
$wpml_current_lang = apply_filters( 'wpml_current_language', NULL );
if ($wpml_default_lang == $wpml_current_lang ) {
do_action( 'wpml_register_single_string', 'FacetWP', 'Facet Display Value : '.substr($label, 0, 10), $label );
}
// Apply the translation to the string
$label = apply_filters('wpml_translate_single_string', $label , 'FacetWP', 'Facet Display Value : '.substr($label, 0, 10) );
}
return $label;
}
add_filter( 'facetwp_facet_display_value', 'wpml_compsupp6751_translate_facet_display_value', 10, 2 );
Then, after visiting the site for the first time in the default language the strings are registered.
And finally, all that is left is to translate the newly registered labels. For that simply look for strings containing "Facet Display Value: " in the WPML -> String Translation tab. I have added a screenshot to show you exactly how.
Please update me on if this does not resolve your issue or you have any further questions.