« Module:traduction » et « Module:bac à sable » : différence entre les pages
(Différence entre les pages)
Contenu supprimé Contenu ajouté
Ajout de animé/inanimé (pour le basque) |
Aucun résumé des modifications |
||
Ligne 1 : | Ligne 1 : | ||
b = require('Module:bases') |
|||
lang = require('Module:bac à sable/langues') |
|||
local m_langs = require("Module:langues") |
|||
local p = {} |
local p = {} |
||
function _fait_span_trad(texte, code) |
|||
local cats = {} |
|||
if (texte ~= nil and code ~= nil) then |
|||
-- List of languages for which the "’" must be kept |
|||
return '<span class="trad-' .. code .. '">' .. texte .. '</span>' |
|||
local keepApos = { fr = true, de = true, } |
|||
-- Shows categories when true. |
|||
-- For debugging purposes, deactivate *before* saving. |
|||
local DEBUG = false |
|||
--- Returns the category with the given name. |
|||
--- @param categoryName string The category’s name. |
|||
--- @param sortingKey string The sorting key. |
|||
--- @param asLink boolean Whether the category should be a link or not. |
|||
--- @return string The category. |
|||
local function getCategory(categoryName, sortingKey, asLink) |
|||
if DEBUG then |
|||
if sortingKey then |
|||
return m_bases.fait_categorie(categoryName, nil, true) .. "(" .. sortingKey .. ")" |
|||
else |
else |
||
return '' |
|||
return m_bases.fait_categorie(categoryName, nil, true) |
|||
end |
end |
||
else |
|||
return m_bases.fait_categorie_contenu(categoryName, sortingKey, asLink) |
|||
end |
|||
end |
end |
||
-- Fonction pour écrire l'équivalent du modèle T |
|||
--- Formats a language name. |
|||
function p.T(frame) |
|||
--- @param langName string The language’s name. |
|||
-- Récupération des variables nécessaires à la création du titre |
|||
--- @param langCode string The language’s code. |
|||
local args = frame:getParent().args |
|||
--- @return string The formated language name. |
|||
args = b.trim_parametres(args) |
|||
local function formatLanguageName(langName, langCode) |
|||
local code = args[1] |
|||
if langName and langCode then |
|||
local trier = false |
|||
return mw.ustring.format('<span class="trad-%s">%s</span>', langCode, langName) |
|||
if (args[2] == 'trier') then trier = true end |
|||
else |
|||
local article = mw.title.getCurrentTitle() |
|||
return "" |
|||
-- Pas de code de langue, indispensable |
|||
if (code == nil or code == '') then |
|||
return '[[WT:Liste des langues|Langue à préciser]]' |
|||
end |
|||
-- A-t-on une langue correspondant au code ? |
|||
local langue = lang.get_nom(code) |
|||
local textet = {} |
|||
-- Oui : écrit le texte |
|||
if (langue ~= nil and langue ~= '') then |
|||
table.insert(textet, b.ucfirst(langue)) |
|||
-- Catégories |
|||
local newcattext = trier and 'Wiktionnaire:Traductions à trier en ' or 'Traductions en ' |
|||
table.insert(textet, b.fait_categorie_contenu(newcattext .. langue)) |
|||
-- Langue sans code! Catégorisée pour la retrouver |
|||
else |
|||
table.insert(textet, '<i><font color="red">' .. code .. '</font></i>[[WT:Liste des langues|*]]') |
|||
table.insert(textet, b.fait_categorie_contenu('Wiktionnaire:Langues sans code', code)) |
|||
end |
|||
texte = _fait_span_trad(table.concat(textet), code) |
|||
return texte |
|||
end |
end |
||
--------------------------------------------------------------------------------------------------------- |
|||
--- Function for the template {{T}}. |
|||
-- Fonctions pour créer les éléments de trad_defaut |
|||
--- frame.args[1] (string): Language code. |
|||
function _fait_lien_local(code_langue, mot, dif) |
|||
--- frame.args[2] (string): If equal to "trier", tells that this translation has to be sorted by users. |
|||
local texte_lien |
|||
--- @return string Template’s code. |
|||
if dif ~= nil and dif ~= '' then |
|||
function p.templateT(frame) |
|||
texte_lien = dif |
|||
local args = m_params.process(frame:getParent().args, { |
|||
else |
|||
texte_lien = mot |
|||
end |
|||
local texte_final = '[[' .. mot .. '#' .. code_langue .. '|' .. '<span lang="' .. code_langue .. '">' .. texte_lien .. '</span>' .. ']]' |
|||
local langCode = args[1] |
|||
return texte_final |
|||
local sort = args[2] == "trier" |
|||
-- Manque dif, et un <span lang="">, à faire par une fonction de base |
|||
-- Language code is mandatory. |
|||
if not langCode then |
|||
return "[[WT:Liste des langues|Langue à préciser]]" |
|||
.. getCategory("Wiktionnaire:Traductions T sans langue précisée") |
|||
end |
|||
local langName = m_langs.get_nom(langCode) |
|||
local formatedText |
|||
local category |
|||
if langName then |
|||
formatedText = m_bases.ucfirst(langName) |
|||
local categoryNamePrefix = sort and "Wiktionnaire:Traductions à trier en " or "Traductions en " |
|||
category = getCategory(categoryNamePrefix .. langName) |
|||
-- Undefined language code, categorize for easy checking. |
|||
else |
|||
formatedText = mw.ustring.format('<i><span style="color:red">%s</span></i>[[WT:Liste des langues|*]]', langCode) |
|||
category = getCategory("Wiktionnaire:Traductions T avec code langue non défini", langCode) |
|||
end |
|||
return formatLanguageName(formatedText, langCode) .. category |
|||
end |
end |
||
function _fait_asterisque(code_langue, mot, statut) |
|||
--- Generates the link pointing to another Wiktionary. |
|||
-- Dessine l'astérisque selon le statut de l'article dans le Wiktionnaire correspondant |
|||
--- @param langCode string Word’s language code. |
|||
local asterisque = '' |
|||
--- @param word string The word to link to. |
|||
--- @param status string The status (either "existe", "inconnu", "absent", "" or nil). |
|||
-- Destination du lien |
|||
--- @return string The outgoing link. |
|||
-- Corriger le lien pour les wikis spéciaux |
|||
local function generateOutgoingLink(langCode, word, status) |
|||
local destination = ':' .. (lang.get_lien_Wikimedia(code_langue) or code_langue) .. ':' .. mot |
|||
local displayedText = "" |
|||
if (not lang.wikt_existe(code_langue)) then |
|||
statut = 'nowikt' |
|||
end |
|||
-- Pas de statut, ou statut du Wiki inconnu ? Ne rien afficher |
|||
-- Link destination |
|||
if (statut == '' or statut == nil) then |
|||
local wikiLangCode = m_langs.get_lien_Wikimedia(langCode) or langCode |
|||
asterisque = '' |
|||
if not keepApos[langCode] then |
|||
destination = nil |
|||
word = mw.ustring.gsub(word, "[’ʼ]", "'") -- apostrophes dactylographique et modificative |
|||
-- Pas de Wiki ? |
|||
local destination = mw.ustring.format(":%s:%s", wikiLangCode, word) |
|||
elseif (statut == 'nowikt') then |
|||
asterisque = '<span class="trad-nowikt">(*)</span>' |
|||
if not m_langs.has_wiktionary(langCode) and langCode ~= 'conv' then |
|||
destination = 'Wiktionnaire:Pas de wiktionnaire dans cette langue' |
|||
displayedText = '<span class="trad-nowikt">(*)</span>' |
|||
elseif (statut == 'existe') then |
|||
destination = "Wiktionnaire:Pas de wiktionnaire dans cette langue" |
|||
asterisque = '<span class="trad-existe">(' .. code_langue .. ')</span>' |
|||
elseif status == "existe" then |
|||
elseif (statut == 'inconnu') then |
|||
displayedText = mw.ustring.format('<span class="trad-existe">(%s)</span>', wikiLangCode) |
|||
asterisque = '<span class="trad-inconnu">(' .. code_langue .. ')</span>' |
|||
elseif status == "inconnu" then |
|||
elseif (statut == 'absent') then |
|||
displayedText = mw.ustring.format('<span class="trad-inconnu">(%s)</span>', wikiLangCode) |
|||
asterisque = '<span class="trad-absent">(' .. code_langue .. ')</span>' |
|||
elseif status == "absent" then |
|||
end |
|||
displayedText = mw.ustring.format('<span class="trad-absent">(%s)</span>', wikiLangCode) |
|||
local texte_final = destination and '<span class="trad-exposant">[[' .. destination .. '|' .. asterisque .. ']]</span>' or '' |
|||
displayedText = "" |
|||
return texte_final |
|||
destination = nil |
|||
end |
|||
return destination |
|||
and mw.ustring.format('<span class="trad-exposant">[[%s|%s]]</span>', destination, displayedText) |
|||
or "" |
|||
end |
end |
||
function _fait_ecrit_traditionnel(code_langue, tradi) |
|||
--- Formats the given text as traditional script (mainly for Chinese). |
|||
if (tradi == nil or tradi == '') then return nil end |
|||
--- @param langCode string The language code. |
|||
--- @param word string The word to format. |
|||
local destination = tradi .. '#' .. code_langue |
|||
--- @return string The formated word. |
|||
local affichage = tradi |
|||
local function formatTraditionalScript(langCode, word) |
|||
-- Manque un <span lang="">, à faire par une fonction de base |
|||
if not word then |
|||
local texte_final = '[[' .. destination .. '|' .. affichage .. ']]' |
|||
return nil |
|||
return texte_final |
|||
end |
|||
-- Traditional Chinese is better displayed by browsers when using the code zh-Hant. |
|||
if langCode == "zh" then |
|||
langCode = "zh-Hant" |
|||
elseif langCode == "ko" then |
|||
langCode = "ko-Hani" |
|||
end |
|||
-- Mark the text as “traditional” for gadgets. |
|||
local shownText = mw.ustring.format('<span class="ecrit_tradi">%s</span>', word) |
|||
return m_bases.lien_modele(word, langCode, nil, shownText, true) |
|||
end |
end |
||
function _fait_transcrit(code_langue, transc, code_lang_R) |
|||
--- Formats a transcription. |
|||
if (transc == nil or transc == '' or code_langue == nil) then return nil end |
|||
--- @param langCode string Transcription’s language code. |
|||
--- @param transcription string Text to format. |
|||
local lang = code_lang_R or code_langue .. '-Latn' |
|||
--- @param traditionalLangCode string Optional language code for traditional scripts. |
|||
local texte_final = '<span lang="' .. lang .. '">' .. transc .. '</span>' |
|||
--- @return string The formated transcription. |
|||
return texte_final |
|||
local function formatTranscription(langCode, transcription, traditionalLangCode) |
|||
if not transcription or not langCode then |
|||
return nil |
|||
end |
|||
local lang = traditionalLangCode or langCode .. "-Latn" |
|||
return m_bases.balise_langue(transcription, lang) |
|||
end |
end |
||
-- Fonction pour écrire l'équivalent de trad/défaut |
|||
--- Returns the full gender label for the given code. |
|||
function p.trad_defaut(frame) |
|||
--- @param gender string Gender code. |
|||
-- Récupération des variables |
|||
--- @return string The full gender label. |
|||
local args = frame.args |
|||
local function formatGender(gender) |
|||
local argsnum = b.trim_parametres(args) -- trim les paramètres numériques |
|||
if not gender then |
|||
local code_langue = argsnum[1] -- Code langue |
|||
end |
|||
local code_lang_s = args['lang-s'] -- Code langue plus précis (rare) PAS UTILISÉ ? |
|||
local code_lang_R = args['lang-R'] or args['lang-tr'] -- Code langue du terme traditionnel (chinois et coréen) |
|||
-- List of authorized genders and associated numbers |
|||
local gendersList = { |
|||
local mot = argsnum[2] -- Le terme traduit |
|||
["m"] = "masculin", |
|||
local dif = args['dif'] -- Affichage alternatif du terme traduit (rare) |
|||
["f"] = "féminin", |
|||
local tradi = args['tradi'] -- Terme traditionnel (chinois et coréen) |
|||
["n"] = "neutre", |
|||
local transc = args['R'] or args['tr'] -- Transcription du terme traduit |
|||
["c"] = "commun", |
|||
["s"] = "singulier", |
|||
local statut = args['statut'] -- Remplace "color", voir les statuts possibles dans _fait_asterisque |
|||
["p"] = "pluriel", |
|||
local nocat = (args['nocat'] and true or false) -- Pas catégorisé (vraiment utile ?) |
|||
["d"] = "duel", |
|||
["a"] = "animé", |
|||
-- Vérification des paramètres |
|||
["i"] = "inanimé", |
|||
if (code_langue == nil or code_langue == '') then |
|||
["mf"] = "masculin et féminin identiques", |
|||
return '[[WT:Liste des langues|Langue à préciser]] (paramètre 1)' |
|||
["mp"] = "masculin pluriel", |
|||
end |
|||
["fp"] = "féminin pluriel", |
|||
["mfp"] = "masculin et féminin pluriel", |
|||
-- Mot par défaut = titre de l'article |
|||
["np"] = "neutre pluriel", |
|||
if (mot == nil or mot =='') then |
|||
["ma"] = "masculin animé", |
|||
local article = mw.title.getCurrentTitle() |
|||
["mi"] = "masculin inanimé", |
|||
mot = article.text |
|||
["fa"] = "féminin animé", |
|||
end |
|||
["fi"] = "féminin inanimé", |
|||
["na"] = "neutre animé", |
|||
-- Préparation du texte à afficher |
|||
["ni"] = "neutre inanimé", |
|||
local lien_local = _fait_lien_local(code_langue, mot, dif) |
|||
} |
|||
local asterisque = _fait_asterisque(code_langue, mot, statut) |
|||
local ecrit_traditionnel = tradi and _fait_ecrit_traditionnel(code_langue, tradi) or nil |
|||
if gendersList[gender] then |
|||
local transcrit = transc and _fait_transcrit(code_langue, transc, code_lang_R) or nil |
|||
return mw.ustring.format("''%s''", gendersList[gender]) |
|||
-- Création du texte à afficher |
|||
table.insert(cats, getCategory("Wiktionnaire:Traductions avec genre inexistant", gender)) |
|||
local textet_final = {lien_local} |
|||
return "" |
|||
if (asterisque) then table.insert(textet_final, ' ' .. asterisque) end |
|||
end |
|||
if (ecrit_traditionnel) then table.insert(textet_final, ' (' .. ecrit_traditionnel .. ')') end |
|||
if (transcrit) then table.insert(textet_final, ' (' .. transcrit .. ')') end |
|||
return table.concat(textet_final) |
|||
end |
end |
||
-- Interface à utiliser dans les modèles trad, trad+, trad-, trad-- |
|||
function p.trad(frame) |
|||
--- @param status string Status of the interwiki link. |
|||
-- Récupère les arguments du modèle |
|||
--- @param langCode string Translation’s language code. |
|||
local par_model = frame:getParent() |
|||
--- @param word string The translation. |
|||
--- @param gender string Word’s gender. |
|||
-- Ajoute le statut |
|||
--- @param alternativeText string Alternative text to display instead of the word. |
|||
par_model.args['statut'] = frame.args['statut'] |
|||
--- @param transcription string Word’s transcription. |
|||
return p.trad_defaut(par_model) |
|||
--- @param traditionalLangCode string Language code for traditional script if any (for Chinese and Korean). |
|||
--- @param traditionalTerm string Word for traditional script (for Chinese and Korean). |
|||
--- @return string Template’s code. |
|||
function p._templateTrad(status, langCode, word, gender, alternativeText, transcription, traditionalLangCode, traditionalTerm) |
|||
if not langCode then |
|||
table.insert(cats, getCategory("Wiktionnaire:Traductions sans langue précisée")) |
|||
return '<span style="color:red;">[[WT:Liste des langues|Langue à préciser]] (paramètre 1)</span>' |
|||
elseif m_langs.get_nom(langCode) == nil then |
|||
table.insert(cats, getCategory("Wiktionnaire:Traductions trad avec code langue non défini")) |
|||
end |
|||
local localLink = "" |
|||
local superscriptText = "" |
|||
if not word then |
|||
table.insert(cats, getCategory("Wiktionnaire:Traductions sans traduction précisée")) |
|||
localLink = '<span style="color:red">pas de traduction précisée (paramètre 2)</span>' |
|||
else |
|||
localLink = m_bases.lien_modele(word, langCode, nil, alternativeText, true) |
|||
superscriptText = generateOutgoingLink(langCode, word, status) |
|||
end |
|||
local formatedTraditionalScript = traditionalTerm and formatTraditionalScript(langCode, traditionalTerm) or nil |
|||
local formatedTranscription = transcription and formatTranscription(langCode, transcription, traditionalLangCode) or nil |
|||
local formatedGender = formatGender(gender) |
|||
local finalText = localLink |
|||
if superscriptText then |
|||
finalText = finalText .. " " .. superscriptText |
|||
end |
|||
if formatedTraditionalScript then |
|||
finalText = finalText .. " (" .. formatedTraditionalScript .. ")" |
|||
end |
|||
if formatedTranscription then |
|||
finalText = finalText .. " " .. formatedTranscription |
|||
end |
|||
if formatedGender then |
|||
finalText = finalText .. " " .. formatedGender |
|||
end |
|||
return finalText |
|||
end |
|||
--- Generates the code for the templates {{trad}}, {{trad+}}, {{trad-}} and {{trad--}}. |
|||
--- frame.args["statut"] (string): Status of the interwiki link. |
|||
--- parent frame.args[1] (string): Translation’s language code. |
|||
--- parent frame.args[2] (string): The translation. |
|||
--- parent frame.args[3] (string): Word’s gender. |
|||
--- parent frame.args["dif"] (string): Alternative text to display instead of the word. |
|||
--- parent frame.args["tr"]/parent frame.args["R"] (string): Word’s transcription. |
|||
--- parent frame.args["lang-tr"]/parent frame.args["lang-R"] (string): Language code for traditional script if any (for Chinese and Korean). |
|||
--- parent frame.args["tradi"] (string): Word for traditional script (for Chinese and Korean). |
|||
--- @return string Template’s code. |
|||
function p.templateTrad(frame) |
|||
local status = m_params.process(frame.args, { |
|||
["statut"] = { enum = { "nowikt", "existe", "inconnu", "absent", nil } }, |
|||
})["statut"] |
|||
local args = m_params.process(frame:getParent().args, { |
|||
[1] = {}, |
|||
[2] = {}, |
|||
[3] = {}, |
|||
["lang-tr"] = {}, |
|||
["lang-R"] = { alias_of = "lang-tr" }, |
|||
["tr"] = {}, |
|||
["R"] = { alias_of = "tr" }, |
|||
["dif"] = {}, |
|||
["tradi"] = {}, |
|||
}) |
|||
local langCode = args[1] |
|||
local traditionalLangCode = args["lang-tr"] |
|||
local word = args[2] |
|||
local alternativeText = args["dif"] |
|||
local traditionalTerm = args["tradi"] |
|||
local transcription = args["tr"] |
|||
local gender = args[3] |
|||
local wikicode = p._templateTrad(status, langCode, word, gender, alternativeText, transcription, traditionalLangCode, traditionalTerm) |
|||
return wikicode .. table.concat(cats) |
|||
end |
end |
||