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.
With Composer:
composer require oblik/kirby-plurals
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
countkey - ordinals, by using a
positionkey - ranges, by using a
startand anendkey
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 cookiesIf you're using different locale names, you can map them with the oblik.plurals.map config option. For example, if you have two languages en-us and en-gb, you need to map them both to the en pluralizator class since both of them have the same pluralization rules:
site/config/config.php
return [
'oblik.plurals.map' => [
'en-us' => 'en',
'en-gb' => 'en'
]
];Check the available pluralization classes here.