Language Converter
Finite-State Transducer implementation of MediaWiki LanguageConverter
Loading...
Searching...
No Matches
Wikimedia\LangConv\ReplacementMachine Class Reference

A machine to convert and/or replace text. More...

+ Inheritance diagram for Wikimedia\LangConv\ReplacementMachine:

Public Member Functions

 __construct ()
 ReplacementMachine constructor.
 
 getCodes ()
 Return the set of language codes supported.
 
 isValidCodePair ( $destCode, $invertCode)
 Override this method in subclass if you want to limit the possible code pairs bracketed.
 
 replace ( $textNode, $destCode, $invertCode)
 Replace the given text Node with converted text, protecting any markup which can't be round-tripped back to invertCode with appropriate synthetic language-converter markup.
 
 convert ( $document, $s, $destCode, $invertCode)
 Convert a string of text.
 
 jsonEncode (array $obj)
 Allow client to customize the JSON encoding of data-mw-variant attributes.
 

Detailed Description

A machine to convert and/or replace text.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\LangConv\ReplacementMachine::__construct ( )

ReplacementMachine constructor.

Reimplemented in Wikimedia\LangConv\ZhReplacementMachine.

Member Function Documentation

◆ convert()

Wikimedia\LangConv\ReplacementMachine::convert ( $document,
$s,
$destCode,
$invertCode )
abstract

Convert a string of text.

Parameters
DOMDocument$document
string$stext to convert
string$destCodedestination language code
string$invertCode
Returns
DOMDocumentFragment DocumentFragment containing converted text

Reimplemented in Wikimedia\LangConv\FstReplacementMachine, and Wikimedia\LangConv\NullReplacementMachine.

◆ getCodes()

Wikimedia\LangConv\ReplacementMachine::getCodes ( )
abstract

Return the set of language codes supported.

Both key and value are set in order to facilitate inclusion testing.

Returns
array<string,string>

Reimplemented in Wikimedia\LangConv\FstReplacementMachine, and Wikimedia\LangConv\NullReplacementMachine.

◆ isValidCodePair()

Wikimedia\LangConv\ReplacementMachine::isValidCodePair ( $destCode,
$invertCode )

Override this method in subclass if you want to limit the possible code pairs bracketed.

(For example, zh has a large number of variants, but we typically want to use only a limited number of these as possible invert codes.)

Parameters
string$destCode
string$invertCode
Returns
bool whether this is a valid bracketing pair.

Reimplemented in Wikimedia\LangConv\NullReplacementMachine, and Wikimedia\LangConv\ZhReplacementMachine.

◆ jsonEncode()

Wikimedia\LangConv\ReplacementMachine::jsonEncode ( array $obj)

Allow client to customize the JSON encoding of data-mw-variant attributes.

Parameters
array$objThe structured attribute value to encode
Returns
string The encoded attribute value

◆ replace()

Wikimedia\LangConv\ReplacementMachine::replace ( $textNode,
$destCode,
$invertCode )

Replace the given text Node with converted text, protecting any markup which can't be round-tripped back to invertCode with appropriate synthetic language-converter markup.

Parameters
DOMNode$textNode
string$destCode
string$invertCode
Returns
DOMNode

The documentation for this class was generated from the following file: