1. Go to this page and download the library: Download matecat/icu-intl library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$pattern = new MessagePattern();
$pattern->parse("You have {count, plural, =0{no messages} one{# message} other{# messages}}.");
$pattern = MessagePattern::parse("{gender, select, female{{num, plural, one{She has one file} other{She has # files}}} male{{num, plural, one{He has one file} other{He has # files}}} other{{num, plural, one{They have one file} other{They have # files}}}}");
/*
0: MSG_START(0)@0
1: ARG_START(SELECT)@0="{"
2: ARG_NAME(0)@1="gender"
3: ARG_SELECTOR(0)@17="female"
4: MSG_START(1)@23="{"
5: ARG_START(PLURAL)@24="{"
...
42: ARG_LIMIT(SELECT)@219="}"
43: MSG_LIMIT(0)@220
*/
use Matecat\Locales\Languages;
// Get all supported languages
$languages = Languages::getInstance();
$allLanguages = $languages->getLanguages();
// Get a specific language by RFC3066 code
$english = $languages->getLanguage('en-US');
echo $english['name']; // "English US"
echo $english['localized']; // "English"
echo $english['direction']; // "ltr"
echo $english['plurals']; // 2
// Check if a language is RTL
$isRtl = $languages->isRTL('ar-SA'); // true
// Get the number of plural forms for a language
$pluralCount = Languages::getPluralsCount('ru-RU'); // 3
use Matecat\ICU\Plurals\PluralRules;
// Get the plural form index for a number in a specific language
$form = PluralRules::getCardinalFormIndex('en', 1); // 0 (singular)
$form = PluralRules::getCardinalFormIndex('en', 5); // 1 (plural)
$form = PluralRules::getCardinalFormIndex('ru', 1); // 0 (one)
$form = PluralRules::getCardinalFormIndex('ru', 2); // 1 (few)
$form = PluralRules::getCardinalFormIndex('ru', 5); // 2 (many)
// Get the CLDR plural category name for a number
$category = PluralRules::getCardinalCategoryName('en', 1); // "one"
$category = PluralRules::getCardinalCategoryName('en', 5); // "other"
$category = PluralRules::getCardinalCategoryName('ru', 1); // "one"
$category = PluralRules::getCardinalCategoryName('ru', 2); // "few"
$category = PluralRules::getCardinalCategoryName('ru', 5); // "many"
$category = PluralRules::getCardinalCategoryName('ar', 0); // "zero"
$category = PluralRules::getCardinalCategoryName('ar', 1); // "one"
$category = PluralRules::getCardinalCategoryName('ar', 2); // "two"
$category = PluralRules::getCardinalCategoryName('ar', 5); // "few"
$category = PluralRules::getCardinalCategoryName('ar', 11); // "many"
$category = PluralRules::getCardinalCategoryName('ar', 100); // "other"
// Get all available plural categories for a language
$categories = PluralRules::getCardinalCategories('en'); // ["one", "other"]
$categories = PluralRules::getCardinalCategories('ru'); // ["one", "few", "many"]
$categories = PluralRules::getCardinalCategories('ar'); // ["zero", "one", "two", "few", "many", "other"]
// Use category constants for comparison
if (PluralRules::getCardinalCategoryName('en', $count) === PluralRules::CATEGORY_ONE) {
echo "Singular form";
}
use Matecat\ICU\MessagePatternValidator;
use Matecat\ICU\Plurals\PluralComplianceException;
// Simplified API: just provide locale and pattern string
$validator = new MessagePatternValidator('en', '{count, plural, one{# item} other{# items}}');
$warning = $validator->validatePluralCompliance();
// Returns null when all categories are valid and complete
var_dump($warning); // null - 'one' and 'other' are valid for English
// Fluent API with setPatternString()
$warning = (new MessagePatternValidator('ru'))
->setPatternString('{count, plural, one{# item} other{# items}}')
->validatePluralCompliance();
// Returns a PluralComplianceWarning - Russian new MessagePatternValidator('en', '{count, plural, one{# item} other{# items}}');
$validator->isValidSyntax(); // true
$validator = new MessagePatternValidator('en', '{invalid');
$validator->isValidSyntax(); // false
$validator->getSyntaxException(); // "Unmatched '{' braces in message..."
use Matecat\ICU\MessagePattern;
use Matecat\ICU\MessagePatternValidator;
// Parse an ICU message first
$pattern = new MessagePattern();
$pattern->parse('{count, plural, one{# item} other{# items}}');
// Create validator using factory method
$validator = MessagePatternValidator::fromPattern('en', $pattern);
$warning = $validator->validatePluralCompliance();
// Validate same pattern against multiple locales (reuses the parsed pattern)
$enValidator = MessagePatternValidator::fromPattern('en', $pattern);
$ruValidator = MessagePatternValidator::fromPattern('ru', $pattern);
$arValidator = MessagePatternValidator::fromPattern('ar', $pattern);
$enValidator->validatePluralCompliance(); // null - English only needs 'one', 'other'
$ruValidator->validatePluralCompliance(); // warning - Russian needs 'one', 'few', 'many', 'other'
use Matecat\ICU\MessagePatternValidator;
// Access per-argument warnings
$validator = new MessagePatternValidator('ru', '{count, plural, one{# item} other{# items}}');
$warning = $validator->validatePluralCompliance();
foreach ($warning->getArgumentWarnings() as $argWarning) {
echo $argWarning->argumentName; // 'count'
echo $argWarning->getArgumentTypeLabel(); // 'plural' or 'selectordinal'
print_r($argWarning->expectedCategories); // ['one', 'few', 'many', 'other']
print_r($argWarning->missingCategories); // ['few', 'many']
print_r($argWarning->foundSelectors); // ['one', 'other']
echo $argWarning->getMessageAsString(); // Detailed message for this argument
}
use Matecat\Locales\LanguageDomains;
// Get all language domains
$domains = LanguageDomains::getInstance();
$allDomains = $domains->getDomains();
// Get a specific domain
$domain = $domains->getDomain('technical');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.