Parsoid
A bidirectional parser between wikitext and HTML5
Loading...
Searching...
No Matches
Wikimedia\Parsoid\Language\LanguageConverter Class Reference

Base class for language variant conversion. More...

+ Inheritance diagram for Wikimedia\Parsoid\Language\LanguageConverter:

Public Member Functions

 __construct (Language $language, string $langCode, array $variants, ?array $variantfallbacks=null, ?array $flags=null, ?array $manualLevel=null)
 
 loadDefaultTables ()
 
 getMachine ()
 Return the ReplacementMachine powering this conversion.
 
 setMachine (ReplacementMachine $machine)
 
 findVariantLink ( $link, $nt, $ignoreOtherCond)
 
 translate ( $fromVariant, $text, $toVariant)
 
 guessVariant ( $text, $variant)
 

Static Public Member Functions

static classFromCode (string $code, bool $fallback)
 Try to return a classname from a given code.
 
static loadLanguage (Env $env, Bcp47Code $lang, bool $fallback=false)
 
static maybeConvert (Env $env, Document $doc, ?Bcp47Code $htmlVariantLanguage, ?Bcp47Code $wtVariantLanguage)
 Convert the given document into $htmlVariantLanguage, if: 1) language converter is enabled on this wiki, and 2) the htmlVariantLanguage is specified, and it is a known variant (not a base language code)
 
static baseToVariant (Env $env, Node $rootNode, $htmlVariantLanguage, $wtVariantLanguage)
 Convert a text in the "base variant" to a specific variant, given by htmlVariantLanguage.
 
static implementsLanguageConversionBcp47 (Env $env, Bcp47Code $htmlVariantLanguage)
 Check if support for html variant conversion is implemented.
 
static autoConvertToAllVariants (Env $env, DOMDocument $doc, string $text)
 Convert a string in an unknown variant of the page language to all its possible variants.
 

Detailed Description

Base class for language variant conversion.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Parsoid\Language\LanguageConverter::__construct ( Language $language,
string $langCode,
array $variants,
?array $variantfallbacks = null,
?array $flags = null,
?array $manualLevel = null )
Parameters
Language$language
string$langCodeThe main language code of this language
string[]$variantsThe supported variants of this language
?array$variantfallbacksThe fallback language of each variant
?array$flagsDefining the custom strings that maps to the flags
?array$manualLevelLimit for supported variants

Member Function Documentation

◆ autoConvertToAllVariants()

static Wikimedia\Parsoid\Language\LanguageConverter::autoConvertToAllVariants ( Env $env,
DOMDocument $doc,
string $text )
static

Convert a string in an unknown variant of the page language to all its possible variants.

Parameters
Env$env
DOMDocument$doc
string$text
Returns
string[] map of converted variants keyed by variant language

◆ baseToVariant()

static Wikimedia\Parsoid\Language\LanguageConverter::baseToVariant ( Env $env,
Node $rootNode,
$htmlVariantLanguage,
$wtVariantLanguage )
static

Convert a text in the "base variant" to a specific variant, given by htmlVariantLanguage.

If wtVariantLanguage is given, assume that the input wikitext is in wtVariantLanguage to construct round-trip metadata, instead of using a heuristic to guess the best variant for each DOM subtree of wikitext.

Parameters
Env$env
Node$rootNodeThe root node of a fragment to convert.
string | Bcp47Code$htmlVariantLanguageThe variant to be used for the output DOM. This is a mediawiki-internal language code string (T320662, deprecated), or a BCP 47 language object (preferred).
string | Bcp47Code | null$wtVariantLanguageAn optional variant assumed for the input DOM in order to create roundtrip metadata. This is a mediawiki-internal language code (T320662, deprecated), or a BCP 47 language object (preferred), or null.

◆ classFromCode()

static Wikimedia\Parsoid\Language\LanguageConverter::classFromCode ( string $code,
bool $fallback )
static

Try to return a classname from a given code.

Parameters
string$code
bool$fallbackWhether we're going through language fallback
Returns
class-string Name of the language class (if one were to exist)

◆ getMachine()

Wikimedia\Parsoid\Language\LanguageConverter::getMachine ( )

Return the ReplacementMachine powering this conversion.

Returns
?ReplacementMachine

◆ guessVariant()

Wikimedia\Parsoid\Language\LanguageConverter::guessVariant ( $text,
$variant )
Parameters
string$text
Bcp47Code$varianta language code
Returns
bool
Deprecated
Appears to be unused

Reimplemented in Wikimedia\Parsoid\Language\SrConverter.

◆ loadLanguage()

static Wikimedia\Parsoid\Language\LanguageConverter::loadLanguage ( Env $env,
Bcp47Code $lang,
bool $fallback = false )
static
Parameters
Env$env
Bcp47Code$langa language code
bool$fallback
Returns
Language

◆ maybeConvert()

static Wikimedia\Parsoid\Language\LanguageConverter::maybeConvert ( Env $env,
Document $doc,
?Bcp47Code $htmlVariantLanguage,
?Bcp47Code $wtVariantLanguage )
static

Convert the given document into $htmlVariantLanguage, if: 1) language converter is enabled on this wiki, and 2) the htmlVariantLanguage is specified, and it is a known variant (not a base language code)

The $wtVariantLanguage, if provided is expected to be per-wiki or per-article metadata which specifies a standard "authoring variant" for this article or wiki. For example, all articles are authored in Cyrillic by convention. It should be left blank if there is no consistent convention on the wiki (as for zhwiki, for instance).

Parameters
Env$env
Document$docThe input document.
?Bcp47Code$htmlVariantLanguageThe desired output variant.
?Bcp47Code$wtVariantLanguageThe variant used by convention when authoring pages, if there is one; otherwise left null.

◆ translate()

Wikimedia\Parsoid\Language\LanguageConverter::translate ( $fromVariant,
$text,
$toVariant )
Parameters
string$fromVariant
string$text
string$toVariant@suppress PhanEmptyPublicMethod

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