MediaWiki  REL1_31
LanguageEn.php
Go to the documentation of this file.
1 <?php
30  function loadDefaultTables() {
31  $this->mTables = [
32  'en' => new ReplacementArray(),
33  'en-x-piglatin' => new ReplacementArray(),
34  ];
35  }
36 
45  function translate( $text, $toVariant ) {
46  if ( $toVariant === 'en-x-piglatin' ) {
47  // Only process words composed of standard English alphabet, leave the rest unchanged.
48  // This skips some English words like 'naïve' or 'résumé', but we can live with that.
49  // Ignore single letters and words which aren't lowercase or uppercase-first.
50  return preg_replace_callback( '/[A-Za-z][a-z\']+/', function ( $matches ) {
51  $word = $matches[0];
52  if ( preg_match( '/^[aeiou]/i', $word ) ) {
53  return $word . 'way';
54  } else {
55  return preg_replace_callback( '/^(s?qu|[^aeiou][^aeiouy]*)(.*)$/i', function ( $m ) {
56  $ucfirst = strtoupper( $m[1][0] ) === $m[1][0];
57  if ( $ucfirst ) {
58  return ucfirst( $m[2] ) . lcfirst( $m[1] ) . 'ay';
59  } else {
60  return $m[2] . $m[1] . 'ay';
61  }
62  }, $word );
63  }
64  }, $text );
65  } else {
66  return $text;
67  }
68  }
69 }
70 
76 class LanguageEn extends Language {
77  function __construct() {
79 
80  parent::__construct();
81 
82  if ( $wgUsePigLatinVariant ) {
83  $this->mConverter = new EnConverter( $this, 'en', [ 'en', 'en-x-piglatin' ] );
84  $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
85  }
86  }
87 }
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:37
$matches
$matches
Definition: NoLocalSettings.php:24
EnConverter\translate
translate( $text, $toVariant)
Translates text into Pig Latin.
Definition: LanguageEn.php:45
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:95
$wgHooks
$wgHooks['ArticleShow'][]
Definition: hooks.txt:108
EnConverter
Definition: LanguageEn.php:26
ReplacementArray
Wrapper around strtr() that holds replacements.
Definition: ReplacementArray.php:24
LanguageEn\__construct
__construct()
Definition: LanguageEn.php:77
LanguageEn
English.
Definition: LanguageEn.php:76
EnConverter\loadDefaultTables
loadDefaultTables()
Dummy methods required by base class.
Definition: LanguageEn.php:30
LanguageConverter
Base class for language conversion.
Definition: LanguageConverter.php:34
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:3074