Difference between revisions 18626569 and 18626570 on frwiktionarylocal m_languages = mw.loadData("Module:languages") local export = {} -- transliterate the text, if possible function export.translit(lang, text) -- TODO: the table's information should be moved to [[Module:languages]] local translit_modules = { ["ae"] = "Module:Avst-translit", (contracted; show full)end -- Detect the script based on the first alphabetical characters of a string function export.detect_script(text, lang) local m_scripts = mw.loadData("Module:scripts") local langinfo = m_languages[lang] or error("The language code \"" .. lang .. "\" is not valid.") local scFix = false⏎ -- Does this language have more than one script? -- If not, we can bypass the detection for a speed bonus. -- But always do the detection if the script is "None" or "Zyyy" if not (langinfo.scripts[2] or langinfo.scripts[1] == "None" or langinfo.scripts[1] == "Zyyy") then return langinfo.scripts[1], falsescFix end for i, script in ipairs(langinfo.scripts) do local script2check = script:gsub(".-%-", "") -- removes the language code from script name, e.g. "nv-Latn" > "Latn" if script2check == "Latf" or script2check == "Latinx" or script2check == "unicode" then script2check = "Latn" end local scriptinfo = m_scripts[script2check] or error("The script code \"" .. script .. "\" is not valid.") if scriptinfo.characters and mw.ustring.match(text, scriptinfo.characters) then return script, falsescFix end end scFix = (langinfo.scripts[1] ~= "Zyyy" and langinfo.scripts[1] ~= "None")⏎ ⏎ -- not written in native script(s); check for all scripts -- TODO: This is slow; we really shouldn't be doing this! for script, scriptinfo in pairs(m_scripts) do if scriptinfo.characters and mw.ustring.match(text, "[%[%d%p%s]-" .. scriptinfo.characters) then return script, (langinfo.scripts[1] ~= "Zyyy" and langinfo.scripts[1] ~= "None")scFix end end return langinfo.scripts[1], falsescFix end -- Format the categories with the appropriate sort key function export.format_categories(categories, lang, sort_key, sort_base) local langinfo = m_languages[lang] or error("The language code \"" .. lang .. "\" is not valid.") NAMESPACE = NAMESPACE or mw.title.getCurrentTitle().nsText (contracted; show full) i = i + 1 cat = args[i] end return export.format_categories(categories, lang, sort_key) end return export All content in the above text box is licensed under the Creative Commons Attribution-ShareAlike license Version 4 and was originally sourced from https://fr.wiktionary.org/w/index.php?diff=prev&oldid=18626570.
![]() ![]() This site is not affiliated with or endorsed in any way by the Wikimedia Foundation or any of its affiliates. In fact, we fucking despise them.
|