let rule: GrammaticalNumberRule = .uncountable("money")
money will never change.
Irregular Rule: Singular from plural
let rule: GrammaticalNumberRule = .irregular("tooth", "teeth")
Turns tooth to teeth when used with pluralized().
Turns teeth to tooth when used with singularized().
Plural Rule: Plural from singular with regular expression
let rule: GrammaticalNumberRule = .plural(#"^(m|l)ousequot;#, #"$1ice"#)
mouse becomes mice and louse becomes lice.
Singular Rule: Singular from plural with regular expression
let rule: GrammaticalNumberRule = .singular(#"(matr)icesquot;#, #"$1ix"#)
Turns matrices to matrix.
Apply rule, so it becomes available
GrammaticalNumberRule.add(rule)
Support other languages
In order to support other languages, pass the language parameter to your custom rules.
Call .pluralized(language: yourLanguage) with the same language value — like so: .pluralized(language: "tr")
BinaryKit — BinaryKit helps you to break down binary data into bits and bytes and easily access specific parts.
Clippy — Clippy from Microsoft Office is back and runs on macOS! Written in Swift.
HackMan — Stop writing boilerplate code yourself. Let hackman do it for you via the command line.
ISO8859 — Convert ISO8859 1-16 Encoded Text to String in Swift. Supports iOS, tvOS, watchOS and macOS.
SpriteMap — SpriteMap helps you to extract sprites out of a sprite map. Written in Swift.
StringCase — Converts String to lowerCamelCase, UpperCamelCase and snake_case. Tested and written in Swift.
TinyConsole — TinyConsole is a micro-console that can help you log and display information inside an iOS application, where having a connection to a development computer is not possible.
License
GrammaticalNumber is released under the MIT License.
GrammaticalNumber
Turning singular words to plural can be very hard in some spoken languages, while other languages have simple rules.
GrammaticalNumberis heavily inspired byActiveSupport::Inflectorknown from the Ruby on Rails web framework.Usage
Turn singular words to plural
Turn plural words to singular
Case Sensitivity
GrammaticalNumberwill try to match the letter casing of your input word. Lowercased, uppercased and capitalized words are supported.Add count to words
Prepends the pluralized
Stringwithcount. If thecountis0, the singular word will be used.Define Custom Rules
Uncountable Rule
moneywill never change.Irregular Rule: Singular from plural
Turns
toothtoteethwhen used withpluralized(). Turnsteethtotoothwhen used withsingularized().Plural Rule: Plural from singular with regular expression
mousebecomesmiceandlousebecomeslice.Singular Rule: Singular from plural with regular expression
Turns
matricestomatrix.Apply rule, so it becomes available
Support other languages
In order to support other languages, pass the
languageparameter to your custom rules. Call.pluralized(language: yourLanguage)with the samelanguagevalue — like so:.pluralized(language: "tr")Example for the turkish language (
tr)Contact
Other Projects
License
GrammaticalNumber is released under the MIT License.