S
S
Stacy None2018-02-19 11:47:04
JavaScript
Stacy None, 2018-02-19 11:47:04

How to make the spelling correct ending of the word?

For example, I have the text "3 screenshots"
How to make the ending of the word "Screenshot" change spelling correctly depending on the number?
For example "1 Screen Shot " / " 6 Screenshots " and so on.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey delphinpro, 2018-02-19
@Stacy11

Function for Russian language:

function pluralizeRus(n, forms) {
  return n % 10 == 1 && n % 100 != 11
        ? forms[0]
        : (n % 10 >= 2 && n % 10 <= 4
        && (n % 100 < 10
            || n % 100 >= 20) ? forms[1] : forms[2]);
}

alert('6 Скриншот' + pluralizeRus(6, ['', 'а', 'ов']));

For other languages, there are ready-made multiplicity tables; it is also easy to write the necessary function using them.

E
Eugene Chefranov, 2018-02-19
@Chefranov

This is called declination. Googled for "Declination in js"

M
Maxim Pak, 2020-08-25
@PML

Declension of endings in words in Javascript.
Here is a good article with examples: https://proweb63.ru/help/js/declension-in-js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question