dn23rus/laravel-translation-rules

本包的最新版本(v1.0.0)没有可用的许可信息。

v1.0.0 2015-09-26 17:07 UTC

This package is not auto-updated.

Last update: 2024-09-18 10:01:48 UTC


README

本包提供了使用翻译规则的能力。

安装

composer require dn23rus/laravel-translation-rules

配置

将服务提供者添加到 config/app.php

    'providers' => [
        //...
        Dmbur\TranslationRule\TranslationRuleServiceProvider::class
    ]

运行以下命令

php artisan vendor:publish

以发布 translation_rules.php

使用方法

现在您可以为 resources/lang/translation_rules.php 添加规则,例如俄语的规则

    'ru' => function ($n) {
        return ($n % 10 == 1 && $n % 100 != 11) ? 0 :
            ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
    },

文件 resource/lang/ru/app.php 中的消息示例

    'apple' => '{0}яблоко|{1}яблока|{2}яблок'

所以

echo 5 . ' ' . trans_rule('app.apple', 5) // will produce 5 яблок