plurals.go 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  1. package ut
  2. import "math"
  3. // PluralRule denotes the type of plural rules
  4. type PluralRule int
  5. // TODO: change this to integer for efficiency and use stringify lib to generate string values.
  6. const (
  7. PluralRuleZero PluralRule = iota // zero
  8. PluralRuleOne // one - singular
  9. PluralRuleTwo // two - dual
  10. PluralRuleFew // few - paucal
  11. PluralRuleMany // many - also used for fractions if they have a separate class
  12. PluralRuleOther // other - required—general plural form—also used if the language only has a single form
  13. )
  14. func (p PluralRule) String() string {
  15. switch p {
  16. case PluralRuleZero:
  17. return "PluralRuleZero"
  18. case PluralRuleOne:
  19. return "PluralRuleOne"
  20. case PluralRuleTwo:
  21. return "PluralRuleTwo"
  22. case PluralRuleFew:
  23. return "PluralRuleFew"
  24. case PluralRuleMany:
  25. return "PluralRuleMany"
  26. case PluralRuleOther:
  27. return "PluralRuleOther"
  28. default:
  29. return "Unknown PluralRule"
  30. }
  31. }
  32. // NumberValue should be one of these types:
  33. // int, float
  34. type NumberValue interface{}
  35. // PluralRuler allows the plural rule to be found
  36. type PluralRuler interface {
  37. FindRule(n NumberValue) PluralRule
  38. }
  39. var pluralRules = map[string]PluralRuler{
  40. "1": PluralRulerFunc(pluralRule1),
  41. "2A": PluralRulerFunc(pluralRule2A),
  42. "2B": PluralRulerFunc(pluralRule2B),
  43. "2C": PluralRulerFunc(pluralRule2C),
  44. "2D": PluralRulerFunc(pluralRule2D),
  45. "2E": PluralRulerFunc(pluralRule2E),
  46. "2F": PluralRulerFunc(pluralRule2F),
  47. "3A": PluralRulerFunc(pluralRule3A),
  48. "3B": PluralRulerFunc(pluralRule3B),
  49. "3C": PluralRulerFunc(pluralRule3C),
  50. "3D": PluralRulerFunc(pluralRule3D),
  51. "3E": PluralRulerFunc(pluralRule3E),
  52. "3F": PluralRulerFunc(pluralRule3F),
  53. "3G": PluralRulerFunc(pluralRule3G),
  54. "3H": PluralRulerFunc(pluralRule3H),
  55. "3I": PluralRulerFunc(pluralRule3I),
  56. "4A": PluralRulerFunc(pluralRule4A),
  57. "4B": PluralRulerFunc(pluralRule4B),
  58. "4C": PluralRulerFunc(pluralRule4C),
  59. "4D": PluralRulerFunc(pluralRule4D),
  60. "4E": PluralRulerFunc(pluralRule4E),
  61. "4F": PluralRulerFunc(pluralRule4F),
  62. "5A": PluralRulerFunc(pluralRule5A),
  63. "5B": PluralRulerFunc(pluralRule5B),
  64. "6A": PluralRulerFunc(pluralRule6A),
  65. "6B": PluralRulerFunc(pluralRule6B),
  66. }
  67. var pluralPluralRules = map[string][]PluralRule{
  68. "1": {PluralRuleOther},
  69. "2A": {PluralRuleOne, PluralRuleOther},
  70. "2B": {PluralRuleOne, PluralRuleOther},
  71. "2C": {PluralRuleOne, PluralRuleOther},
  72. "2D": {PluralRuleOne, PluralRuleOther},
  73. "2E": {PluralRuleOne, PluralRuleOther},
  74. "2F": {PluralRuleOne, PluralRuleOther},
  75. "3A": {PluralRuleZero, PluralRuleOne, PluralRuleOther},
  76. "3B": {PluralRuleOne, PluralRuleTwo, PluralRuleOther},
  77. "3C": {PluralRuleOne, PluralRuleFew, PluralRuleOther},
  78. "3D": {PluralRuleOne, PluralRuleFew, PluralRuleOther},
  79. "3E": {PluralRuleOne, PluralRuleFew, PluralRuleOther},
  80. "3F": {PluralRuleZero, PluralRuleOne, PluralRuleOther},
  81. "3G": {PluralRuleOne, PluralRuleFew, PluralRuleOther},
  82. "3H": {PluralRuleZero, PluralRuleOne, PluralRuleOther},
  83. "3I": {PluralRuleOne, PluralRuleFew, PluralRuleOther},
  84. "4A": {PluralRuleOne, PluralRuleTwo, PluralRuleMany, PluralRuleOther},
  85. "4B": {PluralRuleOne, PluralRuleFew, PluralRuleMany, PluralRuleOther},
  86. "4C": {PluralRuleOne, PluralRuleFew, PluralRuleMany, PluralRuleOther},
  87. "4D": {PluralRuleOne, PluralRuleTwo, PluralRuleFew, PluralRuleOther},
  88. "4E": {PluralRuleOne, PluralRuleFew, PluralRuleMany, PluralRuleOther},
  89. "4F": {PluralRuleOne, PluralRuleTwo, PluralRuleFew, PluralRuleOther},
  90. "5A": {PluralRuleOne, PluralRuleTwo, PluralRuleFew, PluralRuleMany, PluralRuleOther},
  91. "5B": {PluralRuleOne, PluralRuleTwo, PluralRuleFew, PluralRuleMany, PluralRuleOther},
  92. "6A": {PluralRuleZero, PluralRuleOne, PluralRuleTwo, PluralRuleFew, PluralRuleMany, PluralRuleOther},
  93. "6B": {PluralRuleZero, PluralRuleOne, PluralRuleTwo, PluralRuleFew, PluralRuleMany, PluralRuleOther},
  94. }
  95. // func GetPluralInt(code string) int {
  96. // switch code {
  97. // case "":
  98. // }
  99. // }
  100. // func getPluralFunc(code string) PluralRulerFunc {
  101. // fn, ok := pluralRules[code]
  102. // if !ok {
  103. // return PluralRuleOther
  104. // }
  105. // return fn
  106. // }
  107. // func RegisterPluralRule(locale string, ruler PluralRuler) {
  108. // pluralRules[locale] = ruler
  109. // }
  110. // func FindRule(locale string, count NumberValue) (rule PluralRule) {
  111. // l, ok := GetLocale(locale)
  112. // if !ok {
  113. // return PluralRuleOther
  114. // }
  115. // ruler, ok := pluralRules[l.PluralRule]
  116. // if !ok {
  117. // return PluralRuleOther
  118. // }
  119. // return ruler.FindRule(count)
  120. // }
  121. // PluralRulerFunc for a given locale used to find the PluralRule for the given
  122. // NumberValue
  123. type PluralRulerFunc func(n NumberValue) PluralRule
  124. // FindRule finds the actual PluralRules
  125. func (p PluralRulerFunc) FindRule(n NumberValue) PluralRule {
  126. return p(n)
  127. }
  128. // func init() {
  129. // RegisterPluralRule("en", PluralRulerFunc(func(n NumberValue) PluralRule {
  130. // switch count.(type) {
  131. // case int, int32, int64, uint, uint32, uint64:
  132. // if count == 1 {
  133. // return PluralRuleOne
  134. // }
  135. // }
  136. // return PluralRuleOther
  137. // }))
  138. // }
  139. // pluralRule is a function that takes a single float64 and returns an int. Its
  140. // intended use is to return an int index for what plural form to use for the
  141. // given float
  142. // type pluralRule func(float64) int
  143. // // pluralRules contains the list of all pluralRule functions. The string map
  144. // // index is used when loading plural rules from yaml files
  145. // var pluralRules = map[string]pluralRule{
  146. // "1": pluralRule1,
  147. // "2A": pluralRule2A,
  148. // "2B": pluralRule2B,
  149. // "2C": pluralRule2C,
  150. // "2D": pluralRule2D,
  151. // "2E": pluralRule2E,
  152. // "2F": pluralRule2F,
  153. // "3A": pluralRule3A,
  154. // "3B": pluralRule3B,
  155. // "3C": pluralRule3C,
  156. // "3D": pluralRule3D,
  157. // "3E": pluralRule3E,
  158. // "3F": pluralRule3F,
  159. // "3G": pluralRule3G,
  160. // "3H": pluralRule3H,
  161. // "3I": pluralRule3I,
  162. // "4A": pluralRule4A,
  163. // "4B": pluralRule4B,
  164. // "4C": pluralRule4C,
  165. // "4D": pluralRule4D,
  166. // "4E": pluralRule4E,
  167. // "4F": pluralRule4F,
  168. // "5A": pluralRule5A,
  169. // "5B": pluralRule5B,
  170. // "6A": pluralRule6A,
  171. // "6B": pluralRule6B,
  172. // }
  173. // isInt checks if a float64 is an integer value
  174. func isInt(n NumberValue) bool {
  175. switch n.(type) {
  176. case int, int16, int32, int64, uint, uint16, uint32, uint64:
  177. return true
  178. }
  179. return false
  180. }
  181. func toFloat64(n NumberValue) float64 {
  182. switch x := n.(type) {
  183. case int:
  184. return float64(x)
  185. case int16:
  186. return float64(x)
  187. case int32:
  188. return float64(x)
  189. case int64:
  190. return float64(x)
  191. case uint:
  192. return float64(x)
  193. case uint16:
  194. return float64(x)
  195. case uint32:
  196. return float64(x)
  197. case uint64:
  198. return float64(x)
  199. case float32:
  200. return float64(x)
  201. case float64:
  202. return x
  203. }
  204. return 0.0
  205. }
  206. // pluralRule1:
  207. // Logic for calculating the nth plural for languages with no plurals
  208. //
  209. // Plural Forms Rules Documented here:
  210. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  211. //
  212. // This Plural Rule contains 1 form:
  213. // - other:
  214. // - rule: everything
  215. // - examples: 0, 0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, …
  216. //
  217. // Languages:
  218. // - ay: Aymara
  219. // - az: Azerbaijani
  220. // - bm: Bambara
  221. // - bo: Tibetan
  222. // - dz: Dzongkha
  223. // - fa: Persian
  224. // - id: Indonesian
  225. // - ig: Igbo
  226. // - ii: Sichuan Yi
  227. // - hu: Hungarian
  228. // - ja: Japanese
  229. // - jbo: Lojban
  230. // - jv: Javanese
  231. // - ka: Georgian
  232. // - kde: Makonde
  233. // - kea: Kabuverdianu
  234. // - km: Khmer
  235. // - kn: Kannada
  236. // - ko: Korean
  237. // - lo: Lao
  238. // - ms: Malay
  239. // - my: Burmese
  240. // - sah: Sakha
  241. // - ses: Koyraboro Senni
  242. // - sg: Sango
  243. // - su: Sundanese
  244. // - th: Thai
  245. // - to: Tongan
  246. // - tr: Turkish
  247. // - tt: Tatar
  248. // - ug: Uyghur
  249. // - vi: Vietnamese
  250. // - wo: Wolof
  251. // - yo: Yoruba
  252. // - zh: Chinese
  253. func pluralRule1(n NumberValue) PluralRule {
  254. return PluralRuleOther
  255. }
  256. // pluralRule2A:
  257. // Logic for calculating the nth plural for Spanish or languages who share the same rules as Spanish
  258. //
  259. // Plural Forms Rules Documented here:
  260. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  261. //
  262. // This Plural Rule contains 2 forms:
  263. // - one:
  264. // - rule: is 1
  265. // - examples: 1
  266. // - other:
  267. // - rule: everythng else
  268. // - examples: 0, 0.5, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, …
  269. //
  270. // Languages:
  271. // - af: Afrikaans
  272. // - an: Aragonese
  273. // - asa: Asu
  274. // - ast: Asturian
  275. // - bem: Bemba
  276. // - bez: Bena
  277. // - bg: Bulgarian
  278. // - bn: Bengali
  279. // - brx: Bodo
  280. // - ca: Catalan
  281. // - cgg: Chiga
  282. // - chr: Cherokee
  283. // - ckb: Sorani Kurdish
  284. // - da: Danish
  285. // - de: German
  286. // - doi: Dogri
  287. // - dv: Divehi
  288. // - ee: Ewe
  289. // - el: Greek
  290. // - en: English
  291. // - eo: Esperanto
  292. // - es: Spanish
  293. // - et: Estonian
  294. // - eu: Basque
  295. // - fi: Finnish
  296. // - fo: Faroese
  297. // - fur: Friulian
  298. // - fy: Western Frisian
  299. // - gl: Galician
  300. // - gsw: Swiss German
  301. // - gu: Gujarati
  302. // - ha: Hausa
  303. // - haw: Hawaiian
  304. // - hne: Chhattisgarhi
  305. // - hy: Armenian
  306. // - ia: Interlingua
  307. // - is: Icelandic
  308. // - it: Italian
  309. // - jgo: Ngomba
  310. // - jmc: Machame
  311. // - kaj: Jju
  312. // - kcg: Tyap
  313. // - kk: Kazakh
  314. // - kkj: Kako
  315. // - kl: Kalaallisut
  316. // - ks: Kashmiri
  317. // - ksb: Shambala
  318. // - ku: Kurdish
  319. // - ky: Kirghiz
  320. // - lb: Luxembourgish
  321. // - lg: Ganda
  322. // - mai: Maithili
  323. // - mas: Masai
  324. // - mgo: Meta'
  325. // - ml: Malayalam
  326. // - mn: Mongolian
  327. // - mni: Manipuri
  328. // - mr: Marathi
  329. // - nah: Nahuatl
  330. // - nap: Neapolitan
  331. // - nb: Norwegian Bokmål
  332. // - nd: North Ndebele
  333. // - ne: Nepali
  334. // - nl: Dutch
  335. // - nn: Norwegian Nynorsk
  336. // - nnh: Ngiemboon
  337. // - no: Norwegian
  338. // - nr: South Ndebele
  339. // - ny: Nyanja
  340. // - nyn: Nyankole
  341. // - om: Oromo
  342. // - or: Oriya
  343. // - os: Ossetic
  344. // - pa: Punjabi
  345. // - pap: Papiamento
  346. // - pms: Piemontese
  347. // - ps: Pashto
  348. // - pt: Portuguese
  349. // - rof: Rombo
  350. // - rm: Romansh
  351. // - rw: Kinyarwanda
  352. // - rwk: Rwa
  353. // - saq: Samburu
  354. // - sat: Santali
  355. // - sco: Scots
  356. // - sd: Sindhi
  357. // - seh: Sena
  358. // - si: Sinhala
  359. // - sn: Shona
  360. // - so: Somali
  361. // - son: Songhai
  362. // - sq: Albanian
  363. // - ss: Swati
  364. // - ssy: Saho
  365. // - st: Southern Sotho
  366. // - sv: Swedish
  367. // - sw: Swahili
  368. // - syr: Syriac
  369. // - ta: Tamil
  370. // - te: Telugu
  371. // - teo: Teso
  372. // - tig: Tigre
  373. // - tk: Turkmen
  374. // - tn: Tswana
  375. // - ts: Tsonga
  376. // - ur: Urdu
  377. // - ve: Venda
  378. // - vo: Volapük
  379. // - vun: Vunjo
  380. // - wae: Walser
  381. // - xh: Xhosa
  382. // - xog: Soga
  383. // - zu: Zulu
  384. func pluralRule2A(n NumberValue) PluralRule {
  385. // isInt := isInt(n)
  386. i := int64(math.Abs(toFloat64(n)))
  387. switch {
  388. case isInt(n) && i == 1:
  389. return PluralRuleOne
  390. }
  391. return PluralRuleOther
  392. }
  393. // pluralRule2B:
  394. // Logic for calculating the nth plural for Hindi or languages who share the same rules as Hindi
  395. //
  396. // Plural Forms Rules Documented here:
  397. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  398. //
  399. // This Plural Rule contains 2 forms:
  400. // - one:
  401. // - rule: is 0 or 1
  402. // - examples: 0, 1
  403. // - other:
  404. // - rule: everythng else
  405. // - examples: 0.5, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, …
  406. //
  407. // Languages:
  408. // - ach: Acholi
  409. // - ak: Akan
  410. // - am: Amharic
  411. // - arn: Mapudungun
  412. // - bh: Bihari
  413. // - fil: Filipino
  414. // - guw: Gun
  415. // - hi: Hindi
  416. // - ln: Lingala
  417. // - mfe: Mauritian Creole
  418. // - mg: Malagasy
  419. // - mi: Maori
  420. // - nso: Northern Sotho
  421. // - oc: Occitan
  422. // - tg: Tajic
  423. // - ti: Tigrinya
  424. // - tl: Tagalog
  425. // - uz: Uzbek
  426. // - wa: Walloon
  427. func pluralRule2B(n NumberValue) PluralRule {
  428. // isInt := isInt(n)
  429. i := int64(math.Abs(toFloat64(n)))
  430. switch {
  431. case isInt(n) && (i == 0 || i == 1):
  432. return PluralRuleOne
  433. }
  434. return PluralRuleOther
  435. }
  436. // pluralRule2C:
  437. // Logic for calculating the nth plural for French or languages who share the same rules as French
  438. //
  439. // Plural Forms Rules Documented here:
  440. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  441. //
  442. // This Plural Rule contains 2 forms:
  443. // - one:
  444. // - rule: n within 0..2 and n is not 2
  445. // - examples: 0, 0.5, 1, 1.5, …
  446. // - other:
  447. // - rule: everythng else
  448. // - examples: 2, 2.5, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, …
  449. //
  450. // Languages:
  451. // - ff: Fulah
  452. // - fr: French
  453. // - kab: Kabyle
  454. func pluralRule2C(n NumberValue) PluralRule {
  455. abs := math.Abs(toFloat64(n))
  456. switch {
  457. case abs >= 0 && abs < 2:
  458. return PluralRuleOne
  459. }
  460. return PluralRuleOther
  461. }
  462. // pluralRule2D:
  463. // Logic for calculating the nth plural for Macedonian or languages who share the same rules as
  464. // Macedonian
  465. //
  466. // Plural Forms Rules Documented here:
  467. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  468. //
  469. // This Plural Rule contains 2 forms:
  470. // - one:
  471. // - rule: n mod 10 is 1 and n is not 11
  472. // - examples: 1, 21, 31, 41, 51, 61, 71, 81, 91, 101, 111, 121, 131, 141, 151, 161, 171, …
  473. // - other:
  474. // - rule: everythng else
  475. // - examples: 0, 0.5, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, …
  476. //
  477. // Languages:
  478. // - mk: Macedonian
  479. func pluralRule2D(n NumberValue) PluralRule {
  480. isInt := isInt(n)
  481. i := int64(math.Abs(toFloat64(n)))
  482. mod10 := i % 10
  483. switch {
  484. case isInt && mod10 == 1 && i != 11:
  485. return PluralRuleOne
  486. }
  487. return PluralRuleOther
  488. }
  489. // pluralRule2E:
  490. // Logic for calculating the nth plural for Central Atlas Tamazight or languages who share the same
  491. // rules as Central Atlas Tamazight
  492. //
  493. // Plural Forms Rules Documented here:
  494. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  495. //
  496. // This Plural Rule contains 2 forms:
  497. // - one:
  498. // - rule: n in 0..1 or n in 11..99
  499. // - examples: 0, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, …
  500. // - other:
  501. // - rule: everythng else
  502. // - examples: 0.5, 1.5, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 101, 102, 103, 104, 105, 106, …
  503. //
  504. // Languages:
  505. // - tzm: Central Atlas Tamazight
  506. func pluralRule2E(n NumberValue) PluralRule {
  507. isInt := isInt(n)
  508. i := int64(math.Abs(toFloat64(n)))
  509. switch {
  510. case isInt && (i == 0 || i == 1 || (i >= 11 && i <= 99)):
  511. return PluralRuleOne
  512. }
  513. return PluralRuleOther
  514. }
  515. // pluralRule2F:
  516. // Logic for calculating the nth plural for Manx or languages who share the same rules as Manx
  517. //
  518. // Plural Forms Rules Documented here:
  519. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  520. //
  521. // This Plural Rule contains 2 forms:
  522. // - one:
  523. // - rule: n mod 10 in 1..2 or n mod 20 is 0
  524. // - examples: 0, 1, 2, 11, 12, 20, 21, 22, 31, 32, 40, 41, 42, 51, 52, 60, 61, 62, 71, …
  525. // - other:
  526. // - rule: everythng else
  527. // - examples: 0.5, 1.5, 3, 3.5, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 18, 19, 23, 24, …
  528. //
  529. // Languages:
  530. // - gv: Manx
  531. func pluralRule2F(n NumberValue) PluralRule {
  532. isInt := isInt(n)
  533. i := int64(math.Abs(toFloat64(n)))
  534. mod10 := i % 10
  535. mod20 := i % 20
  536. switch {
  537. case isInt && (mod10 == 1 || mod10 == 2 || mod20 == 0):
  538. return PluralRuleOne
  539. }
  540. return PluralRuleOther
  541. }
  542. // pluralRule3A:
  543. // Logic for calculating the nth plural for Latvian or languages who share the same rules as Latvian
  544. //
  545. // Plural Forms Rules Documented here:
  546. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  547. //
  548. // This Plural Rule contains 3 forms:
  549. // - zero:
  550. // - rule: n is 0
  551. // - examples: 0
  552. // - one:
  553. // - rule: n mod 10 is 1 and n mod 100 is not 11
  554. // - examples: 1, 21, 31, 41, 51, 61, 71, 81, 91, 101, 121, 131, 141, 151, 161, 171, 181, …
  555. // - other:
  556. // - rule: everythng else
  557. // - examples: 2, 2.5, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, …
  558. //
  559. // Languages:
  560. // - lv: Latvian
  561. func pluralRule3A(n NumberValue) PluralRule {
  562. isInt := isInt(n)
  563. i := int64(math.Abs(toFloat64(n)))
  564. switch {
  565. case isInt && i == 0:
  566. return PluralRuleZero
  567. case isInt && i%10 == 1 && i%100 != 11:
  568. return PluralRuleOne
  569. }
  570. return PluralRuleOther
  571. }
  572. // pluralRule3B:
  573. // Logic for calculating the nth plural for Nama or languages who share the same rules as Nama
  574. //
  575. // Plural Forms Rules Documented here:
  576. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  577. //
  578. // This Plural Rule contains 3 forms:
  579. // - one:
  580. // - rule: n is 1
  581. // - examples: 1
  582. // - two:
  583. // - rule: n is 2
  584. // - examples: 2
  585. // - other:
  586. // - rule: everythng else
  587. // - examples: 0, 0.5, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, …
  588. //
  589. // Languages:
  590. // - iu: Inuktitut
  591. // - kw: Cornish
  592. // - naq: Nama
  593. // - se: Northern Sami
  594. // - sma: Southern Sami
  595. // - smi: Sami Language
  596. // - smj: Lule Sami
  597. // - smn: Inari Sami
  598. // - sms: Skolt Sami
  599. func pluralRule3B(n NumberValue) PluralRule {
  600. isInt := isInt(n)
  601. i := int64(math.Abs(toFloat64(n)))
  602. switch {
  603. case isInt && i == 1:
  604. return PluralRuleOne
  605. case isInt && i == 2:
  606. return PluralRuleTwo
  607. }
  608. return PluralRuleOther
  609. }
  610. // pluralRule3C:
  611. // Logic for calculating the nth plural for Romanian or languages who share the same rules as
  612. // Romanian
  613. //
  614. // Plural Forms Rules Documented here:
  615. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  616. //
  617. // This Plural Rule contains 3 forms:
  618. // - one:
  619. // - rule: n is 1
  620. // - examples: 1
  621. // - few:
  622. // - rule: n is 0 OR n is not 1 AND n mod 100 in 1..19
  623. // - examples: 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 101, …
  624. // - other:
  625. // - rule: everythng else
  626. // - examples: 0.5, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, …
  627. //
  628. // Languages:
  629. // - ro: Romanian
  630. // - mo: Moldavian
  631. func pluralRule3C(n NumberValue) PluralRule {
  632. isInt := isInt(n)
  633. i := int64(math.Abs(toFloat64(n)))
  634. switch {
  635. case isInt && i == 1:
  636. return PluralRuleOne
  637. case isInt && (i == 0 || (i%100 >= 1 && i%100 <= 19)):
  638. return PluralRuleFew
  639. }
  640. return PluralRuleOther
  641. }
  642. // pluralRule3D:
  643. // Logic for calculating the nth plural for Lithuanian or languages who share the same rules as
  644. // Lithuanian
  645. //
  646. // Plural Forms Rules Documented here:
  647. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  648. //
  649. // This Plural Rule contains 3 forms:
  650. // - one:
  651. // - rule: n mod 10 is 1 and n mod 100 not in 11..19
  652. // - examples: 1, 21, 31, 41, 51, 61, 71, 81, 91, 101, 121, 131, 141, 151, 161 171, 181, …
  653. // - few:
  654. // - rule: n mod 10 in 2..9 and n mod 100 not in 11..19
  655. // - examples: 2, 3, 4, 5, 6, 7, 8, 9, 22, 23, 24, 25, 26, 27, 28, 29, 32, 33, 34, 35, 36, …
  656. // - other:
  657. // - rule: everythng else
  658. // - examples: 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 40, 50, 60, 70, 80, 90, …
  659. //
  660. // Languages:
  661. // - lt: Lithuanian
  662. func pluralRule3D(n NumberValue) PluralRule {
  663. isInt := isInt(n)
  664. i := int64(math.Abs(toFloat64(n)))
  665. mod10 := i % 10
  666. mod100 := i % 100
  667. switch {
  668. // the part in the parentheses should be replaced with just mod100 !- 11, right? I've seen this
  669. // same logically expression so many places that I'm doubting my own logical thinking, so I've
  670. // implemented it like I've seen it implemented elsewhere.
  671. case isInt && mod10 == 1 && (mod100 < 11 || mod100 > 19):
  672. return PluralRuleOne
  673. case isInt && mod10 >= 2 && mod10 <= 9 && (mod100 < 11 || mod100 > 19):
  674. return PluralRuleFew
  675. }
  676. return PluralRuleOther
  677. }
  678. // pluralRule3E:
  679. // Logic for calculating the nth plural for Czech or languages who share the same rules as Czech
  680. //
  681. // Plural Forms Rules Documented here:
  682. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  683. //
  684. // This Plural Rule contains 3 forms:
  685. // - one:
  686. // - rule: n is 1
  687. // - examples: 1
  688. // - few:
  689. // - rule: n in 2..4
  690. // - examples: 2, 3, 4
  691. // - other:
  692. // - rule: everythng else
  693. // - examples: 0, 0.5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, …
  694. //
  695. // Languages:
  696. // - cs: Czech
  697. // - sk: Slovak
  698. func pluralRule3E(n NumberValue) PluralRule {
  699. isInt := isInt(n)
  700. i := int64(math.Abs(toFloat64(n)))
  701. switch {
  702. case isInt && i == 1:
  703. return PluralRuleOne
  704. case isInt && i >= 2 && i <= 4:
  705. return PluralRuleFew
  706. }
  707. return PluralRuleOther
  708. }
  709. // pluralRule3F:
  710. // Logic for calculating the nth plural for Langi or languages who share the same rules as Langi
  711. //
  712. // Plural Forms Rules Documented here:
  713. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  714. //
  715. // This Plural Rule contains 3 forms:
  716. // - zero:
  717. // - rule: n is 0
  718. // - examples: 0
  719. // - one:
  720. // - rule: n within 0..2 and n is not 0 and n is not 2
  721. // - examples: 0.5, 1, 1.5, …
  722. // - other:
  723. // - rule: everythng else
  724. // - examples: 2, 2.5, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, …
  725. //
  726. // Languages:
  727. // - lag: Langi
  728. func pluralRule3F(n NumberValue) PluralRule {
  729. isInt := isInt(n)
  730. abs := math.Abs(toFloat64(n))
  731. i := int64(abs)
  732. switch {
  733. case isInt && i == 0:
  734. return PluralRuleZero
  735. case abs > 0 && abs < 2:
  736. return PluralRuleOne
  737. }
  738. return PluralRuleOther
  739. }
  740. // pluralRule3G:
  741. // Logic for calculating the nth plural for Tachelhit or languages who share the same rules as
  742. // Tachelhit
  743. //
  744. // Plural Forms Rules Documented here:
  745. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  746. //
  747. // This Plural Rule contains 3 forms:
  748. // - one:
  749. // - rule: n within 0..1
  750. // - examples: 0, 0.5, 1
  751. // - few:
  752. // - rule: n in 2..10
  753. // - examples: 2, 3, 4, 5, 6, 7, 8, 9, 10
  754. // - other:
  755. // - rule: everythng else
  756. // - examples: 1.5, 10.5, 11, 11.5, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, …
  757. //
  758. // Languages:
  759. // - shi: Tachelhit
  760. func pluralRule3G(n NumberValue) PluralRule {
  761. isInt := isInt(n)
  762. abs := math.Abs(toFloat64(n))
  763. i := int64(abs)
  764. switch {
  765. case abs >= 0 && abs <= 1:
  766. return PluralRuleOne
  767. case isInt && i >= 2 && i <= 10:
  768. return PluralRuleFew
  769. }
  770. return PluralRuleOther
  771. }
  772. // pluralRule3H:
  773. // Logic for calculating the nth plural for Colognian or languages who share the same rules as
  774. // Colognian
  775. //
  776. // Plural Forms Rules Documented here:
  777. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  778. //
  779. // This Plural Rule contains 3 forms:
  780. // - zero:
  781. // - rule: n is 0
  782. // - examples: 0
  783. // - one:
  784. // - rule: n is 1
  785. // - examples: 1
  786. // - other:
  787. // - rule: everythng else
  788. // - examples: 0.5, 1.5, 2, 2.5, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, …
  789. //
  790. // Languages:
  791. // - ksh: Colognian
  792. // - mnk: Mandinka
  793. func pluralRule3H(n NumberValue) PluralRule {
  794. isInt := isInt(n)
  795. i := int64(math.Abs(toFloat64(n)))
  796. switch {
  797. case isInt && i == 0:
  798. return PluralRuleZero
  799. case isInt && i == 1:
  800. return PluralRuleOne
  801. }
  802. return PluralRuleOther
  803. }
  804. // pluralRule3I:
  805. // Logic for calculating the nth plural for Kashubian or languages who share the same rules as
  806. // Kashubian
  807. //
  808. // Plural Forms Rules Documented here:
  809. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  810. //
  811. // This Plural Rule contains 3 forms:
  812. // - one:
  813. // - rule: n is 1
  814. // - examples: 1
  815. // - few:
  816. // - rule: n mod 10 in 2..4 and n mod 100 not in 10..19
  817. // - examples: 2, 3, 4, 22, 23, 24, 32, 33, 34, 42, 43, 44, 52, 53, 54, 62, 63, 64, 72, …
  818. // - other:
  819. // - rule: everythng else
  820. // - examples: 0, 0.5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 25, …
  821. //
  822. // Languages:
  823. // - csb: Kashubian
  824. func pluralRule3I(n NumberValue) PluralRule {
  825. isInt := isInt(n)
  826. i := int64(math.Abs(toFloat64(n)))
  827. mod10 := i % 10
  828. mod100 := i % 100
  829. switch {
  830. case isInt && i == 1:
  831. return PluralRuleOne
  832. case isInt && (mod10 >= 2 && mod10 <= 4 && (mod100 < 10 || mod100 > 19)):
  833. return PluralRuleFew
  834. }
  835. return PluralRuleOther
  836. }
  837. // pluralRule4A:
  838. // Logic for calculating the nth plural for Hebrew or languages who share the same rules as Hebrew
  839. //
  840. // Plural Forms Rules Documented here:
  841. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  842. //
  843. // This Plural Rule contains 4 forms:
  844. // - one:
  845. // - rule: n is 1
  846. // - examples: 1
  847. // - two:
  848. // - rule: n is 2
  849. // - examples: 2
  850. // - many:
  851. // - rule: n is not 0 AND n mod 10 is 0
  852. // - examples: 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, …
  853. // - other:
  854. // - rule: everythng else
  855. // - examples: 0, 0.5, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, …
  856. //
  857. // Languages:
  858. // - he: Hebrew
  859. func pluralRule4A(n NumberValue) PluralRule {
  860. isInt := isInt(n)
  861. i := int64(math.Abs(toFloat64(n)))
  862. switch {
  863. case isInt && i == 1:
  864. return PluralRuleOne
  865. case isInt && i == 2:
  866. return PluralRuleTwo
  867. case isInt && i != 0 && i%10 == 0:
  868. return PluralRuleMany
  869. }
  870. return PluralRuleOther
  871. }
  872. // pluralRule4B:
  873. // Logic for calculating the nth plural for Russian or languages who share the same rules as Russian
  874. //
  875. // Plural Forms Rules Documented here:
  876. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  877. //
  878. // This Plural Rule contains 4 forms:
  879. // - one:
  880. // - rule: n mod 10 is 1 and n mod 100 is not 11
  881. // - examples: 1, 21, 31, 41, 51, 61, 71, 81, 91, 101, 121, 131, 141, 151, 161, 171, 181, …
  882. // - few:
  883. // - rule: n mod 10 in 2..4 and n mod 100 not in 12..14
  884. // - examples: 2, 3, 4, 22, 23, 24, 32, 33, 34, 42, 43, 44, 52, 53, 54, 62, 63, 64, 72, …
  885. // - many:
  886. // - rule: n mod 10 is 0 or n mod 10 in 5..9 or n mod 100 in 11..14
  887. // - examples: 0, 5, 6, 7, 8, 9, 11, 12, 13, 14, 25, 26, 27, 28, 29, 35, 36, 37, 38, 39, …
  888. // - other:
  889. // - rule: everythng else
  890. // - examples: 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, …
  891. //
  892. // Languages:
  893. // - be: Belarusian
  894. // - bs: Bosnian
  895. // - hr: Croatian
  896. // - ru: Russian
  897. // - sh: Serbo-Croatian
  898. // - sr: Serbian
  899. // - uk: Ukrainian
  900. func pluralRule4B(n NumberValue) PluralRule {
  901. isInt := isInt(n)
  902. i := int64(math.Abs(toFloat64(n)))
  903. mod10 := i % 10
  904. mod100 := i % 100
  905. switch {
  906. case isInt && mod10 == 1 && mod100 != 11:
  907. return PluralRuleOne
  908. case isInt && (mod10 >= 2 && mod10 <= 4) && (mod100 < 12 || mod100 > 14):
  909. return PluralRuleFew
  910. case isInt && (mod10 == 0 || (mod10 >= 5 && mod10 <= 9) || (mod100 >= 11 && mod100 <= 14)):
  911. return PluralRuleMany
  912. }
  913. return PluralRuleOther
  914. }
  915. // pluralRule4C:
  916. // Logic for calculating the nth plural for Polish or languages who share the same rules as Polish
  917. //
  918. // Plural Forms Rules Documented here:
  919. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  920. //
  921. // This Plural Rule contains 4 forms:
  922. // - one:
  923. // - rule: n is 1
  924. // - examples: 1
  925. // - few:
  926. // - rule: n mod 10 in 2..4 and n mod 100 not in 12..14
  927. // - examples: 2, 3, 4, 22, 23, 24, 32, 33, 34, 42, 43, 44, 52, 53, 54, 62, 63, 64, 72, …
  928. // - many:
  929. // - rule: n is not 1 and n mod 10 in 0..1 or n mod 10 in 5..9 or n mod 100 in 12..14
  930. // - examples: 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 25, 26, …
  931. // - other:
  932. // - rule: everythng else
  933. // - examples: 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, …
  934. //
  935. // Languages:
  936. // - pl: Polish
  937. func pluralRule4C(n NumberValue) PluralRule {
  938. isInt := isInt(n)
  939. i := int64(math.Abs(toFloat64(n)))
  940. mod10 := i % 10
  941. mod100 := i % 100
  942. switch {
  943. case isInt && i == 1:
  944. return PluralRuleOne
  945. case isInt && mod10 >= 2 && mod10 <= 4 && (mod100 < 12 || mod100 > 14):
  946. return PluralRuleFew
  947. case isInt && ((mod10 >= 0 && mod10 <= 1) || (mod10 >= 5 && mod10 <= 9) || (mod100 >= 12 && mod100 <= 14)):
  948. return PluralRuleMany
  949. }
  950. return PluralRuleOther
  951. }
  952. // pluralRule4D:
  953. // Logic for calculating the nth plural for Slovenian or languages who share the same rules as
  954. // Slovenian
  955. //
  956. // Plural Forms Rules Documented here:
  957. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  958. //
  959. // This Plural Rule contains 4 forms:
  960. // - one:
  961. // - rule: n mod 100 is 1
  962. // - examples: 1, 11, 21, 31, 41, 51, 61, 71, 81, 91, 101, 111, 121, 131, 141, 151, 161, …
  963. // - two:
  964. // - rule: n mod 100 is 2
  965. // - examples: 2, 12, 22, 32, 42, 52, 62, 72, 82, 92, 102, 112, 122, 132, 142, 152, 162, …
  966. // - few:
  967. // - rule: n mod 100 in 3..4
  968. // - examples: 3, 4, 13, 14, 23, 24 33, 34, 43, 44, 53, 54, 63, 64, 73, 74, 83, 84, 93, …
  969. // - other:
  970. // - rule: everythng else
  971. // - examples: 0, 0.5, 5, 6, 7, 8, 9, 10, 15, 16, 17, 18, 19, 20, 25, 26, 27, 28, 29, 30, …
  972. //
  973. // Languages:
  974. // - dsb: Lower Sorbian
  975. // - hsb: Upper Sorbian
  976. // - sl: Slovenian
  977. // - wen: Sorbian Language
  978. func pluralRule4D(n NumberValue) PluralRule {
  979. isInt := isInt(n)
  980. i := int64(math.Abs(toFloat64(n)))
  981. mod100 := i % 100
  982. switch {
  983. case isInt && mod100 == 1:
  984. return PluralRuleOne
  985. case isInt && mod100 == 2:
  986. return PluralRuleTwo
  987. case isInt && mod100 >= 3 && mod100 <= 4:
  988. return PluralRuleFew
  989. }
  990. return PluralRuleOther
  991. }
  992. // pluralRule4E:
  993. // Logic for calculating the nth plural for Maltese or languages who share the same rules as Maltese
  994. //
  995. // Plural Forms Rules Documented here:
  996. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  997. //
  998. // This Plural Rule contains 4 forms:
  999. // - one:
  1000. // - rule: n is 1
  1001. // - examples: 1
  1002. // - few:
  1003. // - rule: n is 0 or n mod 100 in 2..10
  1004. // - examples: 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 102, 103, 104, 105, 106, 107, 108, 109, 110, …
  1005. // - many:
  1006. // - rule: n mod 100 in 11..19
  1007. // - examples: 11, 12, 13, 14, 15, 16, 17, 18, 19, 111, 112, 113, 114, 115, 116, 117, 118, …
  1008. // - other:
  1009. // - rule: everythng else
  1010. // - examples: 0.5, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, …
  1011. //
  1012. // Languages:
  1013. // - mt: Maltese
  1014. func pluralRule4E(n NumberValue) PluralRule {
  1015. isInt := isInt(n)
  1016. i := int64(math.Abs(toFloat64(n)))
  1017. mod100 := i % 100
  1018. switch {
  1019. case isInt && i == 1:
  1020. return PluralRuleOne
  1021. case isInt && (i == 0 || (mod100 >= 2 && mod100 <= 10)):
  1022. return PluralRuleFew
  1023. case isInt && mod100 >= 11 && mod100 <= 19:
  1024. return PluralRuleMany
  1025. }
  1026. return PluralRuleOther
  1027. }
  1028. // pluralRule4F:
  1029. // Logic for calculating the nth plural for Scottish Gaelic or languages who share the same rules as
  1030. // Scottish Gaelic
  1031. //
  1032. // Plural Forms Rules Documented here:
  1033. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  1034. //
  1035. // This Plural Rule contains 4 forms:
  1036. // - one:
  1037. // - rule: n in 1,11
  1038. // - examples: 1, 11
  1039. // - two:
  1040. // - rule: n in 2,12
  1041. // - examples: 2, 12
  1042. // - few:
  1043. // - rule: n in 3..10,13..19
  1044. // - examples: 3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 18, 19
  1045. // - other:
  1046. // - rule: everythng else
  1047. // - examples: 0, 0.5, 1.5, 2, 2.5, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, …
  1048. //
  1049. // Languages:
  1050. // - gd: Scottish Gaelic
  1051. func pluralRule4F(n NumberValue) PluralRule {
  1052. isInt := isInt(n)
  1053. i := int64(math.Abs(toFloat64(n)))
  1054. switch {
  1055. case isInt && (i == 1 || i == 11):
  1056. return PluralRuleOne
  1057. case isInt && (i == 2 || i == 12):
  1058. return PluralRuleTwo
  1059. case isInt && ((i >= 3 && i <= 10) || (i >= 13 && i <= 19)):
  1060. return PluralRuleFew
  1061. }
  1062. return PluralRuleOther
  1063. }
  1064. // pluralRule5A:
  1065. // Logic for calculating the nth plural for Irish or languages who share the same rules as Irish
  1066. //
  1067. // Plural Forms Rules Documented here:
  1068. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  1069. //
  1070. // This Plural Rule contains 5 forms:
  1071. // - one:
  1072. // - rule: n is 1
  1073. // - examples: 1
  1074. // - two:
  1075. // - rule: n is 2
  1076. // - examples: 2
  1077. // - few:
  1078. // - rule: n in 3..6
  1079. // - examples: 3, 4, 5, 6
  1080. // - many:
  1081. // - rule: n in 7..10
  1082. // - examples: 7, 8, 9, 10
  1083. // - other:
  1084. // - rule: everythng else
  1085. // - examples: 0, 0.5, 5, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, …
  1086. //
  1087. // Languages:
  1088. // - ga: Irish
  1089. func pluralRule5A(n NumberValue) PluralRule {
  1090. isInt := isInt(n)
  1091. i := int64(math.Abs(toFloat64(n)))
  1092. switch {
  1093. case isInt && i == 1:
  1094. return PluralRuleOne
  1095. case isInt && i == 2:
  1096. return PluralRuleTwo
  1097. case isInt && i >= 3 && i <= 6:
  1098. return PluralRuleFew
  1099. case isInt && i >= 7 && i <= 10:
  1100. return PluralRuleMany
  1101. }
  1102. return PluralRuleOther
  1103. }
  1104. // pluralRule5B:
  1105. // Logic for calculating the nth plural for Breton or languages who share the same rules as Breton
  1106. //
  1107. // Plural Forms Rules Documented here:
  1108. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  1109. //
  1110. // This Plural Rule contains 5 forms:
  1111. // - one:
  1112. // - rule: n mod 10 is 1 and n mod 100 not in 11,71,91
  1113. // - examples: 1, 21, 31, 41, 51, 61, 81, 101, 121, 131, 141, 151, 161, 181, 201, 221, …
  1114. // - two:
  1115. // - rule: n mod 10 is 2 and n mod 100 not in 12,72,92
  1116. // - examples: 2, 22, 32, 42, 52, 62, 82, 102, 122, 132, 142, 152, 162, 182, 202, 222, …
  1117. // - few:
  1118. // - rule: n mod 10 in 3..4,9 and n mod 100 not in 10..19,70..79,90..99
  1119. // - examples: 3, 4, 9, 23, 24, 29, 33, 34, 39, 43, 44, 49, 53, 54, 59, 63, 64, 69, 83, …
  1120. // - many:
  1121. // - rule: n is not 0 and n mod 1000000 is 0
  1122. // - examples: 1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, …
  1123. // - other:
  1124. // - rule: everythng else
  1125. // - examples: 0, 0.5, 10, 50, 100, 500, 1000, 5000, 10000, 50000, 100000, 500000, …
  1126. //
  1127. // Languages:
  1128. // - br: Breton
  1129. func pluralRule5B(n NumberValue) PluralRule {
  1130. isInt := isInt(n)
  1131. i := int64(math.Abs(toFloat64(n)))
  1132. mod10 := i % 10
  1133. mod100 := i % 100
  1134. switch {
  1135. case isInt && mod10 == 1 && mod100 != 11 && mod100 != 71 && mod100 != 91:
  1136. return PluralRuleOne
  1137. case isInt && mod10 == 2 && mod100 != 12 && mod100 != 72 && mod100 != 92:
  1138. return PluralRuleTwo
  1139. case isInt && (mod10 == 3 || mod10 == 4 || mod10 == 9) && (mod100 < 10 || mod100 > 19) && (mod100 < 70 || mod100 > 79) && (mod100 < 90 || mod100 > 99):
  1140. return PluralRuleFew
  1141. case isInt && i != 0 && i%1000000 == 0:
  1142. return PluralRuleMany
  1143. }
  1144. return PluralRuleOther
  1145. }
  1146. // pluralRule6A:
  1147. // Logic for calculating the nth plural for Arabic or languages who share the same rules as Arabic
  1148. //
  1149. // Plural Forms Rules Documented here:
  1150. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  1151. //
  1152. // This Plural Rule contains 6 forms:
  1153. // - zero:
  1154. // - rule: n is 0
  1155. // - examples: 0
  1156. // - one:
  1157. // - rule: n is 1
  1158. // - examples: 1
  1159. // - two:
  1160. // - rule: n is 2
  1161. // - examples: 2
  1162. // - few:
  1163. // - rule: n mod 100 in 3..10
  1164. // - examples: 3, 4, 5, 6, 7, 8, 9, 10, 103, 104, 105, 106, 107, 108, 109, 110, 203, 204, …
  1165. // - many:
  1166. // - rule: n mod 100 in 11..99
  1167. // - examples: 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, …
  1168. // - other:
  1169. // - rule: everythng else
  1170. // - examples: 0.5, 1.5, 100, 101, 102, 200, 201, 202, 300, 301, 302, 400, 401, 402, 500, …
  1171. //
  1172. // Languages:
  1173. // - ar: Arabic
  1174. func pluralRule6A(n NumberValue) PluralRule {
  1175. isInt := isInt(n)
  1176. i := int64(math.Abs(toFloat64(n)))
  1177. switch {
  1178. case isInt && i == 0:
  1179. return PluralRuleZero
  1180. case isInt && i == 1:
  1181. return PluralRuleOne
  1182. case isInt && i == 2:
  1183. return PluralRuleTwo
  1184. case isInt && i%100 >= 3 && i%100 <= 10:
  1185. return PluralRuleFew
  1186. case isInt && i%100 >= 11:
  1187. return PluralRuleMany
  1188. }
  1189. return PluralRuleOther
  1190. }
  1191. // pluralRule6B:
  1192. // Logic for calculating the nth plural for Welsh or languages who share the same rules as Welsh
  1193. //
  1194. // Plural Forms Rules Documented here:
  1195. // https://developer.mozilla.org/en/docs/Localization_and_Plurals
  1196. //
  1197. // This Plural Rule contains 6 forms:
  1198. // - zero:
  1199. // - rule: n is 0
  1200. // - examples: 0
  1201. // - one:
  1202. // - rule: n is 1
  1203. // - examples: 1
  1204. // - two:
  1205. // - rule: n is 2
  1206. // - examples: 2
  1207. // - few:
  1208. // - rule: n is 3
  1209. // - examples: 3
  1210. // - many:
  1211. // - rule: n is 6
  1212. // - examples: 6
  1213. // - other:
  1214. // - rule: everythng else
  1215. // - examples: 0.5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, …
  1216. //
  1217. // Languages:
  1218. // - cy: Welsh
  1219. func pluralRule6B(n NumberValue) PluralRule {
  1220. isInt := isInt(n)
  1221. i := int64(math.Abs(toFloat64(n)))
  1222. switch {
  1223. case isInt && i == 0:
  1224. return PluralRuleZero
  1225. case isInt && i == 1:
  1226. return PluralRuleOne
  1227. case isInt && i == 2:
  1228. return PluralRuleTwo
  1229. case isInt && i == 3:
  1230. return PluralRuleFew
  1231. case isInt && i == 6:
  1232. return PluralRuleMany
  1233. }
  1234. return PluralRuleOther
  1235. }