1
0
mirror of https://github.com/robonen/tools.git synced 2026-03-20 10:54:44 +00:00
Files
tools/plural/README.md
2022-08-13 23:59:23 +07:00

38 lines
946 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Функция изменения формы слов в зависимости от числительного
Часто встречается задача вывода правильного окончания слова с предшествующим ему числом.
Например:
- 1 депутат
- 24 депутат**а**
- 0, 5-9 или 10 депутат**ов**
## Примеры исользования
### Typescript
```typescript
import { plural } from 'plural';
const totalOrders = 2;
const words = ['заказ', 'заказа', 'заказов'];
const result = `${totalOrders} ${plural(totalOrders, words)}`;
console.log(result); // 2 заказа
```
### PHP
```php
include 'plural.php';
$totalOrders = 2;
$words = ['заказ', 'заказа', 'заказов'];
$result = "{$totalOrders} {plural($totalOrders, $words)}";
echo result; // 2 заказа
```