Documentation

TranslatePress extends AbstractOutputBufferPlugin
in package

TranslatePress Output Buffering compatibility.

Tags
see
https://translatepress.com/

Table of Contents

Constants

EDIT_QUERY_VAR  = 'trp-edit-translation'
HTML_TAG_IGNORE  = '<ignore-me-completely %s></ignore-me-completely>'
Our plugin does in general support JSON, but it slows down the site extremely, let's do this hacky with a single HTML string.
HTML_TAG_KEEP  = 'keep-me'
Wrap the complete string within a HTML tag so our plugin can extract it correctly and handles it as HTML.
TEMPORARY_TEXT_DOMAIN_PREFIX  = 'multilingual-temporary-text-domain'

Properties

$currentTranslationEntries  : mixed
Current translations hold as an instance.
$findI18nKeyOfTranslationCache  : mixed
$lockCurrentTranslations  : mixed
$domain  : string
Use this as text domain for translations. E. g. `post_title` is automatically passed while duplicating a post to another language.
$localesBeforeSwitch  : array<string|int, string>
List of locales before switching locale via `switchToLanguage`.
$moFile  : mixed
$overrideClass  : mixed
$pendingTranslations  : mixed
$sync  : Sync
The sync instance for this plugin.
$temporaryTextDomain  : TemporaryTextDomain
Temporary text domain, if given.
$useRawQueryForRead  : mixed

Methods

__construct()  : mixed
createTemporaryTextDomain()  : mixed
Create a temporary text domain.
determineImplementation()  : AbstractLanguagePlugin
Determine implementation class.
disableCopyAndSync()  : mixed
Disable sync mechanism of our language plugin as it is handled by `Sync.php`.
findI18nKeyOfTranslation()  : mixed
The same as `findI18nKeyOfTranslationRaw`, but with caching enabled as this could be called very often.
findI18nKeyOfTranslationRaw()  : mixed
Find an i18n key for `__()` from a given translated string.
getActiveCountriesFlags()  : mixed
Get the flags of all active languages.
getActiveLanguages()  : mixed
getCountryFlag()  : mixed
getCurrentLanguage()  : mixed
getCurrentLanguageFallback()  : mixed
Get current language or fallback to default language when the multilingual is in a state like "Show all languages" (option known in the admin toolbar).
getCurrentPostId()  : int
Get current id of passed post id and fallback to passed id, when no translation found.
getCurrentTermId()  : int
Get current id of passed term id and fallback to `0` when not translation found.
getDefaultLanguage()  : mixed
getLanguageSwitcher()  : mixed
getLocalesBeforeSwitch()  : mixed
List of locales before switching locale via `switchToLanguage`.
getOriginalPostId()  : int
Get original id of passed post id.
getOriginalTermId()  : int
Get original id of passed term id.
getOverrideClassInstance()  : mixed
Get an instance of the `overrideClass`.
getPermalink()  : mixed
getPostTranslationIds()  : array<string|int, int>
Get all translations of a given post type.
getSkipHTMLForTag()  : mixed
getSync()  : mixed
Get `Sync` instance for this plugin. Can be `null` if not given.
getTaxonomyTranslationIds()  : array<string|int, int>
Get all translations of a given taxonomy.
getTemporaryTextDomainName()  : mixed
Get the current temporary text domain name which can be used for `__` when e.g. inside `switchToLanguage`.
getTranslatedName()  : mixed
getTrpLanguageManager()  : mixed
Get TranslatePress language manager class.
getTrpQueryManager()  : mixed
Get TranslatePress query manager class.
getTrpRenderManager()  : mixed
Get TranslatePress render manager class.
getTrpSettingsManager()  : mixed
Get TranslatePress settings manager class.
getWordPressCompatibleLanguageCode()  : mixed
isActive()  : mixed
Is a multilingual plugin active?
isCurrentlyInEditorPreview()  : mixed
isPresent()  : mixed
Check if TranslatePress is active. We also need to check for XML availability cause we need to workaround this a bit (object to xml -> translate -> reverse).
iterateAllLanguagesContext()  : mixed
Iterate all language contexts.
iterateOtherLanguagesContext()  : mixed
Iterate all other languages than current one and get their context.
lockCurrentTranslations()  : mixed
Do not allow to take another snapshot of current translations.
maybePersistTranslation()  : mixed
persistTranslations()  : mixed
Persist translations from `maybePersistTranslation`.
rest_prepare_post()  : mixed
Add a `multilingual` section to a given post type.
rest_prepare_taxonomy()  : mixed
Add a `multilingual` section to a given taxonomy.
setSync()  : mixed
Set `Sync` instance for this plugin. Can be `null` if not given.
setUseRawQueryForRead()  : mixed
Enable this if you want to bypass the TranslatePress API and directly use the TranslatePress database tables for reading translations. This could improve performance significantely but keep in mind that this does also skip gettext mechanism.
snapshotCurrentTranslations()  : mixed
Snapshot the current translations.
switch()  : mixed
switchToLanguage()  : mixed
Open given language and get their context. Context = switch to the language.
teardownTemporaryTextDomain()  : mixed
Teardown the known temporary text domain.
translateArray()  : array<string|int, mixed>
Translate a complete array to a given locale (recursively).
translateInput()  : mixed
translateStrings()  : mixed
trp_gettext_blacklist_functions()  : mixed
TranslatePress does automatically hook into the `__` and other localization functions at the time of localizing a script through e.g. `wp_localize_script`. At this time, unwanted characters are added to the translation. Due to the fact, our `translateString` supports MO/PO files, we can skip this.
unsetCurrentTranslations()  : mixed
Unset current translations.
remapResultToReference()  : mixed
Remap the result to the referenced value `$content` for `translateString` method.
translateStringFromMo()  : array<string|int, mixed>
Translate string from `.mo` file. Please consider to create a temporary text domain before!
translateStringsRawQuery()  : mixed
`translateStrings` but directly accessing the database instead of using the TranslatePress API.
wrapArrayToHtml()  : mixed
Wrap a complete array to valid HTML format so output buffer plugins can translate the HTML instead of JSON. This can be useful if the plugin does not support it well enough or JSON walker slows down the page extremely.
wrapHtmlToArray()  : mixed
Reverse `wrapArrayToHtml` functionality.

Constants

EDIT_QUERY_VAR

public mixed EDIT_QUERY_VAR = 'trp-edit-translation'

HTML_TAG_IGNORE

Our plugin does in general support JSON, but it slows down the site extremely, let's do this hacky with a single HTML string.

public mixed HTML_TAG_IGNORE = '<ignore-me-completely %s></ignore-me-completely>'

..

HTML_TAG_KEEP

Wrap the complete string within a HTML tag so our plugin can extract it correctly and handles it as HTML.

public mixed HTML_TAG_KEEP = 'keep-me'

TEMPORARY_TEXT_DOMAIN_PREFIX

public mixed TEMPORARY_TEXT_DOMAIN_PREFIX = 'multilingual-temporary-text-domain'

Properties

$currentTranslationEntries

Current translations hold as an instance.

protected mixed $currentTranslationEntries = null

$domain

Use this as text domain for translations. E. g. `post_title` is automatically passed while duplicating a post to another language.

private string $domain

$localesBeforeSwitch

List of locales before switching locale via `switchToLanguage`.

private array<string|int, string> $localesBeforeSwitch = []

Methods

__construct()

public __construct(mixed $domain[, mixed $moFile = null ][, mixed $overrideClass = null ]) : mixed
Parameters
$domain : mixed
$moFile : mixed = null
$overrideClass : mixed = null

createTemporaryTextDomain()

Create a temporary text domain.

public createTemporaryTextDomain(string $locale[, bool $force = false ]) : mixed
Parameters
$locale : string
$force : bool = false

determineImplementation()

Determine implementation class.

public static determineImplementation([string $domain = '' ][, string $moFile = null ][, mixed $overrideClass = null ]) : AbstractLanguagePlugin
Parameters
$domain : string = ''
$moFile : string = null

Needed for TemporaryTextDomain. E. g. /var/www/html/wp-content/plugins/real-cookie-banner/languages/real-cookie-banner-%s.mo

$overrideClass : mixed = null

A class with a override method (arguments: locale)

Return values
AbstractLanguagePlugin

disableCopyAndSync()

Disable sync mechanism of our language plugin as it is handled by `Sync.php`.

public abstract disableCopyAndSync(Sync $sync) : mixed
Parameters
$sync : Sync

findI18nKeyOfTranslation()

The same as `findI18nKeyOfTranslationRaw`, but with caching enabled as this could be called very often.

public findI18nKeyOfTranslation(string $input, bool &$found, array<string|int, string> &$contexts) : mixed
Parameters
$input : string
$found : bool
$contexts : array<string|int, string>

findI18nKeyOfTranslationRaw()

Find an i18n key for `__()` from a given translated string.

public findI18nKeyOfTranslationRaw(string $input, bool &$found, array<string|int, string> &$contexts) : mixed
Parameters
$input : string
$found : bool

Sets to true when a translation got found

$contexts : array<string|int, string>

getActiveCountriesFlags()

Get the flags of all active languages.

public getActiveCountriesFlags() : mixed

getCountryFlag()

public getCountryFlag(mixed $locale) : mixed
Parameters
$locale : mixed

getCurrentLanguageFallback()

Get current language or fallback to default language when the multilingual is in a state like "Show all languages" (option known in the admin toolbar).

public getCurrentLanguageFallback() : mixed

getCurrentPostId()

Get current id of passed post id and fallback to passed id, when no translation found.

public abstract getCurrentPostId(int $id, string $post_type[, string $locale = null ]) : int
Parameters
$id : int
$post_type : string
$locale : string = null

Get item of this language

Return values
int

getCurrentTermId()

Get current id of passed term id and fallback to `0` when not translation found.

public abstract getCurrentTermId(int $id, string $taxonomy[, string $locale = null ]) : int
Parameters
$id : int
$taxonomy : string
$locale : string = null

Get item of this language

Return values
int

getLocalesBeforeSwitch()

List of locales before switching locale via `switchToLanguage`.

public getLocalesBeforeSwitch() : mixed

getOriginalPostId()

Get original id of passed post id.

public abstract getOriginalPostId(int $id, string $post_type) : int
Parameters
$id : int
$post_type : string
Return values
int

getOriginalTermId()

Get original id of passed term id.

public abstract getOriginalTermId(int $id, string $taxonomy) : int
Parameters
$id : int
$taxonomy : string
Return values
int

getOverrideClassInstance()

Get an instance of the `overrideClass`.

public getOverrideClassInstance() : mixed
public getPermalink(mixed $url, mixed $locale) : mixed
Parameters
$url : mixed
$locale : mixed

getPostTranslationIds()

Get all translations of a given post type.

public abstract getPostTranslationIds(int $id, string $post_type) : array<string|int, int>
Parameters
$id : int
$post_type : string
Return values
array<string|int, int>

getSkipHTMLForTag()

public getSkipHTMLForTag([mixed $force = false ]) : mixed
Parameters
$force : mixed = false

getSync()

Get `Sync` instance for this plugin. Can be `null` if not given.

public getSync() : mixed

getTaxonomyTranslationIds()

Get all translations of a given taxonomy.

public abstract getTaxonomyTranslationIds(int $id, string $taxonomy) : array<string|int, int>
Parameters
$id : int
$taxonomy : string
Return values
array<string|int, int>

getTemporaryTextDomainName()

Get the current temporary text domain name which can be used for `__` when e.g. inside `switchToLanguage`.

public getTemporaryTextDomainName() : mixed

getTranslatedName()

public getTranslatedName(mixed $locale) : mixed
Parameters
$locale : mixed

getTrpLanguageManager()

Get TranslatePress language manager class.

public getTrpLanguageManager() : mixed

getTrpQueryManager()

Get TranslatePress query manager class.

public getTrpQueryManager() : mixed

getTrpRenderManager()

Get TranslatePress render manager class.

public getTrpRenderManager() : mixed

getTrpSettingsManager()

Get TranslatePress settings manager class.

public getTrpSettingsManager() : mixed

getWordPressCompatibleLanguageCode()

public getWordPressCompatibleLanguageCode(mixed $locale) : mixed
Parameters
$locale : mixed

isCurrentlyInEditorPreview()

public isCurrentlyInEditorPreview() : mixed

isPresent()

Check if TranslatePress is active. We also need to check for XML availability cause we need to workaround this a bit (object to xml -> translate -> reverse).

public static isPresent() : mixed

iterateAllLanguagesContext()

Iterate all language contexts.

public iterateAllLanguagesContext(callable $callback[, array<string|int, string> $skip = [] ]) : mixed
Parameters
$callback : callable

Arguments: $locale, $currentLanguage

$skip : array<string|int, string> = []

Skip locales

iterateOtherLanguagesContext()

Iterate all other languages than current one and get their context.

public iterateOtherLanguagesContext(callable $callback) : mixed

Context = switch to the language.

Attention: If you are using switchToLanguage in a REST API call, please consider to pass the _wp_http_referer parameter. E.g. TranslatePress checks if the referer is an admin page and behaves differently.

Parameters
$callback : callable

Arguments: $locale, $currentLanguage

lockCurrentTranslations()

Do not allow to take another snapshot of current translations.

public lockCurrentTranslations([bool $state = false ]) : mixed
Parameters
$state : bool = false

maybePersistTranslation()

public maybePersistTranslation(mixed $sourceContent, mixed $content, mixed $sourceLocale, mixed $targetLocale) : mixed
Parameters
$sourceContent : mixed
$content : mixed
$sourceLocale : mixed
$targetLocale : mixed

persistTranslations()

Persist translations from `maybePersistTranslation`.

public persistTranslations() : mixed

setUseRawQueryForRead()

Enable this if you want to bypass the TranslatePress API and directly use the TranslatePress database tables for reading translations. This could improve performance significantely but keep in mind that this does also skip gettext mechanism.

public setUseRawQueryForRead(bool $state) : mixed

This also skips the parsing of the passed string, when it is e.g. a HTML and paragraphs are split into multiple translations. So, make sure that the passed original strings to translateArray are standalone strings (e.g. URLs).

Parameters
$state : bool
Tags
codeCoverageIgnore

snapshotCurrentTranslations()

Snapshot the current translations.

public snapshotCurrentTranslations([bool $force = false ]) : mixed
Parameters
$force : bool = false

switch()

public switch(mixed $locale) : mixed
Parameters
$locale : mixed

switchToLanguage()

Open given language and get their context. Context = switch to the language.

public switchToLanguage(string $locale, callable $callback) : mixed

Attention: If you are using switchToLanguage in a REST API call, please consider to pass the _wp_http_referer parameter. E.g. TranslatePress checks if the referer is an admin page and behaves differently.

Parameters
$locale : string
$callback : callable

Arguments: $locale, $currentLanguage

teardownTemporaryTextDomain()

Teardown the known temporary text domain.

public teardownTemporaryTextDomain() : mixed

translateArray()

Translate a complete array to a given locale (recursively).

public translateArray(array<string|int, mixed> $content[, array<string|int, string> $skipKeys = [] ][, string $locale = null ][, array<string|int, string> $context = null ]) : array<string|int, mixed>
Parameters
$content : array<string|int, mixed>
$skipKeys : array<string|int, string> = []
$locale : string = null
$context : array<string|int, string> = null
Return values
array<string|int, mixed>

translateInput()

public translateInput(mixed $input[, mixed $context = null ]) : mixed
Parameters
$input : mixed
$context : mixed = null

translateStrings()

public translateStrings(mixed &$content, mixed $locale[, mixed $context = null ]) : mixed
Parameters
$content : mixed
$locale : mixed
$context : mixed = null

trp_gettext_blacklist_functions()

TranslatePress does automatically hook into the `__` and other localization functions at the time of localizing a script through e.g. `wp_localize_script`. At this time, unwanted characters are added to the translation. Due to the fact, our `translateString` supports MO/PO files, we can skip this.

public trp_gettext_blacklist_functions(string $methods) : mixed
Parameters
$methods : string

unsetCurrentTranslations()

Unset current translations.

public unsetCurrentTranslations() : mixed

remapResultToReference()

Remap the result to the referenced value `$content` for `translateString` method.

protected remapResultToReference(array<string|int, string> &$content, array<string|int, string> $result, string $locale[, array<string|int, string> $context = null ]) : mixed
Parameters
$content : array<string|int, string>
$result : array<string|int, string>
$locale : string
$context : array<string|int, string> = null

translateStringFromMo()

Translate string from `.mo` file. Please consider to create a temporary text domain before!

protected translateStringFromMo(string $content, string $targetLocale[, array<string|int, string> $context = null ]) : array<string|int, mixed>
Parameters
$content : string
$targetLocale : string
$context : array<string|int, string> = null
Return values
array<string|int, mixed>

[$found: boolean, $content: string]

translateStringsRawQuery()

`translateStrings` but directly accessing the database instead of using the TranslatePress API.

protected translateStringsRawQuery(array<string|int, string> &$content, string $locale) : mixed

You need to activate this explictely with $this->setUseRawQueryForRead(true).

Parameters
$content : array<string|int, string>
$locale : string

wrapArrayToHtml()

Wrap a complete array to valid HTML format so output buffer plugins can translate the HTML instead of JSON. This can be useful if the plugin does not support it well enough or JSON walker slows down the page extremely.

protected wrapArrayToHtml(array<string|int, string> $content) : mixed
Parameters
$content : array<string|int, string>

wrapHtmlToArray()

Reverse `wrapArrayToHtml` functionality.

protected wrapHtmlToArray(string $html[, callable $strip = null ]) : mixed
Parameters
$html : string
$strip : callable = null

        
On this page

Search results