polyglot/plural-detector-registry-cardinal-cldr

PHP Polyglot CLDR 的基数类型复数检测注册表

v1.0.0 2023-09-08 19:43 UTC

This package is not auto-updated.

Last update: 2024-09-21 22:42:39 UTC


README

这是一个简单的 polyglot CLDR 复数检测注册表。

此复数检测注册表中包含具有 CLDR 规则 的复数检测器

安装

composer require polyglot/plural-detector-registry-cardinal-cldr:^1.0

使用

<?php

$registry = new \Polyglot\CldrCardinalPluralDetectorRegistry\CldrCardinalPluralDetectorRegistry();
$en = $registry->get('en_US'); // or $registry->get('en')
$en->getAllowedCategories(); // returns ["one", "other"]
$en->detect(1); // returns "one"
$en->detect(2); // returns "other"

$ar = $registry->get('ar');
$en->getAllowedCategories(); // returns ["zero", "one", "two", "few", "many", "other"]
$en->detect(0); // returns "zero"
$en->detect(1); // returns "one"
$en->detect(2); // returns "two"
$en->detect(rand(3, 10) + 100 * rand(0, 100)); // returns "few"
$en->detect(rand(11, 99) + 100 * rand(0, 100)); // returns "many"
$en->detect(rand(10, 99) / 10); // returns "other"

$registry->get('unknown'); // throws \Polyglot\Contract\PluralDetectorRegistry\Exception\LocaleNotSupported