This page is a translated version of the page Manual:LocalisationCache.php and the translation is 8% complete.

The LocalisationCache class handles caching of PHP source code messages (as mentioned above, only the MessageCache layer handles database-overridden messages). This class is not called directly; rather the MessageCache class calls Language::getMessage(), which then calls this class to get the message. This layer handles the following logic:

  • Lazily loading messages from the back-end cache
  • Re-caching messages
  • Resolving the language fallback sequence

JSON files

Before MediaWiki 1.23, a PHP associative array was used for storing the messages. A global configuration in $wgExtensionMessagesFiles contains the mapping extension name to the filename where messages can be found.

Since MediaWiki 1.23, use of this variable to define messages is discouraged; instead, store messages in JSON format and use $wgMessagesDirs . For setting other variables than $messages, $wgExtensionMessagesFiles should still be used.

$wgMessagesDirs is an associative array mapping extension name to the path of the directory where message files can be found. The message files are expected to be JSON files named for their language code, e.g. en.json, de.json, etc. Extensions with messages in multiple places may specify an array of message directories.

LocalisationCache reads the localization messages from the files as per the above configuration for recaching.

Resolving language fallbacks

How this class resolves language fallbacks is that when searching for a specific message key, it will look for the message in all the languages, and then cache the value as if it were from the original language. The reason behind this is that each language has its own back-end cache. For a fallback sequence, if a message doesn't exist, it would normally mean having to load and query each cache individually every time the message is accessed. To avoid this, the fallback chain is resolved once when the messages are re-cached from the original PHP files, and the final value is stored in the cache for the top-level language.

It uses the database l10n_cache table by default. Set $wgCacheDirectory in LocalSettings.php to a valid path to use a local caching instead.