Documentation

TemporaryTextDomain
in package

Allows to set a given text domain to be translated from a .mo file.

Table of Contents

Properties

$currentlyActiveLocale  : mixed
List of currently active temporary text domains per domain.
$domain  : mixed
$fallbackDomain  : mixed
$isLocalePotFile  : mixed
$languageFile  : mixed
$locale  : mixed
$pomo  : MO|PO
PO/MO instance. Can be null if the given language file is not found.
$pomoInstances  : array<string|int, MO|PO>
Mo-file to MO instances for caching purposes to avoid a lot of `import_from_file` calls as they are not very performant.
$previousActiveLocale  : TemporaryTextDomain
Previous active temporary text domain.

Methods

__construct()  : mixed
C'tor.
fromPluginReceiver()  : mixed
Create a temporary text domain from a given WP React Starter plugin receiver.
getEntries()  : mixed
Get all translation entries of the given MO file.
getLocale()  : mixed
Getter.
gettext()  : mixed
Gettext filter.
gettext_with_context()  : mixed
Gettext with context filter.
isCurrentlyActive()  : mixed
Checks if this temporary text domain is the latest registered one in stack?
isLocalePotFile()  : mixed
Getter.
teardown()  : mixed
Teardown the `gettext` filter.
translate()  : mixed
Run translation calls inside a temporary domain remap.
createPomo()  : mixed
Create a PO or MO instance with memory caching enabled.
fromLanguageFiles()  : mixed
Create PO/MO instance from language file(s).
hooks()  : mixed
Create `gettext` hooks.

Properties

$currentlyActiveLocale

List of currently active temporary text domains per domain.

private static mixed $currentlyActiveLocale = []

$pomo

PO/MO instance. Can be null if the given language file is not found.

private MO|PO $pomo = null

$pomoInstances

Mo-file to MO instances for caching purposes to avoid a lot of `import_from_file` calls as they are not very performant.

private static array<string|int, MO|PO> $pomoInstances = []

Methods

__construct()

C'tor.

public __construct(string $domain, string $fallbackDomain, string|array<string|int, string> $languageFile, string $locale[, bool $isLocalePotFile = false ]) : mixed
Parameters
$domain : string
$fallbackDomain : string
$languageFile : string|array<string|int, string>

Can be a .po, .pot or .mo file. When passed as array, the translation entries are merged from right to left.

$locale : string
$isLocalePotFile : bool = false

Is the $locale the language of the POT file?

Tags
codeCoverageIgnore

fromPluginReceiver()

Create a temporary text domain from a given WP React Starter plugin receiver.

public static fromPluginReceiver(string $domain, string $fallbackDomain, PluginReceiver $receiver, AbstractSyncPlugin|string $compLanguageOrLocale[, string $overrideClass = null ]) : mixed
Parameters
$domain : string
$fallbackDomain : string
$receiver : PluginReceiver
$compLanguageOrLocale : AbstractSyncPlugin|string
$overrideClass : string = null

A class with a getPotLanguages method

getEntries()

Get all translation entries of the given MO file.

public getEntries() : mixed

gettext()

Gettext filter.

public gettext(string $translation, string $text, string $domain) : mixed
Parameters
$translation : string

Translated text.

$text : string

Text to translate.

$domain : string

Text domain. Unique identifier for retrieving translated strings.

gettext_with_context()

Gettext with context filter.

public gettext_with_context(string $translation, string $text, string $context, string $domain) : mixed
Parameters
$translation : string

Translated text.

$text : string

Text to translate.

$context : string

Text context.

$domain : string

Text domain. Unique identifier for retrieving translated strings.

isCurrentlyActive()

Checks if this temporary text domain is the latest registered one in stack?

public isCurrentlyActive() : mixed

translate()

Run translation calls inside a temporary domain remap.

public translate(callable $callback) : mixed

Within this callback you can keep using __(), _x() and related functions with the fallback text domain (e.g. the plugin text domain). While this method runs, these calls are redirected to the temporary text domain so translated defaults can still be loaded from the temporary MO/PO data. The remap is limited to this callback and is always cleaned up, even if an exception occurs.

Parameters
$callback : callable
Tags
see
https://developer.wordpress.org/reference/hooks/gettext/

fromLanguageFiles()

Create PO/MO instance from language file(s).

protected fromLanguageFiles(string|array<string|int, string> $languageFile) : mixed
Parameters
$languageFile : string|array<string|int, string>

Can be a .po, .pot or .mo file. When passed as array, the translation entries are merged from right to left.


        
On this page

Search results