@@ -183,17 +183,44 @@ end
183183
184184-- simple plural s function for localisation
185185function cry_pls (str , vars )
186- if string.sub (str , 1 , 1 ) == " p" or string.sub (str , 1 , 1 ) == " s" or string.sub (str , 1 , 1 ) == " y" then
187- num = vars [tonumber (string.sub (str , 2 , - 1 ))]
188- if num then
189- if math.abs (to_big (num ) - 1 ) > to_big (0.001 ) then
190- return string.sub (str , 1 , 1 ) == " y" and " ies" or " s"
186+ local inside = str :match (" <(.-)>" ) -- finds args
187+ local _table = {}
188+ if inside then
189+ for v in inside :gmatch (" [^,]+" ) do -- adds args to array
190+ table.insert (_table , v )
191+ end
192+ end
193+ local num = vars [tonumber (string.match (str , " >(%d+)" ))] -- gets the number outside angle brackets, and its corresponding variable
194+ local plural = _table [1 ] -- default
195+ local checks = { [1 ] = " =" }
196+ if # _table > 1 then
197+ for i = 2 , # _table do
198+ local isnum = tonumber (_table [i ])
199+ if isnum then
200+ checks [isnum ] = " >" .. (_table [i + 1 ] or " " )
201+ i = i + 1
202+ elseif i == 2 then
203+ checks [1 ] = " =" .. _table [i ]
191204 else
192- return string.sub (str , 1 , 1 ) == " y" and " y" or " "
205+ print (" Unexpected string: " .. _table [i ])
206+ end
207+ end
208+ end
209+ local function fch (str , c )
210+ return string.sub (str , 1 , 1 ) == c -- gets first char and returns boolean
211+ end
212+ for k , v in pairs (checks ) do
213+ if fch (v , " =" ) then
214+ if math.abs (to_big (num ) - k ) < to_big (0.001 ) then
215+ return string.sub (v , 2 , - 1 )
216+ end
217+ elseif fch (v , " >" ) then
218+ if to_big (num ) >= to_big (k - 0.001 ) then
219+ return string.sub (v , 2 , - 1 )
193220 end
194221 end
195222 end
196- return false -- idk it doesn't really matter
223+ return plural
197224end
198225
199226-- generate a random edition (e.g. Antimatter Deck)
0 commit comments