MediaWiki  1.30.0
LanguageEn.php
Go to the documentation of this file.
1 <?php
24 class EnConverter extends LanguageConverter {
28  function loadDefaultTables() {
29  $this->mTables = [
30  'en' => new ReplacementArray(),
31  'en-x-piglatin' => new ReplacementArray(),
32  ];
33  }
34 
43  function translate( $text, $toVariant ) {
44  if ( $toVariant === 'en-x-piglatin' ) {
45  // Only process words composed of standard English alphabet, leave the rest unchanged.
46  // This skips some English words like 'naïve' or 'résumé', but we can live with that.
47  // Ignore single letters and words which aren't lowercase or uppercase-first.
48  return preg_replace_callback( '/[A-Za-z][a-z]+/', function ( $matches ) {
49  $word = $matches[0];
50  if ( preg_match( '/^[aeiou]/i', $word ) ) {
51  return $word . 'way';
52  } else {
53  return preg_replace_callback( '/^(qu|[^aeiou][^aeiouy]*)(.*)$/i', function ( $m ) {
54  $ucfirst = strtoupper( $m[1][0] ) === $m[1][0];
55  if ( $ucfirst ) {
56  return ucfirst( $m[2] ) . lcfirst( $m[1] ) . 'ay';
57  } else {
58  return $m[2] . $m[1] . 'ay';
59  }
60  }, $word );
61  }
62  }, $text );
63  } else {
64  return $text;
65  }
66  }
67 }
68 
74 class LanguageEn extends Language {
75  function __construct() {
77 
78  parent::__construct();
79 
80  if ( $wgUsePigLatinVariant ) {
81  $this->mConverter = new EnConverter( $this, 'en', [ 'en', 'en-x-piglatin' ] );
82  $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
83  }
84  }
85 }
Language\$mConverter
LanguageConverter $mConverter
Definition: Language.php:39
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$matches
$matches
Definition: NoLocalSettings.php:24
EnConverter\translate
translate( $text, $toVariant)
Translates text into Pig Latin.
Definition: LanguageEn.php:43
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
EnConverter
Definition: LanguageEn.php:24
ReplacementArray
Wrapper around strtr() that holds replacements.
Definition: ReplacementArray.php:24
LanguageEn\__construct
__construct()
Definition: LanguageEn.php:75
LanguageEn
English.
Definition: LanguageEn.php:74
$wgHooks
$wgHooks['ArticleShow'][]
Definition: hooks.txt:108
EnConverter\loadDefaultTables
loadDefaultTables()
Dummy methods required by base class.
Definition: LanguageEn.php:28
Language
Internationalisation code.
Definition: Language.php:35
$wgUsePigLatinVariant
$wgUsePigLatinVariant
Whether to enable the pig latin variant of English (en-x-piglatin), used to ease variant development ...
Definition: DefaultSettings.php:3048