New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

dn23rus/laravel-translation-rules

11
Install
composer require dn23rus/laravel-translation-rules
Latest Version:v1.0.0
Laravel:5
Last Updated:Sep 26, 2015
Links: GitHub  ·  Packagist
Maintainer: b.dmitry

Overview

This package gives ability to use translation rules.

Installation

composer require dn23rus/laravel-translation-rules

Configuration

Add service provider to config/app.php

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

Run the command:

php artisan vendor:publish

to publish translation_rules.php

Usage

Now you can add rule to resources/lang/translation_rules.php, for example rule for Russian language:

    '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);
    },

And example of message in file resource/lang/ru/app.php:

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

So

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

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

651,963,193 9,701
laravel/framework

The Laravel Framework.

604,216,237 34,982
laravel/tinker

Powerful REPL for the Laravel framework.

512,508,631 7,443
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

429,221,767 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

407,699,310 4,663

Version History

Version Released Laravel License
v1.0.0 5.*