「モジュール:Linguistic」の版間の差分

ナビゲーションに移動 検索に移動
apply changes to noungroup function requested at the talk page
(1版)
 
bsd>Jarekt
(apply changes to noungroup function requested at the talk page)
1行目: 1行目:
-- some simple internationalization that can be called by other modules
--[[
  __  __          _      _        _    _                  _    _  _     
|  \/  | ___  __| |_  _| | ___ _| |  (_)_ __  __ _ _  _(_)___| |_(_) ___
| |\/| |/ _ \ / _` | | | | |/ _ (_) |  | | '_ \ / _` | | | | / __| __| |/ __|
| |  | | (_) | (_| | |_| | |  __/_| |___| | | | | (_| | |_| | \__ \ |_| | (__
|_|  |_|\___/ \__,_|\__,_|_|\___(_)_____|_|_| |_|\__, |\__,_|_|___/\__|_|\___|
                                                  |___/                       
Simple internationalization functions that can be called by other modules.
This Module was copied from Wikimedia Commons, so please request changes there.


local p = {}
Maintainers:
local f = require('Module:Fallback')
* Zolo - original version
* Jarekt


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


function comma(lang)
-- ==================================================
m = mw.message.newFallbackSequence( "comma-separator" )
-- === Internal functions ===========================
m:inLanguage(lang)
-- ==================================================
return m:plain()
end


function wordand(lang)
local function langSwitch(list,lang)
local andtable = { -- languages with a problem with the MediaWiki:And
local langList = mw.language.getFallbacksFor(lang)
['pl'] = ' i',
table.insert(langList,1,lang)
['no'] = ' og',
for i,language in ipairs(langList) do
['zh'] = '和',
if list[language] then
['ja'] = 'および'
return list[language]
}
end
if andtable[lang] then
return andtable[lang]
end
end
m = mw.message.newFallbackSequence( "and" )
return nil
m:inLanguage(lang)
return m:plain()
end
end


function wordsep(lang) -- default separator between words
-- ==================================================
m = mw.message.newFallbackSequence( "Word-separator" )
-- === External functions ===========================
m:inLanguage(lang)
-- ==================================================
return m:plain()
local p = {}
end


function isin(str, pattern)
function p.vowelfirst (str)
if str and pattern and mw.ustring.find(str, pattern, 1, true ) then
if str then
return true
local vowels = 'aeiouyąăẵằẳặȃắâẫấầẩậãäǟāáàȁǎảẚåǻḁạǡæǣǽĕȇêễếềểệḙẽḛëēḕéḗèȅěẻẹęȩḝǝĭȋîĩḭïḯīíìȉǐỉịįıŏȏôỗốồổộõṏṍöōṑóṓòȍǒỏọǫǭơỡớờởợøǿŭȗûṷũṻṹṵüǖǘǜǚṳūúùȕǔủůụųưữứừửựŷỹÿȳýỳỷẙỵ'
end
str = mw.ustring.lower(mw.ustring.sub(str,1,1))
end
return mw.ustring.find(vowels, str, 1, true )  
 
function langisin(str, lang)
return isin(str, lang .. ' ') -- space is necessary to avoid false positives like zh in zh-hans
end
 
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
end
end


function processnumber(str)
function p.inparentheses(str)
if (str == 'p') or (str == 'plural') then
if (not str) or (str == "") then
return 'plural'
return nil
else
return 'singular'
end
end
return "(".. str .. ")" -- same in all languages  ?
end
end
function p.vowelfirst (str)
if str then return isin(vowels, str[1]) end
end


function p.of(word, lang, raw, gender, number, determiner) -- rough translation of "of" in various languages
function p.of(word, lang, raw, gender, number, determiner) -- rough translation of "of" in various languages
-- 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
-- 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 or mw.text.trim(raw) == "" then  
raw = word
local args = {}
local Delink = require('Module:Delink')._delink
args[1] = word
raw = mw.ustring.lower(Delink(args))
end
end
gender = processgender(gender)
 
number = processnumber(number)
-- 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 lang == 'fr' then  
if lang == 'fr' then  
if number == 'plural' then
local yesno = require('Module:Yesno')
return 'des ' .. word
determiner = yesno(determiner,false)
elseif p.vowelfirst(raw) then
 
return 'de l\'' .. word
if determiner then
elseif gender == 'feminine' then
if string.sub(number or '',1,1)=='p' then -- number == 'plural'
return 'de la ' .. word
return 'des ' .. word
elseif derterminer then
elseif p.vowelfirst(raw) then
return 'du ' .. word
return 'de l’' .. word
elseif string.sub(gender or '',1,1)=='f' then -- gender == 'feminine'
return 'de la ' .. word
else
return 'du ' .. word
end
else
if p.vowelfirst(raw) then
return 'd’' .. word
else
return 'de ' .. word
end
end
elseif lang == 'ca' then
-- implement [[Template:Of/ca]] or  https://ca.wikipedia.org/wiki/Plantilla:Deod%27/base for case where "{{{context}}}" is "en" (default on Commons)
if ( p.vowelfirst(raw) and not mw.ustring.find( 'ia|ià|ie|io|iu|ua|ue|ui|uí|uï|uo|ya|ye|yi|yo|yu|', mw.ustring.sub(raw,1,2) .. '|')) then
return 'd\'' .. word
else
else
return 'de ' .. word
return 'de ' .. word
102行目: 102行目:
return p.of(args.word, args.lang, args.raw, args.gender, args.number, args.determiner)
return p.of(args.word, args.lang, args.raw, args.gender, args.number, args.determiner)
end
end
function p.noungroup(noun, adj, lang)
function p.noungroup(noun, adj, lang)
if not noun or noun == '' then  
if not noun or noun == '' then  
109行目: 110行目:
then return noun
then return noun
end
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
local wordsep = mw.message.new( "Word-separator" ):inLanguage(lang):plain()
return adj .. wordsep(lang) .. noun
-- Assign order of words per language: 1- means adjective before the noun and 2 means adjective after the noun
-- adjective after the noun
-- original source for many: language subpages of [[Template:Technique]]
elseif langisin('fr fr-ca es it') then
-- corrections to that using https://wals.info/feature/87A, still different:
return noun .. wordsep(lang) .. adj
-- * vi: WALS says 2
else
-- gl isn't consistent in [[Template:Technique/gl]], but seems to be 2
return noun ' (' .. adj .. ')'
local LUT = {ar=2, ca=2, cs=1, da=1, de=1, el=1, en=1, es=2, et=1, fi=1, fr=2,
gl=2, he=2, hu=1, it=2, ja=1, la=2, mk=1, nds=1, nb=1, nl=1, no=1, pl=1, pt=2,
ro=2, ru=1, scn=2, sk=1, sl=1, sr=1, sv=1, sw=1, tr=1, vec=1, vi=1, zh=1}
local case = LUT[lang]
if case==1 then     -- adjective before the noun
return adj .. wordsep .. noun
elseif case==2 then -- adjective after the noun
return noun .. wordsep .. adj
else               -- order unknown
return noun .. ' (' .. adj .. ')'
end
end
end
end


function p.conj(args, lang, conjtype)
function p.conj(args, lang, conjtype)
local comma    = mw.message.new( "comma-separator"):inLanguage(lang):plain()
local wordsep  = mw.message.new( "Word-separator" ):inLanguage(lang):plain()
local andtable = { ar=' و', he=' ו', ja='および', pl=' i '} -- languages with a problem with the MediaWiki:And
if conjtype == 'comma' then
if conjtype == 'comma' then
return mw.text.listToText(args, comma(lang), comma(lang))
return mw.text.listToText(args, comma, comma)
elseif conjtype == 'or' then  
elseif conjtype == 'or' then  
return mw.text.listToText(args, comma(lang), wordor(lang) .. wordsep(lang))
local wordor = langSwitch(require('Module:I18n/or'), lang)
return mw.text.listToText(args, comma, wordor  .. wordsep)
elseif conjtype == 'explicit or' then -- adds "or" betwen all words when the context can be confusing
elseif conjtype == 'explicit or' then -- adds "or" betwen all words when the context can be confusing
return mw.text.listToText(args, wordor(lang) .. wordsep(lang), wordor(lang) .. wordsep(lang))
local wordor = langSwitch(require('Module:I18n/or'), lang)
return mw.text.listToText(args, wordor .. wordsep, wordor  .. wordsep)
elseif conjtype and conjtype ~= 'and' and conjtype ~= '' then
elseif conjtype and conjtype ~= 'and' and conjtype ~= '' then
return 'unknown conj type : ' .. conjtype .. '[[Category:Pages with incorrect template usage/Conj|B]]'
return mw.text.listToText(args, conjtype, conjtype)
else  
elseif andtable[lang] then
return mw.text.listToText(args, comma(lang), wordand(lang) .. wordsep(lang))
return mw.text.listToText(args, comma, andtable[lang])
else
local wordand = mw.message.new( "and" ):inLanguage(lang):plain()
return mw.text.listToText(args, comma, wordand .. wordsep)
end
end
end
end
137行目: 155行目:
args = frame.args
args = frame.args
if not args or not args[1] then
if not args or not args[1] then
args = mw.getCurrentFrame():getParent().args
args = frame:getParent().args
end
end
local conjtype = args.type
local lang = args.lang
local lang = args.lang
if not lang or mw.text.trim(lang) == '' then
if not lang or mw.text.trim(lang) == '' then
lang = frame:preprocess( "{{int:lang}}" )
lang = frame:callParserFunction( "int", "lang" )
end
end
newargs = {}  -- transform args metatable into a table so it can be concetenated
newargs = {}  -- transform args metatable into a table so it can be concetenated
157行目: 174行目:
end
end
end
end
return p.conj(newargs, lang, conjtype)
return p.conj(newargs, lang, args.type)
end
end


return p
return p
匿名利用者

案内メニュー