Base class for language variant conversion.
More...
|
| __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 | 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.
|
|
Base class for language variant conversion.
◆ __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 | $langCode | The main language code of this language |
string[] | $variants | The supported variants of this language |
?array | $variantfallbacks | The fallback language of each variant |
?array | $flags | Defining the custom strings that maps to the flags |
?array | $manualLevel | Limit for supported variants |
◆ 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 | $rootNode | The root node of a fragment to convert. |
string | Bcp47Code | $htmlVariantLanguage | The 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 | $wtVariantLanguage | An 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 | $fallback | Whether 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 |
( |
| ) |
|
◆ guessVariant()
Wikimedia\Parsoid\Language\LanguageConverter::guessVariant |
( |
| $text, |
|
|
| $variant ) |
◆ loadLanguage()
static Wikimedia\Parsoid\Language\LanguageConverter::loadLanguage |
( |
Env | $env, |
|
|
Bcp47Code | $lang, |
|
|
bool | $fallback = false ) |
|
static |
- Parameters
-
Env | $env | |
Bcp47Code | $lang | a 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 | $doc | The input document. |
?Bcp47Code | $htmlVariantLanguage | The desired output variant. |
?Bcp47Code | $wtVariantLanguage | The 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:
- src/Language/LanguageConverter.php