Module:Linguistic: Difference between revisions
From Neodyland Wiki
More actions
m table may be written as variable or programmatically filled, ... also there was a little bug: << " or lang == 'ja' or 'zh-hans' " >> which would make it always true and thus returning no space for every lang |
test with a "global" lang variable that might simplify much of the code |
||
| Line 1: | Line 1: | ||
-- some simple internationalization that can be called by other modules | -- some simple internationalization that can be called by other modules | ||
local p = {} | local p = {} | ||
local vowels = 'aeiouyąăẵằẳặȃắâẫấầẩậãäǟāáàȁǎảẚåǻḁạǡæǣǽĕȇêễếềểệḙẽḛëēḕéḗèȅěẻẹęȩḝǝĭȋîĩḭïḯīíìȉǐỉịįıŏȏôỗốồổộõṏṍöōṑóṓòȍǒỏọǫǭơỡớờởợøǿŭȗûṷũṻṹṵüǖǘǜǚṳūúùȕǔủůụųưữứừửựŷỹÿȳýỳỷẙỵ' | local vowels = 'aeiouyąăẵằẳặȃắâẫấầẩậãäǟāáàȁǎảẚåǻḁạǡæǣǽĕȇêễếềểệḙẽḛëēḕéḗèȅěẻẹęȩḝǝĭȋîĩḭïḯīíìȉǐỉịįıŏȏôỗốồổộõṏṍöōṑóṓòȍǒỏọǫǭơỡớờởợøǿŭȗûṷũṻṹṵüǖǘǜǚṳūúùȕǔủůụųưữứừửựŷỹÿȳýỳỷẙỵ' | ||
local lang = function(frame) | |||
args = mw.getCurrentFrame():getParent().args | |||
if args.lang then | |||
return args.lang | |||
end | |||
return frame:preprocess( "{{int:lang}}" ) | |||
end | |||
function | function isin(str, pattern) | ||
if mw.ustring.find( | if mw.ustring.find(str, pattern, 1, true ) then | ||
return true | return true | ||
end | end | ||
end | end | ||
function p.wordsep( | function langisin(str) | ||
return langisin(str, lang .. ',') -- comma is necessary to avoid false positives like zh in zh-hans | |||
end | |||
function p.vowelfirst (str) | |||
return isin(vowels, str[1]) | |||
end | |||
function p.wordsep() -- default separator between words | |||
-- language with no separator | -- language with no separator | ||
if ( | if langisin('zh, ja, zh-hans, zh-hant, zh-sg, zh-cn, sh-tw') then | ||
return '' | return '' | ||
end | end | ||
| Line 18: | Line 34: | ||
end | end | ||
function p.noungroup(noun, adj | function p.noungroup(noun, adj) | ||
if not noun then | if not noun then | ||
return nil end | return nil end | ||
| Line 25: | Line 41: | ||
end | end | ||
-- adjective before the noun | -- adjective before the noun | ||
if | if langisin('de, de-at, de-ch, en, en-ca, en-gb, zh ') then | ||
return adj .. p.wordsep(lang) .. noun | return adj .. p.wordsep(lang) .. noun | ||
-- adjective after the noun | -- adjective after the noun | ||
elseif | elseif langisin('fr, fr-ca, it') then | ||
return noun .. p.wordsep(lang) .. adj | return noun .. p.wordsep(lang) .. adj | ||
else | else | ||
Revision as of 12:11, 22 November 2013
This documentation is transcluded from Module:Linguistic/doc.
-- some simple internationalization that can be called by other modules
local p = {}
local vowels = 'aeiouyąăẵằẳặȃắâẫấầẩậãäǟāáàȁǎảẚåǻḁạǡæǣǽĕȇêễếềểệḙẽḛëēḕéḗèȅěẻẹęȩḝǝĭȋîĩḭïḯīíìȉǐỉịįıŏȏôỗốồổộõṏṍöōṑóṓòȍǒỏọǫǭơỡớờởợøǿŭȗûṷũṻṹṵüǖǘǜǚṳūúùȕǔủůụųưữứừửựŷỹÿȳýỳỷẙỵ'
local lang = function(frame)
args = mw.getCurrentFrame():getParent().args
if args.lang then
return args.lang
end
return frame:preprocess( "{{int:lang}}" )
end
function isin(str, pattern)
if mw.ustring.find(str, pattern, 1, true ) then
return true
end
end
function langisin(str)
return langisin(str, lang .. ',') -- comma is necessary to avoid false positives like zh in zh-hans
end
function p.vowelfirst (str)
return isin(vowels, str[1])
end
function p.wordsep() -- default separator between words
-- language with no separator
if langisin('zh, ja, zh-hans, zh-hant, zh-sg, zh-cn, sh-tw') then
return ''
end
-- default: white space
return ' '
end
function p.noungroup(noun, adj)
if not noun then
return nil end
if not adj
then return noun
end
-- adjective before the noun
if langisin('de, de-at, de-ch, en, en-ca, en-gb, zh ') then
return adj .. p.wordsep(lang) .. noun
-- adjective after the noun
elseif langisin('fr, fr-ca, it') then
return noun .. p.wordsep(lang) .. adj
else
return noun ' (' .. adj .. ')'
end
end
return p