Dokumentaci tohoto modulu lze vytvořit na stránce Nápověda:Modul:Language
-- @brief
-- Language object.
--
-- @author
-- ]
local Language = {}
----------------------------------------
local Languages = require( "Module:Languages" )
-- @brief
-- Parses and splits the language tag into appropriate parts.
--
-- @details
-- Very trivial implementation
--
-- @param
-- String langTag Language tag
--
-- @return
-- table Parts of parsed language tag
-- nil If language tag is invalid or any of its part is unknown
function Language._parseLanguageTag( langTag )
local parsedLangTag = {}
local subtagStartPos
local subtagPartPos
local _
_, _, parsedLangTag.lang, subtagStartPos = langTag:find( "^(%l%l%l?)()" )
_, _, parsedLangTag.region, subtagPartPos = langTag:find( "^%-(%u%u)()", subtagStartPos )
_, _, parsedLangTag.script, subtagPartPos = langTag:find( "^%-(%u%l%l%l)()", subtagPartPos or subtagStartPos )
return next( parsedLangTag ) and parsedLangTag
end
function Language._getLanguageFromLanguageTag( langTag )
local parsedLangTag = Language._parseLanguageTag( langTag )
return parsedLangTag and parsedLangTag.lang
end
-- @brief
-- Gets the language direction by language tag.
--
-- @param
-- String langTag Language tag
--
-- @return
-- String Language direction
-- nil If language tag is invalid or any of its language part is unknown
function Language:getDirection( langTag )
local lang = self._getLanguageFromLanguageTag( langTag )
return Languages and Languages.dir or nil
end
-- @brief
-- Gets the language name by language tag.
--
-- @param
-- String langTag Language tag
--
-- @return
-- String Language name
-- nil If language tag is invalid or any of its language part is unknown
function Language:getName( langTag )
local lang = self._getLanguageFromLanguageTag( langTag )
return Languages and Languages.name or nil
end
-- @brief
-- Gets the full language name (including script and region) by language tag.
--
-- @param
-- String langTag Language tag
--
-- @return
-- String Full language name
-- nil If language tag is invalid or any of its parts is unknown
function Language:getFullName( langTag )
local output
local parsedLangTag = self._parseLanguageTag( langTag )
if parsedLangTag then
local lang = Languages and Languages.name
local region = ""
local script = ""
if lang then
output = lang
if parsedLangTag.region then
region = Languages.regions and Languages.regions
end
if parsedLangTag.script then
script = Languages.scripts and Languages.scripts
end
if parsedLangTag.region or parsedLangTag.script then
if region and script then
if ( region ~= "" and script ~= "" ) then
output = output .. " (" .. region .. ", " .. script .. ")"
else
output = output .. " (" .. ( region ~= "" and region or script ) .. ")"
end
else
output = nil
end
end
end
end
return output
end
----------------------------------------
return Language