Module:DateI18n: Difference between revisions
From Neodyland Wiki
More actions
Fulfilling edit request by CalendulaAsteraceae. Thanks for helping! |
Fulfilling edit request by CalendulaAsteraceae. |
||
| Line 277: | Line 277: | ||
end | end | ||
return timeStamp, datecode | return timeStamp, datecode | ||
end | |||
local function isValidLangCode(lang) | |||
if not lang then | |||
return false | |||
end | |||
lang = mw.text.trim(lang) | |||
return lang ~= '' and lang ~= '⧼Lang⧽' and mw.language.isValidCode(lang) | |||
end | end | ||
| Line 303: | Line 311: | ||
-- set language | -- set language | ||
if not | if not isValidLangCode(lang) then | ||
-- get user's chosen language | -- get user's chosen language | ||
-- equivalent to {{int:lang}} | |||
lang = mw.getCurrentFrame():callParserFunction("int", "lang") | lang = mw.getCurrentFrame():callParserFunction("int", "lang") | ||
if not | if not isValidLangCode(lang) then | ||
-- if that doesn't work, use the project language | -- if that doesn't work, use the project language | ||
-- this is useful on projects which import this module from Commons | -- this is useful on projects which import this module from Commons | ||
lang = mw.language.getContentLanguage().code | lang = mw.language.getContentLanguage().code | ||
if not | if not isValidLangCode(lang) then | ||
-- if that doesn't work, use English | -- if that doesn't work, use English | ||
lang = "en" | lang = "en" | ||
| Line 437: | Line 446: | ||
-- default values | -- default values | ||
-- Allows to set the html class of the time node where the date is included. This is useful for microformats. | -- Allows to set the html class of the time node where the date is included. This is useful for microformats. | ||
args.class = args.class or 'dtstart' | args.class = args.class or '-' | ||
if args.class == '' then | |||
args.class = 'dtstart' | |||
end | |||
-- By default, pad one- and two-digit years to be 4 digits long, while keeping three-digit years as-is. | -- By default, pad one- and two-digit years to be 4 digits long, while keeping three-digit years as-is. | ||
args.trim_year = args.trim_year or '100-999' | args.trim_year = args.trim_year or '100-999' | ||