Support of plural forms for cardinal and ordinal numerals

1C Developer team

28.08.2018 10 min

We have added support for strings that require harmonization with numerals to the platform. Now you can generate strings of the “run time 1 second” and “run time 32 seconds” type automatically, without analyzing the numeral in order to use the correct unit of measurement form.

To this end, we added a new StringWithNumber() method to the platform. Its working principle is based on the fact that any numeral in any language can be classified into one of the six categories:
  • ZERO
  • ONE
  • TWO
  • FEW
  • MANY
  • OTHER
In different languages, the same numerals may refer to different categories. Besides, not all languages have all six categories. For example, in the German language, categories ZERO, TWO, FEW, and MANY are not used. The detailed table of conformity of categories with numerals for all languages can be viewed on unicode.org.

The StringWithNumber() method works as follows. You need to pass there string fragments for those categories that are present in the selected language. You must also pass the numeral itself. As a result, the method, depending on the numeral and language, selects one of the string fragments by placing the numeral in there and then returns it to you.

For example, in the English language, you need to automatically display the following: “So many days left until New Year's Day”. Then, using this method might look like this:
For Counter = 1 To 7 Do
 
    String = StringWithNumber("; %1 day; ; ; ; %1 days",
               8 - Counter,
               NumberValueType.Cardinal);
 
    Message = New UserMessage;
    Message.Text = String + " left until New Year's Day";
    Message.Message();
 
EndDo;
As a result, you get the following sequence of strings:

ce2563f8f41cff46eae813be86b9f4c7.png

Or another example. In English, you must display the following: “January this datethe day of the year”. Then the code will look like this:
For Counter = 1 To 7 Do

    String = StringWithNumber( "; %1st; %1nd; %1rd; ; %1th",
               Counter,
               NumberValueType.Ordinal);
 
    Message = New UserMessage;
    Message.Text = "January " + Counter + ", the " + String + " day of the year";
    Message.Message();
 
EndDo;
As a result, you get the following sequence of strings:

5707c34d38f100e9758a12084122872c.png

Note that these examples illustrate different types of numerals. The first example uses cardinal numerals, while the second - ordinal ones. Cardinal numbers answer the question "How many?" Ordinal numbers answer the question "Which one?"

The spelling of cardinal and ordinal numerals varies, therefore, you need to use different calls of the StringWithNumber() method. For example, in the Russian language, a noun that refers to cardinal numerals is declined according to cases and numbers (1 день, 2 дня, 5 дней), and ordinal numerals are used in the singular form (1-й день, 2-й день, 3-й день, 4-й день). In English, a noun that refers to cardinal numerals is declined only according to numbers (1 day, 2 days), and there are four different forms for ordinal numerals: 1st day, 2nd day, 3rd day, 4th day.

To help you use the new method, we specified in the Syntax Assistant the strings that you must use for each language and for each numeral type (cardinal or ordinal).

cf28d5cc54537bdd599804618bf174e3.png

Thus, all you have to do is substitute correct measurement unit forms and use the characters "%1" to indicate, in which place of each fragment the numeral will be located.

We have already used the new string generation features in the platform interface. For example, the schedule of a scheduled job now includes the correct numeral form:

321783ec987592167c713d3c1f99383b.png

The string representation of the planner schedule now contains no spelling errors.

c2ddcddadf9c68630ce8f2f1f2efdb95.png

In conclusion, we would like to point out that the new StringWithNumber() method was implemented for 21 languages:
  • Azerbaijani
  • Belarusian
  • Bulgarian
  • Chinese
  • English
  • Estonian
  • Finnish
  • French
  • Georgian
  • German
  • Hungarian
  • Kazakh
  • Latvian
  • Lithuanian
  • Polish
  • Romanian
  • Russian
  • Turkish
  • Turkmen
  • Ukrainian
  • Vietnamese
Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.