TranslatePress
extends AbstractOutputBufferPlugin
in package
TranslatePress Output Buffering compatibility.
Tags
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.
- MARKER_SPLIT_TRANSLATION_ENTRY = 'splitTranslationEntry'
- MARKER_WRAP_ARRAY_TO_HTML = 'wrapArrayToHtml-'
- TEMPORARY_TEXT_DOMAIN_PREFIX = 'multilingual-temporary-text-domain'
Properties
- $currentTranslationEntries : mixed
- Current translations hold as an instance.
- $findI18nKeyOfTranslationCache : mixed
- $lockCurrentTranslations : mixed
- $splitTranslationEntriesCache : SplObjectStorage<Translation_Entry, array<string|int, Translation_Entry>>
- Cache for split translation entries.
- $translateArrayCache : mixed
- $pendingTranslations : mixed
- $useRawQueryForRead : mixed
Methods
- __construct() : mixed
- C'tor.
- 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`.
- filterWithExistingTranslatedTextDomain() : mixed
- Filter a list of locales and check if translations from a PO/MO file exists.
- 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() : array<string|int, string>
- Get all active languages.
- getCountryFlag() : string|false
- Get a `src` compatible link to the country flag.
- getCurrentLanguage() : string
- Get current language.
- 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() : string
- Get default language.
- getLanguageSwitcher() : array<string|int, array<string|int, mixed>>
- Get a language switcher for the current page.
- 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() : string
- Get the URL of a given URL for another locale.
- getPostLanguage() : string
- Get language of passed post id.
- getPostTranslationIds() : array<string|int, int>
- Get all translations of a given post type.
- getSkipHTMLForTag() : string
- Get the HTML attribute so the "dynamic" replacement gets disabled on frontend side. This can be useful for texts which are directly translated in PHP already and gets translated via JavaScript again.
- 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() : string
- Get translated name for a given locale.
- 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() : string
- Get the WordPress compatible language code of a given locale.
- isActive() : mixed
- Is a multilingual plugin active?
- isCurrentlyInEditorPreview() : bool
- Check if the translate plugin is currently in edit mode (preview).
- 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
- Maybe persist a translation in the database of available translations.
- 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.
- splitTranslationEntries() : mixed
- Split a translation entry key into multiple parts. This is useful when using e.g. TranslatePress and we need to find translations from MO file which is divided into multiple "parts" like `<strong>Text</strong>: Another text`.
- switch() : mixed
- Switch to a given language code. Please do not use this function directly, use `switchToLanguage` instead!
- switchToLanguage() : mixed
- Open given language and get their context. Context = switch to the language.
- teardownTemporaryTextDomain() : mixed
- Teardown the known temporary text domain.
- translatableStrings() : array<string|int, array<string|int, string>>
- Extract translatable strings from a given content. The returned array is a map of the original strings to the translatable strings.
- translateArray() : array<string|int, mixed>
- Translate a complete array to a given locale (recursively). This is mostly implemented by output buffer plugins like TranslatePress or Weglot.
- translateInput() : mixed
- Translate a given input from known translations (.po, .pot).
- translateStrings() : mixed
- Translate strings to a given locale. Do not use this function directly, use `translateArray` instead!
- 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.
- addWptexturizeToContent() : mixed
- TranslatePress does currently not support wptexturize, so we need to map it accordingly. Use this in conjunction with `remapWptexturizeFromContent`.
- mapInnerTextWithIdToOriginalString() : mixed
- Map the inner text with ID to the original string. See also `wrapArrayToHtml` and the `addInnerTextWithId` parameter.
- remapResultToReference() : mixed
- Remap the result to the referenced value `$content` for `translateString` method.
- remapWptexturizeFromContent() : mixed
- Remap the wptexturized strings back to the original strings if there is a translation. Use this before `remapResultToReference`.
- translateAndParseTranslateableStrings() : mixed
- Get all strings which are translatable.
- 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'
MARKER_SPLIT_TRANSLATION_ENTRY
public
mixed
MARKER_SPLIT_TRANSLATION_ENTRY
= 'splitTranslationEntry'
MARKER_WRAP_ARRAY_TO_HTML
public
mixed
MARKER_WRAP_ARRAY_TO_HTML
= 'wrapArrayToHtml-'
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
$findI18nKeyOfTranslationCache
protected
mixed
$findI18nKeyOfTranslationCache
= []
$lockCurrentTranslations
protected
mixed
$lockCurrentTranslations
= false
$splitTranslationEntriesCache
Cache for split translation entries.
protected
SplObjectStorage<Translation_Entry, array<string|int, Translation_Entry>>
$splitTranslationEntriesCache
= []
$translateArrayCache
protected
mixed
$translateArrayCache
= []
$pendingTranslations
private
mixed
$pendingTranslations
= []
$useRawQueryForRead
private
mixed
$useRawQueryForRead
= false
Methods
__construct()
C'tor.
public
__construct(mixed $domain[, mixed $moFile = null ][, mixed $overrideClass = null ]) : mixed
Parameters
- $domain : mixed
-
Original text domain where
post_titleand so on are translated - $moFile : mixed = 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
getPotLanguagesmethod
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
overridemethod (arguments:locale)
Return values
AbstractLanguagePlugindisableCopyAndSync()
Disable sync mechanism of our language plugin as it is handled by `Sync.php`.
public
disableCopyAndSync(mixed $sync) : mixed
Parameters
- $sync : mixed
filterWithExistingTranslatedTextDomain()
Filter a list of locales and check if translations from a PO/MO file exists.
public
filterWithExistingTranslatedTextDomain(array<string|int, string> $locales[, array<string|int, string> $skip = [] ]) : mixed
Parameters
- $locales : array<string|int, string>
- $skip : array<string|int, string> = []
-
Allows to skip locales and they will never be in the result, e.g. minimal translations; the codes need to be compatible with the WordPress locale format.
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
truewhen a translation got found - $contexts : array<string|int, string>
getActiveCountriesFlags()
Get the flags of all active languages.
public
getActiveCountriesFlags() : mixed
getActiveLanguages()
Get all active languages.
public
getActiveLanguages() : array<string|int, string>
Return values
array<string|int, string>getCountryFlag()
Get a `src` compatible link to the country flag.
public
getCountryFlag(mixed $locale) : string|false
Parameters
- $locale : mixed
Return values
string|falsegetCurrentLanguage()
Get current language.
public
getCurrentLanguage() : string
Return values
stringgetCurrentLanguageFallback()
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
getCurrentPostId(mixed $id, mixed $post_type[, mixed $locale = null ]) : int
Parameters
- $id : mixed
- $post_type : mixed
- $locale : mixed = null
-
Get item of this language
Return values
intgetCurrentTermId()
Get current id of passed term id and fallback to `0` when not translation found.
public
getCurrentTermId(mixed $id, mixed $taxonomy[, mixed $locale = null ]) : int
Parameters
- $id : mixed
- $taxonomy : mixed
- $locale : mixed = null
-
Get item of this language
Return values
intgetDefaultLanguage()
Get default language.
public
getDefaultLanguage() : string
Return values
stringgetLanguageSwitcher()
Get a language switcher for the current page.
public
getLanguageSwitcher() : array<string|int, array<string|int, mixed>>
Return values
array<string|int, array<string|int, mixed>>getLocalesBeforeSwitch()
List of locales before switching locale via `switchToLanguage`.
public
getLocalesBeforeSwitch() : mixed
getOriginalPostId()
Get original id of passed post id.
public
getOriginalPostId(mixed $id, mixed $post_type) : int
Parameters
- $id : mixed
- $post_type : mixed
Return values
intgetOriginalTermId()
Get original id of passed term id.
public
getOriginalTermId(mixed $id, mixed $taxonomy) : int
Parameters
- $id : mixed
- $taxonomy : mixed
Return values
intgetOverrideClassInstance()
Get an instance of the `overrideClass`.
public
getOverrideClassInstance() : mixed
getPermalink()
Get the URL of a given URL for another locale.
public
getPermalink(mixed $url, mixed $locale) : string
Parameters
- $url : mixed
- $locale : mixed
Return values
stringgetPostLanguage()
Get language of passed post id.
public
getPostLanguage(mixed $id) : string
Parameters
- $id : mixed
Return values
string —Returns empty string if no language is set or cannot be determined, otherwise the locale
getPostTranslationIds()
Get all translations of a given post type.
public
getPostTranslationIds(mixed $id, mixed $post_type) : array<string|int, int>
Parameters
- $id : mixed
- $post_type : mixed
Return values
array<string|int, int>getSkipHTMLForTag()
Get the HTML attribute so the "dynamic" replacement gets disabled on frontend side. This can be useful for texts which are directly translated in PHP already and gets translated via JavaScript again.
public
getSkipHTMLForTag([mixed $force = false ]) : string
Parameters
- $force : mixed = false
-
Pass
trueto get the attribute and do not respectisCurrentlyInEditorPreview
Return values
stringgetSync()
Get `Sync` instance for this plugin. Can be `null` if not given.
public
getSync() : mixed
getTaxonomyTranslationIds()
Get all translations of a given taxonomy.
public
getTaxonomyTranslationIds(mixed $id, mixed $taxonomy) : array<string|int, int>
Parameters
- $id : mixed
- $taxonomy : mixed
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()
Get translated name for a given locale.
public
getTranslatedName(mixed $locale) : string
Parameters
- $locale : mixed
Return values
stringgetTrpLanguageManager()
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()
Get the WordPress compatible language code of a given locale.
public
getWordPressCompatibleLanguageCode(mixed $locale) : string
Parameters
- $locale : mixed
Return values
stringisActive()
Is a multilingual plugin active?
public
isActive() : mixed
isCurrentlyInEditorPreview()
Check if the translate plugin is currently in edit mode (preview).
public
isCurrentlyInEditorPreview() : bool
Return values
boolisPresent()
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()
Maybe persist a translation in the database of available translations.
public
maybePersistTranslation(mixed $sourceContent, mixed $content, mixed $sourceLocale, mixed $targetLocale[, mixed $force = false ]) : mixed
Parameters
- $sourceContent : mixed
- $content : mixed
-
Pass
nullto delete the translation - $sourceLocale : mixed
- $targetLocale : mixed
- $force : mixed = false
-
Pass
trueto force persist the translation
persistTranslations()
Persist translations from `maybePersistTranslation`.
public
persistTranslations() : mixed
rest_prepare_post()
Add a `multilingual` section to a given post type.
public
rest_prepare_post(WP_REST_Response $response, WP_Post $post, WP_REST_Request $request) : mixed
Usage:
add_filter('rest_prepare_my_cpt', [$this->getCompLanguage(), 'rest_prepare_post'], 10, 3);
Parameters
- $response : WP_REST_Response
- $post : WP_Post
- $request : WP_REST_Request
Tags
rest_prepare_taxonomy()
Add a `multilingual` section to a given taxonomy.
public
rest_prepare_taxonomy(WP_REST_Response $response, WP_Term $term, WP_REST_Request $request) : mixed
Usage:
add_filter('rest_prepare_my_taxonomy', [$this->getCompLanguage(), 'rest_prepare_taxonomy'], 10, 3);
Parameters
- $response : WP_REST_Response
- $term : WP_Term
- $request : WP_REST_Request
Tags
setSync()
Set `Sync` instance for this plugin. Can be `null` if not given.
public
setSync(Sync $sync) : mixed
Parameters
- $sync : Sync
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
snapshotCurrentTranslations()
Snapshot the current translations.
public
snapshotCurrentTranslations([bool $force = false ]) : mixed
Parameters
- $force : bool = false
splitTranslationEntries()
Split a translation entry key into multiple parts. This is useful when using e.g. TranslatePress and we need to find translations from MO file which is divided into multiple "parts" like `<strong>Text</strong>: Another text`.
public
splitTranslationEntries(array<string|int, Translation_Entry> &$entriesToSplit) : mixed
Parameters
- $entriesToSplit : array<string|int, Translation_Entry>
Tags
switch()
Switch to a given language code. Please do not use this function directly, use `switchToLanguage` instead!
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, $temporaryTextDomain
teardownTemporaryTextDomain()
Teardown the known temporary text domain.
public
teardownTemporaryTextDomain() : mixed
translatableStrings()
Extract translatable strings from a given content. The returned array is a map of the original strings to the translatable strings.
public
translatableStrings(mixed $content) : array<string|int, array<string|int, string>>
Parameters
- $content : mixed
Return values
array<string|int, array<string|int, string>>translateArray()
Translate a complete array to a given locale (recursively). This is mostly implemented by output buffer plugins like TranslatePress or Weglot.
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()
Translate a given input from known translations (.po, .pot).
public
translateInput(mixed $input[, mixed $context = null ]) : mixed
Parameters
- $input : mixed
- $context : mixed = null
translateStrings()
Translate strings to a given locale. Do not use this function directly, use `translateArray` instead!
public
translateStrings(mixed &$content, mixed $locale[, mixed $context = null ]) : mixed
Parameters
- $content : mixed
-
This parameter needs to be passed as reference map, see also
translateArray. The implementation needs to update the references correctly - $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
addWptexturizeToContent()
TranslatePress does currently not support wptexturize, so we need to map it accordingly. Use this in conjunction with `remapWptexturizeFromContent`.
protected
addWptexturizeToContent(array<string|int, string> &$content) : mixed
Parameters
- $content : array<string|int, string>
mapInnerTextWithIdToOriginalString()
Map the inner text with ID to the original string. See also `wrapArrayToHtml` and the `addInnerTextWithId` parameter.
protected
mapInnerTextWithIdToOriginalString(array<string|int, string> $translatableStrings, array<string|int, string> $content, array<string|int, array<string|int, string>> &$result) : mixed
Parameters
- $translatableStrings : array<string|int, string>
- $content : array<string|int, string>
- $result : array<string|int, array<string|int, string>>
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
remapWptexturizeFromContent()
Remap the wptexturized strings back to the original strings if there is a translation. Use this before `remapResultToReference`.
protected
remapWptexturizeFromContent(int $contentCount, array<string|int, string> &$content, array<string|int, string> &$result) : mixed
Parameters
- $contentCount : int
- $content : array<string|int, string>
- $result : array<string|int, string>
translateAndParseTranslateableStrings()
Get all strings which are translatable.
protected
translateAndParseTranslateableStrings(array<string|int, string> $content[, bool $skipTranslate = false ]) : mixed
Parameters
- $content : array<string|int, string>
- $skipTranslate : bool = false
-
If you pass
true, no translation is done and only the strings are returned. It additionally returns the 4th return array variable$contentToTranslateableStringsMapwhich maps the original strings to the translatable strings.
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[, bool $addInnerTextWithId = false ]) : mixed
Parameters
- $content : array<string|int, string>
- $addInnerTextWithId : bool = false
-
Instead of the content, the inner text will be in format
<div>wrapArrayToHtml-{id}</div><div>{content}</div>. This allows you to map the content back to the original strings by iterating over an array of translatable strings. See alsomapInnerTextWithIdToOriginalString.
wrapHtmlToArray()
Reverse `wrapArrayToHtml` functionality.
protected
wrapHtmlToArray(string $html[, callable $strip = null ]) : mixed
Parameters
- $html : string
- $strip : callable = null