Documentation

PolyLang extends AbstractSyncPlugin
in package

PolyLang language handler.

Table of Contents

Constants

TEMPORARY_TEXT_DOMAIN_PREFIX  = 'multilingual-temporary-text-domain'

Properties

$copyToOtherLanguageMap  : mixed
`copyTermToOtherLanguage` and `copyPostToOtherLanguage` create a duplicate of a term and post. This map holds the mapping of original-ID to translation-ID. This map is filled with the translations like this:
$currentTranslationEntries  : mixed
Current translations hold as an instance.
$findI18nKeyOfTranslationCache  : mixed
$lockCurrentTranslations  : mixed
$disabledCopyAndSync  : 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
$sync  : Sync
The sync instance for this plugin.
$temporaryTextDomain  : TemporaryTextDomain
Temporary text domain, if given.

Methods

__construct()  : mixed
C'tor.
copyPostTaxonomies()  : mixed
Copy already existing taxonomies as it can be inserted with `tax_input` directly.
copyPostToOtherLanguage()  : int|bool
Translate given post to other language.
copyTermToOtherLanguage()  : int|bool
Translate given term to other language.
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`.
duplicatePostMeta()  : mixed
Copy already existing meta as it can be inserted with `meta_input` directly.
filterMetaValue()  : mixed
Apply a WordPress filter so a meta value can be modified for copy process to other languages.
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()  : mixed
getCurrentTermId()  : mixed
getDefaultLanguage()  : mixed
getLanguageSwitcher()  : mixed
getLocalesBeforeSwitch()  : mixed
List of locales before switching locale via `switchToLanguage`.
getOriginalPostId()  : mixed
getOriginalTermId()  : mixed
getOverrideClassInstance()  : mixed
Get an instance of the `overrideClass`.
getPermalink()  : mixed
getPostTranslationIds()  : mixed
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()  : mixed
getTemporaryTextDomainName()  : mixed
Get the current temporary text domain name which can be used for `__` when e.g. inside `switchToLanguage`.
getTranslatedName()  : mixed
getWordPressCompatibleLanguageCode()  : mixed
isActive()  : mixed
Is a multilingual plugin active?
isCurrentlyInEditorPreview()  : bool
Check if the translate plugin is currently in edit mode (preview).
isPresent()  : mixed
Check if PolyLang is active.
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.
postCopiedToAllOtherLanguages()  : mixed
This method is called due to `Sync::save_post`. It allows you to get a list of all translations of a post in an associate array.
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.
setPostLanguage()  : mixed
This method is called due to `Sync::save_post`. It allows you to assign a post to a given language.
setSync()  : mixed
Set `Sync` instance for this plugin. Can be `null` if not given.
setTermLanguage()  : mixed
This method is called due to `Sync::created_term`. It allows you to assign a term to a given language.
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.
termCopiedToAllOtherLanguages()  : mixed
This method is called due to `Sync::created_term`. It allows you to get a list of all translations of a term in an associate array.
translateArray()  : array<string|int, mixed>
Translate a complete array to a given locale (recursively).
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!
unsetCurrentTranslations()  : mixed
Unset current translations.
duplicateMeta()  : mixed
Listen to meta (term, post, ...) addition and copy.
duplicatePost()  : mixed
A simple `get_post` => `wp_insert_post` wrapper.
duplicateTerm()  : mixed
A simple `get_term` => `wp_insert_term` wrapper.
duplicateTermMeta()  : mixed
Listen to term meta addition and copy.
translateStringFromMo()  : array<string|int, mixed>
Translate string from `.mo` file. Please consider to create a temporary text domain before!

Constants

TEMPORARY_TEXT_DOMAIN_PREFIX

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

Properties

$copyToOtherLanguageMap

`copyTermToOtherLanguage` and `copyPostToOtherLanguage` create a duplicate of a term and post. This map holds the mapping of original-ID to translation-ID. This map is filled with the translations like this:

protected mixed $copyToOtherLanguageMap = ['post' => [], 'term' => []]
{
  "post": {
    "de": {
         800: 801
    }
  }
}

$currentTranslationEntries

Current translations hold as an instance.

protected mixed $currentTranslationEntries = null

$disabledCopyAndSync

private mixed $disabledCopyAndSync = false

$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()

C'tor.

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

Original text domain where post_title and so on are translated

$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 getPotLanguages method

Tags
codeCoverageIgnore

copyPostTaxonomies()

Copy already existing taxonomies as it can be inserted with `tax_input` directly.

public copyPostTaxonomies(int $from, int $to, array<string|int, string> $taxonomies, string $locale) : mixed

Additionally listen to term additions and copy.

Parameters
$from : int
$to : int
$taxonomies : array<string|int, string>

Taxonomy keys to copy

$locale : string

The destination locale

copyPostToOtherLanguage()

Translate given post to other language.

public copyPostToOtherLanguage(string $locale, string $currentLanguage, string $post_id, array<string|int, string> $meta, array<string|int, string> $taxonomies) : int|bool
Parameters
$locale : string
$currentLanguage : string
$post_id : string
$meta : array<string|int, string>

The meta keys to copy

$taxonomies : array<string|int, string>

The taxonomies to copy

Return values
int|bool

The new created post id

copyTermToOtherLanguage()

Translate given term to other language.

public copyTermToOtherLanguage(string $locale, string $currentLanguage, int $term_id, string $taxonomy, array<string|int, string> $meta) : int|bool
Parameters
$locale : string
$currentLanguage : string
$term_id : int
$taxonomy : string
$meta : array<string|int, string>

The meta keys to copy

Return values
int|bool

The new created term id

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 disableCopyAndSync(Sync $sync) : mixed
Parameters
$sync : Sync

duplicatePostMeta()

Copy already existing meta as it can be inserted with `meta_input` directly.

public duplicatePostMeta(int $from, int $to, array<string|int, string> $meta) : mixed

Additionally listen to term meta addition and copy.

Parameters
$from : int
$to : int
$meta : array<string|int, string>

Meta keys to copy

filterMetaValue()

Apply a WordPress filter so a meta value can be modified for copy process to other languages.

public filterMetaValue(string $type, int $from, int $to, string $meta_key, mixed $meta_value, string $locale) : mixed
Parameters
$type : string

E. g. 'post'

$from : int

Object id of source language item

$to : int

Object id of destination language item

$meta_key : string
$meta_value : mixed
$locale : string

Destination locale

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

getActiveLanguages()

public getActiveLanguages() : mixed

getCountryFlag()

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

getCurrentLanguage()

public getCurrentLanguage() : 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()

public getCurrentPostId(mixed $id, mixed $post_type[, mixed $locale = null ]) : mixed
Parameters
$id : mixed
$post_type : mixed
$locale : mixed = null

getCurrentTermId()

public getCurrentTermId(mixed $id, mixed $taxonomy[, mixed $locale = null ]) : mixed
Parameters
$id : mixed
$taxonomy : mixed
$locale : mixed = null

getDefaultLanguage()

public getDefaultLanguage() : mixed

getLanguageSwitcher()

public getLanguageSwitcher() : mixed

getLocalesBeforeSwitch()

List of locales before switching locale via `switchToLanguage`.

public getLocalesBeforeSwitch() : mixed

getOriginalPostId()

public getOriginalPostId(mixed $id, mixed $post_type) : mixed
Parameters
$id : mixed
$post_type : mixed

getOriginalTermId()

public getOriginalTermId(mixed $id, mixed $taxonomy) : mixed
Parameters
$id : mixed
$taxonomy : mixed

getOverrideClassInstance()

Get an instance of the `overrideClass`.

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

getPostTranslationIds()

public getPostTranslationIds(mixed $id, mixed $post_type) : mixed
Parameters
$id : mixed
$post_type : mixed

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 abstract getSkipHTMLForTag([bool $force = false ]) : string
Parameters
$force : bool = false

Pass true to get the attribute and do not respect isCurrentlyInEditorPreview

Return values
string

getSync()

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

public getSync() : mixed

getTaxonomyTranslationIds()

public getTaxonomyTranslationIds(mixed $id, mixed $taxonomy) : mixed
Parameters
$id : mixed
$taxonomy : mixed

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

getWordPressCompatibleLanguageCode()

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

isCurrentlyInEditorPreview()

Check if the translate plugin is currently in edit mode (preview).

public abstract isCurrentlyInEditorPreview() : bool
Return values
bool

isPresent()

Check if PolyLang is active.

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 abstract maybePersistTranslation(string $sourceContent, string $content, string $sourceLocale, string $targetLocale) : mixed
Parameters
$sourceContent : string
$content : string
$sourceLocale : string
$targetLocale : string

postCopiedToAllOtherLanguages()

This method is called due to `Sync::save_post`. It allows you to get a list of all translations of a post in an associate array.

public postCopiedToAllOtherLanguages(mixed $translations) : mixed
Parameters
$translations : mixed

setPostLanguage()

This method is called due to `Sync::save_post`. It allows you to assign a post to a given language.

public setPostLanguage(mixed $postId, mixed $locale) : mixed
Parameters
$postId : mixed
$locale : mixed

setTermLanguage()

This method is called due to `Sync::created_term`. It allows you to assign a term to a given language.

public setTermLanguage(mixed $termId, mixed $locale) : mixed
Parameters
$termId : mixed
$locale : mixed

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

termCopiedToAllOtherLanguages()

This method is called due to `Sync::created_term`. It allows you to get a list of all translations of a term in an associate array.

public termCopiedToAllOtherLanguages(mixed $translations) : mixed
Parameters
$translations : 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()

Translate a given input from known translations (.po, .pot).

public translateInput(string $input[, array<string|int, string> $contexts = null ]) : mixed
Parameters
$input : string
$contexts : array<string|int, string> = null

translateStrings()

Translate strings to a given locale. Do not use this function directly, use `translateArray` instead!

public abstract translateStrings(array<string|int, string> &$content, string $locale[, array<string|int, string> $context = null ]) : mixed
Parameters
$content : array<string|int, string>

This parameter needs to be passed as reference map, see also translateArray. The implementation needs to update the references correctly

$locale : string
$context : array<string|int, string> = null

unsetCurrentTranslations()

Unset current translations.

public unsetCurrentTranslations() : mixed

duplicateMeta()

Listen to meta (term, post, ...) addition and copy.

protected duplicateMeta(string $type, int $from, int $to, array<string|int, string> $meta) : mixed
Parameters
$type : string

E. g. 'post'

$from : int
$to : int
$meta : array<string|int, string>

Meta keys to copy

duplicatePost()

A simple `get_post` => `wp_insert_post` wrapper.

protected duplicatePost(WP_Post $post) : mixed
Parameters
$post : WP_Post

duplicateTerm()

A simple `get_term` => `wp_insert_term` wrapper.

protected duplicateTerm(WP_Term $term, string $taxonomy) : mixed
Parameters
$term : WP_Term
$taxonomy : string

duplicateTermMeta()

Listen to term meta addition and copy.

protected duplicateTermMeta(int $from, int $to, array<string|int, string> $meta) : mixed
Parameters
$from : int
$to : int
$meta : array<string|int, string>

Meta keys to copy

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]


        
On this page

Search results