Welcome to the TTSCpedia (beta)! This wiki is the successor to the FANDOM/Wikia version! You may create an account on the new wiki during the Public Beta stage and begin editing. Please see the to-do list here. Any content from the FANDOM/Wikia wiki will not be transferred automatically, such as pages, and accounts. That must be done manually by the end user, being you. |
Limited Feature Set Many TTSCpedia features are currently semi-broken due to regressions introduced with the MediaWiki upgrade. We hope to be fully operational again soon. The MonoBook skin has temporarily been set as the default skin due to Cali not being fully ported to the new version of MediaWiki. |
Changes
From The TTSCpedia
Jump to navigationJump to searchSplitting Module:Fallback into Module:Autotranslate, Module:LangSwitch and Module:Fallback
--[[
__ __ _ _ _____ _ _ _ _
| \/ | ___ __| |_ _| | ___ _| ___|_ _| | | |__ __ _ ___| | __
| |\/| |/ _ \ / _` | | | | |/ _ (_) |_ / _` | | | '_ \ / _` |/ __| |/ /
| | | | (_) | (_| | |_| | | __/_| _| (_| | | | |_) | (_| | (__| <
|_| |_|\___/ \__,_|\__,_|_|\___(_)_| \__,_|_|_|_.__/ \__,_|\___|_|\_\
Authors and maintainers:
* User:Zolo - original version
* User:Jarekt
]]
local p = {}
--[[
translatelua
Allows easy translation or internalization of pages in Lua.
Example Usage from a template:
{{#invoke: fallback|translatelua| i18n/oil on canvas|lang={{{lang|}}}}}
Parameters:
frame.args.1 - name of translation module
frame.args.2 - field name of the structure in Module:[frame.args.1] to use
frame.args.lang - desired language (often user's native language)
Error Handling:
]]
function p.translatelua(frame)
local lang = mw.text.trim(frame.args.lang)
local page = require('Module:' .. mw.text.trim(frame.args[1])) -- page should only contain a simple of translations
if not lang or lang == '' then
lang = frame:callParserFunction("int", "lang")
end
if frame.args[2] then
page = page[mw.text.trim(frame.args[2])]
end
local langList = mw.language.getFallbacksFor(lang)
table.insert(langList,1,lang)
for _,language in ipairs(langList) do
if page[language] then
return page[language]
end
end
end
--[[
fblist
Similar to mw.language.getFallbacksFor(lang) but uses Commons old fallback chain
Parameters:
lang - desired language (often user's native language)
Error Handling:
]]
function p.fblist(lang) -- list the full fallback chain from a language to en
local fbtable = p.fallbackloop{lang:lower()}
table.insert(fbtable, 'default')
table.insert(fbtable, 'en')
return fbtable
end
local function _inArray(x, t)
for i, v in ipairs(t) do
if v == x then return i end
end
return -1
end
function p.fallbackloop(fbtable) --list of fallback languages in string format (more convenient than tables)
local langlist = require('Module:Fallbacklist')
local changes = false
for i, j in ipairs(fbtable) do
local seq = langlist[j]
if seq then
for k, l in ipairs(seq) do
if _inArray(l, fbtable) == -1 then
table.insert(fbtable, l)
changes = true
end
end
end
end
if changes then
return p.fallbackloop(fbtable)
end
return fbtable
end
return p
__ __ _ _ _____ _ _ _ _
| \/ | ___ __| |_ _| | ___ _| ___|_ _| | | |__ __ _ ___| | __
| |\/| |/ _ \ / _` | | | | |/ _ (_) |_ / _` | | | '_ \ / _` |/ __| |/ /
| | | | (_) | (_| | |_| | | __/_| _| (_| | | | |_) | (_| | (__| <
|_| |_|\___/ \__,_|\__,_|_|\___(_)_| \__,_|_|_|_.__/ \__,_|\___|_|\_\
Authors and maintainers:
* User:Zolo - original version
* User:Jarekt
]]
local p = {}
--[[
translatelua
Allows easy translation or internalization of pages in Lua.
Example Usage from a template:
{{#invoke: fallback|translatelua| i18n/oil on canvas|lang={{{lang|}}}}}
Parameters:
frame.args.1 - name of translation module
frame.args.2 - field name of the structure in Module:[frame.args.1] to use
frame.args.lang - desired language (often user's native language)
Error Handling:
]]
function p.translatelua(frame)
local lang = mw.text.trim(frame.args.lang)
local page = require('Module:' .. mw.text.trim(frame.args[1])) -- page should only contain a simple of translations
if not lang or lang == '' then
lang = frame:callParserFunction("int", "lang")
end
if frame.args[2] then
page = page[mw.text.trim(frame.args[2])]
end
local langList = mw.language.getFallbacksFor(lang)
table.insert(langList,1,lang)
for _,language in ipairs(langList) do
if page[language] then
return page[language]
end
end
end
--[[
fblist
Similar to mw.language.getFallbacksFor(lang) but uses Commons old fallback chain
Parameters:
lang - desired language (often user's native language)
Error Handling:
]]
function p.fblist(lang) -- list the full fallback chain from a language to en
local fbtable = p.fallbackloop{lang:lower()}
table.insert(fbtable, 'default')
table.insert(fbtable, 'en')
return fbtable
end
local function _inArray(x, t)
for i, v in ipairs(t) do
if v == x then return i end
end
return -1
end
function p.fallbackloop(fbtable) --list of fallback languages in string format (more convenient than tables)
local langlist = require('Module:Fallbacklist')
local changes = false
for i, j in ipairs(fbtable) do
local seq = langlist[j]
if seq then
for k, l in ipairs(seq) do
if _inArray(l, fbtable) == -1 then
table.insert(fbtable, l)
changes = true
end
end
end
end
if changes then
return p.fallbackloop(fbtable)
end
return fbtable
end
return p