Overview

This filter allows you to translate a set of strings that are otherwise not translatable using __() or _e(). These strings are dynamic, “in-database” strings, so WPML or Polylang cannot see them.

Translatable strings

The following strings can be translated with the facetwp_i18n hook. For an example of how to use it, see below.

Facet type Option / string
Dropdown facet Default label
Radio facet Default label
fSelect facet Default label
Hierarchy facet Default label
Search facet Placeholder text
Autocomplete facet Placeholder text
Pager facet
Type: Page numbers Dots label
Prev button label
Next button label
Type: Result counts Count text (plural)
Count text (singular)
Count text (no results)
Type: Load more Load more text
Loading text
Type: Per page Default label
“Show all” text (if a non-numberic option is added in the settings)
Reset facet Reset text
Sort facet Default label
All sort option labels
Hierarchy Select facet Depth labels
Time Since facet Choices labels
All facet types Facet labels (which appear as headings/labels in the Mobile Flyout and as labels in User Selections)

Parameters

  • $string | string | The string to translate

Usage example

Add the following code (adapted with your translated strings) to your (child) theme’s functions.php:

add_filter( 'facetwp_i18n', function( $string ) {
    if ( isset( FWP()->facet->http_params['lang'] ) ) {
        $lang = FWP()->facet->http_params['lang'];

        $translations = [];
        $translations['es']['Any'] = 'Cualquier';
        $translations['de']['Any'] = 'Jeder';
        $translations['es']['Enter keywords'] = 'Introduzca las palabras clave';
        $translations['de']['Enter keywords'] = 'Geben Sie Schlüsselwörter';

        if ( isset( $translations[ $lang ][ $string ] ) ) {
            return $translations[ $lang ][ $string ];
        }
    }

    return $string;
});

More examples

See also