MediaWiki REL1_30
LanguageEn.php
Go to the documentation of this file.
1<?php
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
74class LanguageEn extends Language {
75 function __construct() {
77
78 parent::__construct();
79
81 $this->mConverter = new EnConverter( $this, 'en', [ 'en', 'en-x-piglatin' ] );
82 $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
83 }
84 }
85}
$wgUsePigLatinVariant
Whether to enable the pig latin variant of English (en-x-piglatin), used to ease variant development ...
translate( $text, $toVariant)
Translates text into Pig Latin.
loadDefaultTables()
Dummy methods required by base class.
Base class for language conversion.
English.
Internationalisation code.
Definition Language.php:35
LanguageConverter $mConverter
Definition Language.php:39
Wrapper around strtr() that holds replacements.
$wgHooks['ArticleShow'][]
Definition hooks.txt:108