定制 polyglot/plural-detector-callable 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

polyglot/plural-detector-callable

最新稳定版本:v1.0.0

Composer 安装命令:

composer require polyglot/plural-detector-callable

包简介

PHP Polyglot callable plural detector

README 文档

README

A simple polyglot callable plural detector.

Install

composer require polyglot/plural-detector-callable:^1.0

Using

<?php

$callable = function (Number $number): string {
    $n = $number->number();
    if ($n == 0) {
        return PluralCategory::ZERO;
    }
    if ($n == 1) {
        return PluralCategory::ONE;
    }
    if ($n == 2) {
        return PluralCategory::TWO;
    }
    if ($n == 3) {
        return PluralCategory::FEW;
    }
    if ($n == 4) {
        return PluralCategory::MANY;
    }
    return PluralCategory::OTHER;
};
$allowedCategories = [];

$registry = new \Polyglot\CallablePluralDetector\CallablePluralDetector($callable);
$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 

统计信息

  • 总下载量: 14
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-08