UNPKG

@plteam/chat-ui

Version:

CUI Kit is a free and open-source library for creating AI assistant chat interfaces, built with React, Material UI, and TypeScript

35 lines (34 loc) 1 kB
import { lng } from '../lng'; export const getDeclension = (int, nouns, insertNumFirst) => { const [one, two, five] = nouns; let n = Math.abs(int); n %= 100; let res; if (n >= 5 && n <= 20) { res = five; } n %= 10; if (!res && n === 1) { res = one; } if (!res && n >= 2 && n <= 4) { res = two; } if (!res) res = five; return insertNumFirst ? `${int} ${res}` : res; }; export const getLangDeclension = (int, langArray, replaceKey) => { return lng([ getDeclension(int, langArray[0]), getDeclension(int, langArray[1]) ], replaceKey ? { [replaceKey]: int, } : undefined); }; export const getDaysText = (daysCount) => { return lng([ getDeclension(daysCount, [`${daysCount} день`, `${daysCount} дня`, `${daysCount} дней`]), getDeclension(daysCount, [`${daysCount} day`, `${daysCount} days`, `${daysCount} days`]) ]); };