Leximorph
Appearance
| This page is under construction Please help review and edit this page. |
Leximorph provides handlers for internationalization (i18n) text transformations, including pluralization, grammatical inflection, gender and formality selection, and bidirectional isolation, using language data.
Usage
[edit]use Wikimedia\Leximorph\Manager;
// Create a manager for your language
$manager = new Manager( 'de' );
// Pluralization
$plural = $manager->getPlural();
echo $plural->process( 3, [ 'Artikel', 'Artikel' ] );
// Grammar transformation (e.g., Russian genitive)
$grammar = ( new Manager( 'ru' ) )->getGrammar();
echo $grammar->process( 'Википедия', 'genitive' );
// Gender-based selection
$gender = $manager->getGender();
echo $gender->process( 'female', [ 'er', 'sie', 'sie' ] );
// Formal vs. informal
$formal = $manager->getFormal();
echo $formal->process( [ 'Du hast', 'Sie haben' ] );
// Bidi-safe wrapping
$bidi = ( new Manager( 'ar' ) )->getBidi();
echo $bidi->process( 'مرحبا بالعالم' );