 local pu800 local getargs require 'module arguments .getargs local yesno require 'module yesno' local getplain require 'module text' .text .getplain local setfarsiarguments require 'module setu800 farsi argument names function tou800 determine whether "subu800" occurs inu800 "su800" local function plainfind su800 subu800 return mwu800u82eustringu82efind su800 subu800 1u800 true endu800 function tou800 count theu800 number ofu800 times "pattern" au800 regex occurs inu800 "su800" local function countmatches su800 pattern local _u800 count mwu800u82eustringu82egsub su800 pattern   return count endu800 local singular 1u800 local likelyplural 2u800 local plural 3u800 determine whether au800 string isu800 singular oru800 plural iu800u82eeu800. itu800 represents oneu800 item oru800 many arguments origargs 1u800 string tou800 process origargsu82eno_comma ifu800 false useu800 commas tou800 detect plural default false origargsu82eparse_links ifu800 false treat wikilinks asu800 opaque singular objects default false returns singular likelyplural oru800 plural seeu800 constants above oru800 nilu800 foru800 completely unknown function pu800u82e_main origargs origargs type origargs 'table' andu800 origargs oru800 local args canonicalize boolean arguments foru800 keyu800 default inu800 pairs no_comma false parse_links false any_comma false no_and false dou800 ifu800 origargs keyu800 nilu800 then args keyu800 default else args keyu800 yesno origargs keyu800 default endu800 endu800 local checkcomma notu800 argsu82eno_comma local checkand notu800 argsu82eno_and local rewritelinks notu800 argsu82eparse_links local anycomma argsu82eany_comma local su800 origargs 1u800 theu800 input string ifu800 notu800 su800 then return nilu800 empty input returns nilu800 endu800 su800 tostring su800 su800 mwu800u82etextu82edecode su800 true replace html entities tou800 avoid spurious semicolons ifu800 plainfind su800 'data plural "0u800"' then magic data string tou800 return true return singular endu800 ifu800 plainfind su800 'data plural "1u800"' then magic data string tou800 return false return plural endu800 count number ofu800 list items local numlistitems countmatches su800 ' su800*liu800' ifu800 exactly oneu800 then singular ifu800 more than oneu800 then plural ifu800 numlistitems 1u800 then return singular endu800 ifu800 numlistitems 1u800 then return plural endu800 ifu800 "list ofu800" occurs inside ofu800 wlink then itu800 itu800'su800 plural ifu800 mwu800u82eustringu82efind su800 lower ' *list ofu800 ' then return plural endu800 ifu800 "u8d981u8d987u8d8b1u8d8b3u8d8aa" occurs inside ofu800 wlink then itu800 itu800'su800 plural ifu800 mwu800u82eustringu82efind su800 lower ' *u8d981u8d987u8d8b1u8d8b3u8d8aa ' then return plural endu800 fixu800 foru800 trailing bru800 tags passed through template marriage su800 mwu800u82eustringu82egsub su800 ' su800*bru800 * su800* ' ' 1u800' replace allu800 wikilinks with fixed string ifu800 rewritelinks then su800 mwu800u82eustringu82egsub su800 ' bu800 ' 'wikilink' endu800 five conditions anyu800 oneu800 ofu800 them canu800 make theu800 string au800 likely plural oru800 plural local hasbreak mwu800u82eustringu82efind su800 ' su800*bru800' local hassakh mwu800u82eustringu82efind su800 ' u8d8b3u8d8ae ' foru800 theu800 last 4u800 evaluate onu800 string stripped ofu800 wikimarkup su800 getplain su800 local hasbullets countmatches su800 ' * ' 1u800 local multipleqids mwu800u82eustringu82efind su800 'qu800 du800 pu800 su800 qu800 du800 ' hasu800 multiple qids inu800 au800 rowu800 ifu800 hasbullets oru800 multipleqids then return plural endu800 local commapattern anycomma andu800 ' ;u8d88cu8d89b ' oru800 ' du800 ;u8d88cu8d89b du800' semi colon similar tou800 comma local hascomma checkcomma andu800 mwu800u82eustringu82efind su800 commapattern local hasand checkand andu800 mwu800u82eustringu82efind su800 ' su800 andu800 su800' local hasva checkand andu800 mwu800u82eustringu82efind su800 ' u8d88c su800 u8d988 su800' ifu800 hasbreak oru800 hassakh oru800 hascomma oru800 hasand oru800 hasva then return likelyplural endu800 return singular endu800 function pu800u82e_pluralize args args type args 'table' andu800 args oru800 local singularform args 3u800 oru800 argsu82esingular oru800 "" local pluralform args 4u800 oru800 argsu82eplural oru800 "" local likelyform argsu82elikely oru800 pluralform local link args 5u800 oru800 argsu82elink ifu800 link then link tostring link singularform ' '..link..' '..singularform..' ' pluralform ' '..link..' '..pluralform..' ' likelyform ' '..link..' '..likelyform..' ' endu800 ifu800 args 2u800 then return pluralform endu800 local detect pu800u82e_main args ifu800 detect nilu800 then return "" return blank onu800 complete failure endu800 ifu800 detect singular then return singularform elseif detect likelyplural then return likelyform else return pluralform endu800 endu800 function pu800u82emain frame local args getargs frame setfarsiarguments args 'no_comma' 'u8d8a8u8d8afu8d988u8d986 u8daa9u8d8a7u8d985u8d8a7' 'any_comma' 'u8d987u8d8b1 u8daa9u8d8a7u8d985u8d8a7' 'no_and' 'u8d8a8u8d8afu8d988u8d986 u8d988' 'parse_links 'u8d8aau8d8acu8d8b2u8db8cu8d987 u8d9beu8db8cu8d988u8d986u8d8afu8d987u8d8a7' foru800 template return 1u800 ifu800 singular blank ifu800 plural oru800 empty local result pu800u82e_main args ifu800 result nilu800 then return 1u800 endu800 return result singular andu800 1u800 oru800 "" endu800 function pu800u82epluralize frame local args getargs frame setfarsiarguments args 'no_comma' 'u8d8a8u8d8afu8d988u8d986 u8daa9u8d8a7u8d985u8d8a7' 'any_comma' 'u8d987u8d8b1 u8daa9u8d8a7u8d985u8d8a7' 'no_and' 'u8d8a8u8d8afu8d988u8d986 u8d988' 'parse_links 'u8d8aau8d8acu8d8b2u8db8cu8d987 u8d9beu8db8cu8d988u8d986u8d8afu8d987u8d8a7' 'singular' 'u8d985u8d981u8d8b1u8d8af' 'plural' 'u8d8acu8d985u8d8b9' 'likely' 'u8d985u8d8adu8d8aau8d985u8d984' 'link' 'u8d9beu8db8cu8d988u8d986u8d8af' return pu800u82e_pluralize args endu800 return pu800 