API / Minn\I18n / Gettext

Gettext final class

Minn\I18n\Gettext · public/minn/src/Minn/I18n/Gettext.php · 84 lines

Translation as plugins see it (__, _x, _n and the rest map here): the message looked up in its domain's loaded files (loading the domain just in time on first use, through the loader the runtime hands over), else the English, then the gettext filters a plugin may change it through. Engine code translates here rather than through the WordPress names; with no runtime (an engine CLI verb) there is nothing loaded, and the English stands.

Constants and properties

privatestatic ?Closure $loader

Public

staticloadWith(Closure $loader): void#

The runtime's just-in-time loader for a domain's files. @param Closure(string): mixed $loader

$loaderClosure(string): mixed
statictext(string $text, string $domain = 'default'): string#

A message (__).

staticinContext(string $text, string $context, string $domain = 'default'): string#

A message in a context (_x).

staticplural(string $single, string $plural, int $number, string $domain = 'default'): string#

The form a count takes (_n): the domain's own plural, else English's.

staticpluralInContext(string $single, string $plural, int $number, string $context, string $domain = 'default'): string#

The form a count takes in a context (_nx).

staticlookup(string $domain, string $key): ?string#

A domain's translation of a message key, or null (no runtime to have loaded one, no file, no entry).

staticpluralForm(string $single, string $plural, int $number, string $domain, ?string $context): string#

The plural form a count takes in a domain, or English's when no file has the message.

Internals 1

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatehooked(): bool#

Whether the hook API is loaded: without it (an engine CLI verb, a unit case) a message stands unfiltered.