Manual:Hooks/MessageCacheFetchOverrides

From Linux Web Expert

Revision as of 07:40, 18 March 2023 by imported>Mainframe98
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

MessageCacheFetchOverrides
<translate> Available from <tvar name=1><translate> version <tvar (Gerrit change 884416)</tvar></translate>
Allows changing message keys, to customize it before the translation is accessed
<translate> Define function:</translate>
public static function onMessageCacheFetchOverrides( array &$keys ) { ... }
<translate> Attach hook:</translate> <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
	"Hooks": {
		"MessageCacheFetchOverrides": "MediaWiki\\Extension\\MyExtension\\Hooks::onMessageCacheFetchOverrides"
	}
}
<translate> Called from:</translate> <translate> File(s):</translate> cache/MessageCache.php
<translate> Interface:</translate> MessageCacheFetchOverridesHook.php

<translate> For more information about attaching hooks, see <tvar name=1>Manual:Hooks </tvar>.</translate>
<translate> For examples of extensions using this hook, see <tvar name=cat>Category:MessageCacheFetchOverrides extensions</tvar>.</translate>


Details

Both the input and output keys must have an initial lowercase character. No spaces can be used in the keys; any spaces must be converted to underscores.

  • &$keys - Array of message keys mapped to their replacement.

Values may be either a string or a callable that returns a string. Callables are provided four arguments: the message key, an instance of MessageCache, a Language object and a boolean indicating if the value should be loaded from the database.

function ( string $key, MessageCache $cache, Language $language, bool $useDB ): string { ... }

To prevent ambiguity between message keys that can also be interpreted as a callable (strtotime, for example), all string values are interpreted as a message key. To use a callable defined as a string, use Closure::fromCallable.

See also