MediaWiki fundraising/REL1_35
MessageUtils.php
Go to the documentation of this file.
1<?php
2
7
19 public static function languageSpecificFallback(
20 $language = 'en', $msg_keys = [], $params = []
21 ) {
22 if ( count( $msg_keys ) < 1 ) {
23 throw new InvalidArgumentException( __FUNCTION__ . " BAD PROGRAMMER. No message keys given." );
24 }
25
26 # look for the first message that exists
27 foreach ( $msg_keys as $m ) {
28 if ( WmfFramework::messageExists( $m, $language ) ) {
29 return WmfFramework::formatMessage( $m, $params );
30 }
31 }
32
33 # we found nothing in the requested language, return the first fallback message that exists
34 foreach ( $msg_keys as $m ) {
35 if ( WmfFramework::messageExists( $m, $language ) ) {
36 return WmfFramework::formatMessage( $m, $params );
37 }
38 }
39
40 # somehow we still don't have a message, return a default error message
41 return WmfFramework::formatMessage( $msg_keys[0], $params );
42 }
43
53 public static function getCountrySpecificMessage( $key, $country, $language, $params = [] ) {
55 $language, [ $key . '-' . strtolower( $country ), $key ], $params
56 );
57 }
58
67 public static function makeSafe( $string ) {
68 $stripped = preg_replace( '/[^-_\w]/', '', $string );
69
70 // theoretically this is overkill, but better safe than sorry
71 return WmfFramework::sanitize( htmlspecialchars( $stripped ) );
72 }
73}
Convenience methods for translating and localizing interface messages.
static languageSpecificFallback( $language='en', $msg_keys=[], $params=[])
languageSpecificFallback - returns the text of the first existing message in the requested language.
static makeSafe( $string)
This function limits the possible characters passed as template keys and values to letters,...
static getCountrySpecificMessage( $key, $country, $language, $params=[])
Retrieves and translates a country-specific message, or the default if no country-specific version ex...