NumeralEndings 0.1.4

NumeralEndings 0.1.4

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jun 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Andrey Volobuev.



NumeralEndings

A tiny library helping to correctly modify Russian words depending on the count.

Features

Library extends integer type to return a correct form of a word. Russian words a spelled diffently in this cases:

  • Quantity ends in 1 - As per position in the sentence.
  • Quantity ends in 2,3,4 - Genitive Singular.
  • Quantity ends in 5,6,7,8,9,0,11,12 etc. - Genitive Plural

Pros

  • Very flexible
  • Small
  • 100% unit tested

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

NumeralEndings is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "NumeralEndings"

Examples

let count: Int

let counted = count.toNumeralEndingString(commonPart: "организаци", oneOf:"я", twoOf: "ии", fiveOf: "ий")
"В нашем каталоге \(count) \(counted)"
// "В нашем каталоге 1 орагнизация"
// "В нашем каталоге 2 орагнизации"
// "В нашем каталоге 100 орагнизаций"

let counted = count.toNumeralEndingString(commonPart: "час", twoOf: "а", fiveOf: "ов")
"Длительность \(count) \(counted)"
// "Длительность 1 час"
// "Длительность 2 часа"
// "Длительность 5 часов"

let counted = count.toNumeralEndingString(oneOf: "день", twoOf: "дня", fiveOf: "дней")
"До конца отпуска \(count) \(counted)"
// До конца отпуска 1 день
// До конца отпуска 2 дня
// До конца отпуска 36 дней

let counted = count.toNumeralEndingString(oneOf: "год", twoOf: "года", fiveOf: "лет")
"До сингулярности \(count) \(counted)"
// До сингулярности 1 год
// До сингулярности 2 года
// До сингулярности 36 лет

let counted = count.toNumeralEndingString(format: "1год 2года 5лет")
"До сингулярности \(count) \(counted)"
// До сингулярности 1 год
// До сингулярности 2 года
// До сингулярности 36 лет

let counted = count.toNumeralEndingString(format: "яблок 1о 2а")
"У вас \(count) \(counted)"
// У вас 1 яблоко
// У вас 2 яблока
// У вас 36 яблок

Authors

Anton Lagutin, Andrey Volobyev [email protected]

License

NumeralEndings is available under the MIT license. See the LICENSE file for more info.