Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Dir: Difference between revisions

From Neodyland Wiki
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


local function isRTL(code)
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

Module documentation[ create · purge ]
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
Cookies help us deliver our services. By using our services, you agree to our use of cookies.