plurals.go 35 KB

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