-
-
Save abesmon/596e68506ccb18c88288091cc8f8dd97 to your computer and use it in GitHub Desktop.
Swift Russian Plural Form Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Orig created by youmee https://gist.github.com/youmee/bc23dd6088e59609609f | |
// Modified by Лысенко Алексей Димитриевич on 09/09/2019. | |
// Copyright © 2019 SMG All rights reserved. | |
// | |
import Foundation | |
@objc class Pluralizer: NSObject { | |
@objc class PluralForms: NSObject { | |
let one: String | |
let two: String | |
let many: String | |
@objc init(_ one: String, _ two: String, _ many: String) { | |
self.one = one | |
self.two = two | |
self.many = many | |
} | |
} | |
/* | |
pluralForm(28, forms: .init("год", "года", "лет")) | |
output: "лет" | |
*/ | |
@objc static func pluralForm(number: Int, forms: PluralForms) -> String { | |
return number % 10 == 1 && number % 100 != 11 ? forms.one : | |
(number % 10 >= 2 && number % 10 <= 4 && (number % 100 < 10 || number % 100 >= 20) ? forms.two : forms.many) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment