Module:Dir: Difference between revisions
From Neodyland Wiki
More actions
allow overrides for RTL codes specified in Module:Dir/RTL overrides |
allow isRTL to be accessed directly from other Lua modules |
||
| Line 23: | Line 23: | ||
end | end | ||
function p.isRTL(code) | |||
local success, ret = pcall(function () | local success, ret = pcall(function () | ||
return rtlOverrides[code] or mw.language.new(code):isRTL() | return rtlOverrides[code] or mw.language.new(code):isRTL() | ||
| Line 33: | Line 33: | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local code = trimAndRemoveBlanks(args[1]) | local code = trimAndRemoveBlanks(args[1]) | ||
if isRTL(code) then | if p.isRTL(code) then | ||
return trim(args[2]) or 'rtl' | return trim(args[2]) or 'rtl' | ||
else | else | ||
Revision as of 04:59, 21 February 2015
This documentation is transcluded from Module:Dir/doc.
-- This module implements [[Template:Dir]].
local rtlOverrides = mw.loadData('Module:Dir/RTL overrides')
local p = {}
local function trim(s)
if s then
return s:match('^%s*(.-)%s*$')
else
return nil
end
end
local function trimAndRemoveBlanks(s)
if s then
s = trim(s)
if s ~= '' then
return s
end
end
return nil
end
function p.isRTL(code)
local success, ret = pcall(function ()
return rtlOverrides[code] or mw.language.new(code):isRTL()
end)
return success and ret
end
function p.main(frame)
local args = frame:getParent().args
local code = trimAndRemoveBlanks(args[1])
if p.isRTL(code) then
return trim(args[2]) or 'rtl'
else
return trim(args[3]) or 'ltr'
end
end
return p