U
U
Urukhayy2014-11-21 09:46:58
Programming
Urukhayy, 2014-11-21 09:46:58

Solution for declension of nouns after numerals?

What is the best solution for declension of nouns after numerals?
I mean a way, perhaps not the most optimal, but true. Its essence is simple: We send to the function a word in the singular and a number indicating the amount. In this function, we run swtich on the last letter, and in this switch there will be 33 cases (but if the letters have the same declension, then less), in which in turn there will be 3 more cases : on the number 1, the number 2, and the number 5.
" 1 Car", "2 Cars", "5 Cars"

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey Lerg, 2014-11-21
@Urukhayy

It is not so easy, one function is not enough, as there are many words in Russian that do not fall under the general rules.
We need a special database of words for the Russian language.
Therefore, they usually use functions that are passed words in all forms at once, and she chooses the right one according to the number.
habrahabr.ru/post/105428
www.unicode.org/cldr/charts/latest/supplemental/la...

A
anyd3v, 2014-11-21
@anyd3v

At least it can be found in libraries supporting this
https://github.com/yaroslav/russian/blob/master/li...

S
Sergey delphinpro, 2017-02-22
@sergemin

In any case, the server must have your form handler. Most often it is php, due to its wide distribution.
Form validation can (and should!) be done on the client. And just duplicate it on the server. For validation, the www.formvalidator.net
plugin is very good. Connect and configure the plugin. It will prevent you from submitting a form with errors. And when all the fields are filled in correctly, you can already send your form to the server with Ajax.
This way you can submit any form except enctype=multipart/formdata

$('[data-toggle="ajax"]').on('submit', function (e) {
        e.preventDefault();
        var $form    = $(this);
        var data     = $form.serialize();
        var action   = $form.attr('action');
        var method   = $form.attr('method');

        $.ajax({
            url     : action,
            type    : method,
            data    : data,
            dataType: 'html' // или 'json' смотря какой ответ будете возвращать
        }).then(function (data) {
            console.log('Форма отправлена', data);
        }).fail(function () {
            console.log('Ошибка отправки');
        });
    });

I explain.
We assign the data-toggle="ajax" attribute to the forms we want to submit with Ajax.
The handler where the form will be sent is taken from the action="" attribute of the form. The sending method (post/get) is also taken from the form. This gives some flexibility in how the code is used when the values ​​are not hardcore in the script. If the form has been sent, then in the then method we will get what the handler on the server will return to us. For more flexibility, it is preferable to use dataType: 'json'. Then you can send an object from the server with a detailed status of the response, such as the results of the validation of each field.
If the form is not sent, the fail() method will work. For example, the server returned a response not equal to 200 or data that does not match the requested type (you asked for json, but html came).
Sending files is a little more complicated, but you'll figure it out first.

A
Alexander, 2017-02-22
@zkelo

NodeJS?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question