Language_Handler
Language handler class.
Handles i18n, WPML integration, and Polylang integration.
Namespace: WebberZone\Knowledge_Base\Frontend
Since: 2.3.0
Source: includes/frontend/class-language-handler.php line 24
Methods
__construct()
Constructor.
Since: 2.3.0
Line: 31
public function __construct( );
load_plugin_textdomain() static
Initialises text domain for l10n.
Since: 2.3.0
Line: 43
static public function load_plugin_textdomain( ): void;
Returns: void
get_translated_term_id() static
Translate a term ID to the current language.
Widget and shortcode settings store the term ID saved by the admin in the default language. On a non-default-language page the stored ID must be resolved to the equivalent term in the current language before use.
Since: 3.0.0
Line: 60
static public function get_translated_term_id( int $term_id, string $taxonomy ): int;
| Type | Name | Description |
|---|---|---|
int |
$term_id |
Term ID in the default language. |
string |
$taxonomy |
Taxonomy slug. |
Returns: int — Translated term ID, or the original if no translation exists.
get_current_language() static
Return the current language slug, or an empty string when no multilingual plugin is active.
Since: 3.0.0
Line: 86
static public function get_current_language( ): string;
Returns: string — Language slug (e.g. ‘en’, ‘fr’) or ‘’ if not multilingual.
is_translatepress_active() static
Whether TranslatePress is active and exposes the API this integration needs.
Since: 3.1.5
Line: 105
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: 3.1.5
Line: 117
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: 3.1.5
Line: 139
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: 3.1.5
Line: 153
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: 3.1.5
Line: 178
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: 3.1.5
Line: 238
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.
get_trp_ajax_language() static
Resolve the TranslatePress language for an admin-ajax request.
Since: 3.1.5
Line: 313
static public function get_trp_ajax_language( ): string;
Returns: string — Language code, or an empty string when no translation is needed.
trp_translate_content() static
Translate a string with TranslatePress.
Since: 3.1.5
Line: 330
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: 3.1.5
Line: 348
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 Knowledge Base 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: 3.1.5
Line: 378
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.