Skip to content

OblikStudio/kirby-plurals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Locale Mapping

If 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.

About

Advanced pluralization for Kirby.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages