Language_Handler
Language handler class.
Namespace: WebberZone\Top_Ten\Frontend
Since: 3.3.3
Source: includes/frontend/class-language-handler.php line 22
Methods
__construct()
Constructor.
Since: 3.3.3
Line: 29
public function __construct( );
translate_ids() static
Get the ID of a post in the current language. Works with WPML and PolyLang.
Since: 3.3.3
Line: 43
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.3.3
Line: 83
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.1
Line: 130
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.1
Line: 142
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.1
Line: 164
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.1
Line: 178
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.1
Line: 203
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.1
Line: 263
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.1
Line: 340
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.1
Line: 358
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 Top 10 REST API response with TranslatePress.
TranslatePress’s own page output buffer never runs for REST requests, so the output returned over REST would otherwise always be served in the default language.
Since: 4.5.1
Line: 388
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.