Recent

Language_Handlerclass

Language_Handler

Language handler class.

Namespace: WebberZone\Contextual_Related_Posts\Frontend
Since: 3.5.0
Source: includes/frontend/class-language-handler.php line 22

Methods

__construct()

Constructor.

Since: 3.5.0
Line: 29

public function __construct(  );

load_plugin_textdomain() static

Initialises text domain for l10n.

Since: 3.5.0
Line: 42

static public function load_plugin_textdomain(  ): void;

Returns: void

translate_ids() static

Get the ID of a post in the current language. Works with WPML and PolyLang.

Since: 3.5.0
Line: 54

static public function translate_ids( $results ): \WP_Post[];
Type Name Description
int[] $results Arry of Posts.

Returns: \WP_Post[] — Updated array of WP_Post objects.

object_id_cur_lang() static

Returns the object identifier for the current language (WPML).

Since: 3.5.0
Line: 90

static public function object_id_cur_lang( $post ): \WP_Post|array|null;
Type Name Description
int|string|\WP_Post $post Post object or Post ID.

Returns: \WP_Post|array|null — Post opbject, updated if needed.

is_translatepress_active() static

Whether TranslatePress is active and exposes the API this integration needs.

Since: 4.5.0
Line: 136

static public function is_translatepress_active(  ): bool;

Returns: bool — True if TranslatePress can be used.

get_trp_component() static

Fetch a TranslatePress component instance.

Since: 4.5.0
Line: 148

static public function get_trp_component( string $component ): object|null;
Type Name Description
string $component Component name, e.g. url_converter.

Returns: object|null — Component instance or null when unavailable.

get_trp_settings() static

Get the TranslatePress settings array.

Since: 4.5.0
Line: 170

static public function get_trp_settings(  ): array;

Returns: array — TranslatePress settings.

get_trp_current_language() static

Get the TranslatePress language the current front-end request is rendering in.

Since: 4.5.0
Line: 184

static public function get_trp_current_language(  ): string;

Returns: string — Language code, or an empty string when TranslatePress is inactive

get_cache_language() static

Get a language identifier for cache keys.

Rendered output is language-specific — TranslatePress filters home_url(), and WPML/Polylang resolve different post IDs — so cached HTML and post lists must not be shared between languages.

Since: 4.5.0
Line: 209

static public function get_cache_language(  ): string;

Returns: string — Current language code, or an empty string when the site is monolingual.

get_trp_rest_language() static

Resolve the TranslatePress language a REST request should be rendered in.

TranslatePress derives the language from the page URL, but REST routes carry no language prefix, so the language is taken from an explicit lang parameter and falls back to the referring front-end URL.

Since: 4.5.0
Line: 269

static public function get_trp_rest_language( $request = ... ): string;
Type Name Description
\WP_REST_Request|null $request REST request.

Returns: string — Language code, or an empty string when no translation is needed.

trp_translate_content() static

Translate a string with TranslatePress.

Since: 4.5.0
Line: 335

static public function trp_translate_content( string $content, string $language ): string;
Type Name Description
string $content Content in the default language. Text or HTML.
string $language Target language code.

Returns: string — Translated content.

trp_translate_url() static

Convert a URL to its TranslatePress equivalent in the given language.

Since: 4.5.0
Line: 353

static public function trp_translate_url( string $url, string $language ): string;
Type Name Description
string $url URL in the default language.
string $language Target language code.

Returns: string — Converted URL.

translate_rest_response() static

Translate the CRP REST API response with TranslatePress.

TranslatePress’s own page output buffer never runs for REST requests, so the related posts returned to block editors and the lazy load script would otherwise always be served in the default language.

Since: 4.5.0
Line: 383

static public function translate_rest_response( $result, $server, $request ): mixed;
Type Name Description
mixed $result Response data to send to the client.
mixed $server Server instance.
mixed $request Request used to generate the response.

Returns: mixed — Response data, translated where applicable.