Module:languages: Difference between revisions

No edit summary
Tag: Reverted
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 136: Line 136:
local export = {}
local export = {}


local debug_track_module = "Module:debug/track"
local etymology_languages_data_module = "Module:etymology languages/data"
local etymology_languages_data_module = "Module:etymology languages/data"
local families_module = "Module:families"
local families_module = "Module:families"
Line 191: Line 192:
check_object = require(utilities_module).check_object
check_object = require(utilities_module).check_object
return check_object(...)
return check_object(...)
end
local function debug_track(...)
debug_track = require(debug_track_module)
return debug_track(...)
end
end


Line 321: Line 327:
uupper = require(string_utilities_module).upper
uupper = require(string_utilities_module).upper
return uupper(...)
return uupper(...)
end
local function track(page)
debug_track("languages/" .. page)
return true
end
end


Line 864: Line 875:


function Language:makeWikipediaLink()
function Language:makeWikipediaLink()
return make_link(self, (self:hasType("conlang") and self:getCanonicalName() or "w:" .. self:getWikipediaArticle()), self:getCanonicalName())
    return make_link(self, (self:hasType("conlang") and self:getCanonicalName() or "w:" .. self:getWikipediaArticle()), self:getCanonicalName())
end
 
function Language:getMainCategoryName()
return self._data.main_category or "lemma"
end
end


Line 875: Line 882:
Language.getCommonsCategory = require(language_like_module).getCommonsCategory
Language.getCommonsCategory = require(language_like_module).getCommonsCategory
return self:getCommonsCategory()
return self:getCommonsCategory()
end
function Language:getMainCategoryName()
    return self._data.main_category or "lemma"
end
end


Line 954: Line 965:
first_sc = get_script(first_sc)
first_sc = get_script(first_sc)
local charset = first_sc.characters
local charset = first_sc.characters
return charset and umatch(text, "[" .. charset .. "]") and first_sc or get_script("None")
return charset and umatch(text, "[" .. ugsub(charset, "%]", "%%]") .. "]") and first_sc or get_script("None")
end
end


Line 1,009: Line 1,021:
-- Count characters by removing everything in the script's charset and comparing to the original length.
-- Count characters by removing everything in the script's charset and comparing to the original length.
local charset = sc.characters
local charset = sc.characters
local count = charset and length - ulen((ugsub(text, "[" .. charset .. "]+", ""))) or 0
local count = charset and length - ulen((ugsub(text, "[" .. charset:gsub("%]", "%%]") .. "]+", ""))) or 0


if count >= length then
if count >= length then
Line 1,610: Line 1,622:
-- FIXME: This probably shouldn't happen but it happens when makeEntryName() receives nil.
-- FIXME: This probably shouldn't happen but it happens when makeEntryName() receives nil.
if pagename == nil then
if pagename == nil then
track("nil-passed-to-logicalToPhysical")
return nil
return nil
end
end
Line 1,732: Line 1,745:
if (not text) or text == "" then
if (not text) or text == "" then
return text
return text
end
if match(text, "<[^<>]+>") then
track("track HTML tag")
end
end
-- Remove directional characters, bold, italics, soft hyphens, strip markers and HTML tags.
-- Remove directional characters, bold, italics, soft hyphens, strip markers and HTML tags.
Line 1,859: Line 1,875:
default module yet, or you want to demonstrate an alternative version of a transliteration module before making it
default module yet, or you want to demonstrate an alternative version of a transliteration module before making it
official. It should not be used in real modules or templates, only for testing. All uses of this parameter are tracked
official. It should not be used in real modules or templates, only for testing. All uses of this parameter are tracked
by [[wikt:Wiktionary:Tracking/languages/module_override]].
by [[Wiktionary:Tracking/languages/module_override]].
'''Known bugs''':
'''Known bugs''':
* This function assumes {tr(s1) .. tr(s2) == tr(s1 .. s2)}. When this assertion fails, wikitext markups like <nowiki>'''</nowiki> can cause wrong transliterations.
* This function assumes {tr(s1) .. tr(s2) == tr(s1 .. s2)}. When this assertion fails, wikitext markups like <nowiki>'''</nowiki> can cause wrong transliterations.
Line 1,872: Line 1,888:
sc = checkScript(text, self, sc)
sc = checkScript(text, self, sc)
if not (sc:isTransliterated() or module_override) then
if not (sc:isTransliterated() or module_override) then
-- temporary tracking to see if/when this gets triggered
track("non-transliterable")
track("non-transliterable/" .. self._code)
track("non-transliterable/" .. sc:getCode())
track("non-transliterable/" .. sc:getCode() .. "/" .. self._code)
return nil
return nil
end
end
Line 1,897: Line 1,918:
-- Incomplete transliterations return nil.
-- Incomplete transliterations return nil.
local charset = sc.characters
local charset = sc.characters
if charset and umatch(text, "[" .. charset .. "]") then
if charset and umatch(text, "[" .. charset:gsub("%]", "%%]") .. "]") then
-- Remove any characters in Latin, which includes Latin characters also included in other scripts (as these are
-- Remove any characters in Latin, which includes Latin characters also included in other scripts (as these are
-- false positives), as well as any PUA substitutions. Anything remaining should only be script code "None"
-- false positives), as well as any PUA substitutions. Anything remaining should only be script code "None"
Line 1,920: Line 1,941:
return m1 .. uupper(m2)
return m1 .. uupper(m2)
end)
end)
end
-- Track module overrides.
if module_override ~= nil then
track("module_override")
end
end


Line 2,260: Line 2,286:
--[==[Finds the language whose code matches the one provided. If it exists, it returns a <code class="nf">Language</code> object representing the language. Otherwise, it returns {{code|lua|nil}}, unless <code class="n">paramForError</code> is given, in which case an error is generated. If <code class="n">paramForError</code> is {{code|lua|true}}, a generic error message mentioning the bad code is generated; otherwise <code class="n">paramForError</code> should be a string or number specifying the parameter that the code came from, and this parameter will be mentioned in the error message along with the bad code. If <code class="n">allowEtymLang</code> is specified, etymology-only language codes are allowed and looked up along with normal language codes. If <code class="n">allowFamily</code> is specified, language family codes are allowed and looked up along with normal language codes.]==]
--[==[Finds the language whose code matches the one provided. If it exists, it returns a <code class="nf">Language</code> object representing the language. Otherwise, it returns {{code|lua|nil}}, unless <code class="n">paramForError</code> is given, in which case an error is generated. If <code class="n">paramForError</code> is {{code|lua|true}}, a generic error message mentioning the bad code is generated; otherwise <code class="n">paramForError</code> should be a string or number specifying the parameter that the code came from, and this parameter will be mentioned in the error message along with the bad code. If <code class="n">allowEtymLang</code> is specified, etymology-only language codes are allowed and looked up along with normal language codes. If <code class="n">allowFamily</code> is specified, language family codes are allowed and looked up along with normal language codes.]==]
function export.getByCode(code, paramForError, allowEtymLang, allowFamily)
function export.getByCode(code, paramForError, allowEtymLang, allowFamily)
-- Track uses of paramForError, ultimately so it can be removed, as error-handling should be done by [[Module:parameters]], not here.
if paramForError ~= nil then
track("paramForError")
end
if type(code) ~= "string" then
if type(code) ~= "string" then
local typ
local typ
Line 2,275: Line 2,305:


local m_data = load_data(languages_data_module)
local m_data = load_data(languages_data_module)
if m_data.aliases[code] or m_data.track[code] then
track(code)
end


local norm_code = normalize_code(code)
local norm_code = normalize_code(code)