MediaWiki master
|
Utility class for json localization needs in the REST API. More...
Public Member Functions | |
__construct (ResponseFactory $responseFactory) | |
getFormattedMessage ( $message) | |
Tries to return one formatted string for a message key or message value object. | |
localizeJson (array $json) | |
Recursively localizes name/value pairs, where the name begins with "x-i18-n-". | |
localizeValue (array $json, string $key) | |
Returns the localized value if possible, or the non-localized value if one is available, or null otherwise. | |
Utility class for json localization needs in the REST API.
Much of this involves replacing custom name/value pairs (herein referred to as i18n pairs) with translated standard name/value pairs (herein referred to as schema pairs). For example, OpenAPI specifications include a "description" field represented as a name/value pair, like: "description": "My description". We allow a "x-i18n-description" field, whose value is a MediaWiki message key, like: "x-i18n-description": "rest-my-description-message-key" Functions in this class will replace the "x-i18n-description" with a translated "description".
Definition at line 18 of file JsonLocalizer.php.
MediaWiki\Rest\JsonLocalizer::__construct | ( | ResponseFactory | $responseFactory | ) |
ResponseFactory | $responseFactory |
Definition at line 28 of file JsonLocalizer.php.
MediaWiki\Rest\JsonLocalizer::getFormattedMessage | ( | $message | ) |
Tries to return one formatted string for a message key or message value object.
string | MessageValue | $message | the message format, or a key representing it |
Definition at line 111 of file JsonLocalizer.php.
MediaWiki\Rest\JsonLocalizer::localizeJson | ( | array | $json | ) |
Recursively localizes name/value pairs, where the name begins with "x-i18-n-".
array | $json | the input json, as a PHP array |
Definition at line 41 of file JsonLocalizer.php.
MediaWiki\Rest\JsonLocalizer::localizeValue | ( | array | $json, |
string | $key ) |
Returns the localized value if possible, or the non-localized value if one is available, or null otherwise.
Translates only top-level keys. Useful when the value corresponding to the input key may be either a string to be used as-is or a MessageValue object to be localized.
array | $json | the input json, as a PHP array |
string | $key | key name of the field |
Definition at line 90 of file JsonLocalizer.php.