Sətir 1: |
Sətir 1: |
− | -- Ordinals for Azerbaijani by RexxS
| + | local p = {} |
− | -- Takes a number and returns its ordinal.
| + | |
| + | local yesno = require('Module:Yesno') |
| | | |
| local suffixes = { | | local suffixes = { |
Sətir 7: |
Sətir 8: |
| } | | } |
| | | |
− | function ordinal(number) | + | function p.Ordinal(frame) |
− | local suffix | + | local args = frame.args |
− | if number == 0 then | + | if args[1] == nil then |
− | suffix = "cı"
| + | args = frame:getParent().args |
− | elseif number % 1000 == 0 then
| + | end |
− | suffix = "ci"
| + | if args[1] == nil then |
− | elseif number %100 == 0 then
| + | args[1] = "{{{1}}}" |
− | suffix = "cü"
| + | end |
− | elseif number %10 == 0 then
| + | return p._ordinal(args[1], (args[2] == 'd'), yesno(args.sup)) |
− | suffix = suffixes[number % 100]
| + | end |
− | else
| + | |
− | suffix = suffixes[number %10] or ""
| + | function p._ordinal(n, d, sup) |
| + | local x = tonumber(mw.ustring.match(n, "(%d*)%W*$")) |
| + | local suffix = "ci" |
| + | if x then |
| + | local mod10 = math.abs(x) % 10 |
| + | local mod100 = math.abs(x) % 100 |
| + | local mod1000 = math.abs(x) % 1000 |
| + | if x == 0 then |
| + | suffix = "cı" |
| + | elseif mod1000 == 0 then |
| + | suffix = "ci" |
| + | elseif mod100 == 0 then |
| + | suffix = "cü" |
| + | elseif mod10 == 0 then |
| + | suffix = suffixes[x % 100] |
| + | else |
| + | suffix = suffixes[x %10] or "" |
| + | end |
| + | end |
| + | if sup then |
| + | suffix = "<sup>" .. suffix .. "</sup>" |
| end | | end |
− | return number .. "-" .. suffix | + | return n .. '-' .. suffix |
| end | | end |
| | | |
Sətir 26: |
Sətir 47: |
| function inYear( year ) | | function inYear( year ) |
| if year >= 0 then | | if year >= 0 then |
− | return ordinal(year) | + | return p._ordinal(year) |
| else | | else |
| year = -year | | year = -year |
− | return 'e.ə. ' .. ordinal(year) | + | return 'e.ə. ' .. p._ordinal(year) |
| end | | end |
| + | end |
| + | |
| + | function makeOrdinal( year ) |
| + | return p._ordinal(year) |
| end | | end |
| | | |
Sətir 40: |
Sətir 65: |
| return displaySuffixMonth .. 'da' | | return displaySuffixMonth .. 'da' |
| end | | end |
− | end
| |
− |
| |
− | -- Just for testing by allowing a #invoke: call
| |
− | p = {}
| |
− |
| |
− | function p.Ordinal(frame)
| |
− | number = tonumber(frame.args[1] or frame.args.number) or 0
| |
− | return ordinal(number)
| |
| end | | end |
| | | |
| return p | | return p |