« Module:Linguistique » : différence entre les versions

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
mAucun résumé des modifications
0x010D (discussion | contributions)
supprime les langues étrangères pour l'instant
Ligne 1 : Ligne 1 :
-- module d'origine multilingue (voir [[wikidata:Module:Linguistic]], d'où une structure d'apparence un peu comple
-- Ne fonctionne qu'en français. Si besoin est, on peut s'inspirer de [[wikidata:Module:Linguistic]] pour ajouter d'autres langues.


local p = {}
local p = {}
Ligne 19 : Ligne 19 :
end
end


local function langisin(str, lang)
return isin(str, lang .. ' ') -- space is necessary to avoid false positives like zh in zh-hans
end


local function processgender(str)
local function processgender(str)
Ligne 45 : Ligne 42 :
end
end


function p.inparentheses(str, lang)
function p.inparentheses(str)
--todo: define language with exotic parentheses
if (not str) or str == '' then
if str == '' then
return str
return str
else  
else  
return ' (' .. str .. ')'  
return ' (' .. str .. ')'  
-- needs internationalization.
--Needs leading space in Enlgish because as some languages do not use it, it is part of the formatting
end
end
end
end


function p.of(word, lang, raw, gender, number, determiner) -- rough translation of "of" in various languages
function p.of(word, raw, gender, number, determiner)  
-- note that the cases when on "of" is employed varies a lot among languages, so it is more prudent to call this from lang specific function only
if not raw then  
if not raw then  
raw = word
raw = word
Ligne 65 : Ligne 58 :
-- raw is the string without the Wikiformatting so that it correctly analyses the string that is [[:fr:Italie|Italie]] -> 'italie'
-- raw is the string without the Wikiformatting so that it correctly analyses the string that is [[:fr:Italie|Italie]] -> 'italie'
-- any way to automate this ?
-- any way to automate this ?
-- todo: ca to replace Template:Of/ca
if number == 'plural' then
return 'des ' .. word
if lang == 'fr' then
elseif p.vowelfirst(raw) then
if number == 'plural' then
return 'de l\'' .. word
return 'des ' .. word
elseif gender == 'feminine' then
elseif p.vowelfirst(raw) then
return 'de la ' .. word
return 'de l\'' .. word
elseif derterminer then
elseif gender == 'feminine' then
return 'du ' .. word
return 'de la ' .. word
else
elseif derterminer then
return 'de ' .. word
return 'du ' .. word
end
else
return 'de ' .. word
end
end


end
end


function p.noungroup(noun, adj, lang)
function p.noungroup(noun, adj)
if not noun or noun == '' then  
if not noun or noun == '' then  
return nil -- not '' so that it is not counted as a string by mw.listToText
return nil -- not '' so that it is not counted as a string by mw.listToText
end
end
if not adj or adj == ''
return noun .. wordsep(lang) .. adj -- lorsque c'est en français
then return noun
end
-- adjective before the noun
if langisin('de de-at de-ch en en-ca en-gb pl zh zh-hans zh-hant zh-my zh-cn zh-sg zh-tw ', lang) then
return adj .. wordsep(lang) .. noun
-- adjective after the noun
elseif langisin('fr fr-ca es it') then
return noun .. wordsep(lang) .. adj
else
return noun ' (' .. adj .. ')'
end
end
end


Ligne 156 : Ligne 135 :
end
end
end
end
return p.conj(newargs, lang, conjtype)
return p.conj(newargs, conjtype)
end
end


return p
return p

Version du 5 octobre 2014 à 14:15

-- Ne fonctionne qu'en français. Si besoin est, on peut s'inspirer de wikidata:Module:Linguistic pour ajouter d'autres langues.

local p = {} local lang = 'fr'

local vowels = 'aeiouyąăẵằẳặȃắâẫấầẩậãäǟāáàȁǎảẚåǻḁạǡæǣǽĕȇêễếềểệḙẽḛëēḕéḗèȅěẻẹęȩḝǝĭȋîĩḭïḯīíìȉǐỉịįıŏȏôỗốồổộõṏṍöōṑóṓòȍǒỏọǫǭơỡớờởợøǿŭȗûṷũṻṹṵüǖǘǜǚṳūúùȕǔủůụųưữứừửựŷỹÿȳýỳỷẙỵ'

-- i18n local wordor = ' ou ' local wordand = ' et ' local comma = ', ' local fullstop = '. ' local wordsep = ' '

local function isin(str, pattern) if str and pattern and mw.ustring.find(str, pattern, 1, true ) then return true end end


local function processgender(str) if (str == 'f') or (str == 'fem') or (str == 'feminine') then return 'feminine' elseif (str == 'n') or (str == 'neutral') then return 'neutral' else return 'masculine' end end

local function processnumber(str) if (str == 'p') or (str == 'plural') then return 'plural' else return 'singular' end end

function p.vowelfirst (str) if str then return isin(vowels, str[1]) end end

function p.inparentheses(str) if (not str) or str == then return str else return ' (' .. str .. ')' end end

function p.of(word, raw, gender, number, determiner) if not raw then raw = word end gender = processgender(gender) number = processnumber(number) -- raw is the string without the Wikiformatting so that it correctly analyses the string that is Italie -> 'italie' -- any way to automate this ?


if number == 'plural' then return 'des ' .. word elseif p.vowelfirst(raw) then return 'de l\ .. word elseif gender == 'feminine' then return 'de la ' .. word elseif derterminer then return 'du ' .. word else return 'de ' .. word end

end

function p.noungroup(noun, adj) if not noun or noun == then return nil -- not so that it is not counted as a string by mw.listToText end return noun .. wordsep(lang) .. adj -- lorsque c'est en français end

function p.quickconj(args, conjtype) local separator, conjunction

-- cas où separator ~= conj if (not conjtype) or conjtype == 'and' then separator, conjunction = comma, wordand elseif conjtype == 'or' then separator, conjunction = comma, wordor end if (separator and conjunction) then return mw.text.listToText(args, conjunction, separator) end -- autres cas if conjtype == 'comma' then separator = comma else separator = conjtype end return table.concat(args, separator) end

function p.conj(args, conjtype) if (not args) or (#args == 0) then return nil end local newargs = {} for i, j in pairs(args) do if type(j) ~= 'nil' then table.insert(newargs, j) end end args = newargs return p.quickconj(newargs, conjtype, lang) end

function p.conjfromWiki(frame) args = frame.args if not args or not args[1] then args = mw.getCurrentFrame():getParent().args end local conjtype = args.type newargs = {} -- transform args metatable into a table so it can be concetenated for i, j in pairs(args) do if type(i) == 'number' then j = mw.text.trim(j) if j ~= then table.insert(newargs, j) end else if i ~= 'type' and i ~= 'lang' then return error('bad parameter in template:Conj:' .. i), end end end return p.conj(newargs, conjtype) end

return p