Skip to content
Advanced pluralization for Kirby.
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
vendor
.gitignore
LICENSE
README.md
composer.json
composer.lock
global.php
index.php

README.md

kirby-plurals

Allows you to use language variables to translate a string according to that language's plural forms defined in the Unicode CLDR. For more information, check php-pluralization which is a dependency of this plugin.

Installation

With Composer:

composer require oblik/kirby-plurals

Usage

You get a tp() (translate plural) helper function that works similar to other helper functions and especially, tc().

Here's an example language file en.php:

return [
    'code' => 'en',
    'default' => true,
    'name' => 'English',
    'translations' => [
        'apples' => [
            'one' => '{{ count }} apple',
            'other' => '{{ count }} apples'
        ],
        'place' => [
            'one' => '{{ position }}st',
            'two' => '{{ position }}nd',
            'few' => '{{ position }}rd',
            'other' => '{{ position }}th'
        ],
        'cookies' => [
            'other' => '{{ start }}-{{ end }} cookies'
        ]
    ]
];

You can translate:

  • cardinals, by using a count key
  • ordinals, by using a position key
  • ranges, by using a start and an end key
tp('apples', [ 'count' => 1 ]);                 // 1 apple
tp('apples', [ 'count' => 3 ]);                 // 3 apples
tp('place', [ 'position' => 1 ]);               // 1st
tp('place', [ 'position' => 103 ]);             // 103rd
tp('cookies', [ 'start' => 3, 'end' => 4 ]);    // 3-4 cookies
You can’t perform that action at this time.