|
MediaWiki master
|
Utility class for json localization needs in the REST API. More...
Public Member Functions | |
| __construct (ITextFormatter $formatter) | |
| getFormattedMessage ( $message) | |
| Tries to return one formatted string for a message key or message value object. | |
| getLangCode () | |
| Returns the language this localizer produces. | |
| 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 20 of file JsonLocalizer.php.
| MediaWiki\Rest\JsonLocalizer::__construct | ( | ITextFormatter | $formatter | ) |
| ITextFormatter | $formatter |
Definition at line 30 of file JsonLocalizer.php.
| MediaWiki\Rest\JsonLocalizer::getFormattedMessage | ( | $message | ) |
Tries to return one formatted string for a message key or message value object.
| string | MessageSpecifier | $message | the message format, or a key representing it. Prior to MediaWiki 1.47 the type was string|MessageValue. |
Definition at line 117 of file JsonLocalizer.php.
| MediaWiki\Rest\JsonLocalizer::getLangCode | ( | ) |
Returns the language this localizer produces.
Definition at line 130 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 43 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 MessageSpecifier object to be localized.
Prior to MediaWiki 1.47, only MessageValue objects were localized, other implementations of MessageSpecifier were not supported.
| array | $json | the input json, as a PHP array |
| string | $key | key name of the field |
Definition at line 95 of file JsonLocalizer.php.