Editing
Module:TranslateThis
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local insert = table.insert local remove = table.remove local myFrame = mw.getCurrentFrame() local myLang = myFrame:callParserFunction('Int', 'Lang'):lower():gsub('_', '-') local myLangObj = mw.language.new(myLang) local myFallbacks = myLangObj:getFallbackLanguages() for i, lang in ipairs(myFallbacks) do lang = lang:lower():gsub('_', '-') if lang == myLang then remove(myFallbacks, i) break end end insert(myFallbacks, 1, myLang) local p = {} function p.main(frame) local source, anchor local args = {} for k, v in pairs(frame:getParent().args) do if type(k) == 'string' and type(v) == 'string' then v = v:gsub('^%s+(.-)%s+$', '%1') -- Trim texts given in argument values. -- Split argument keys by language code (separated by any non-letter non-digit character); -- this allows setting the same value for multiple languages. for lang in k:lower():gsub('_', '-'):gfind('[-0-9a-z]+') do if lang == 'source' then source = v elseif lang == 'anchor' then anchor = v else -- if not args[lang] then args[lang] = v end end end end for i, lang in ipairs(myFallbacks) do local result = args[lang] if result and result ~= '' then if lang == myLang then return result end return '<bdi style="background:#FCC;color:#222"' .. (anchor and (' id="' .. anchor .. '"') or '') .. ' lang="' .. frame:expandTemplate{title = 'Template:BCP47', args = {lang}} .. '">' .. result .. '</bdi>' .. (source and '<sup style="font-size:xx-small"><bdi lang="en" dir="ltr">[[:' .. source .. '|[Translate this message]]]</bdi></sup>' or '') end end return source and '<sup style="font-size:xx-small"><bdi lang="en" dir="ltr">[[:' .. source .. '|[Translate this message]]]</bdi></sup>' or '' end return p
Summary:
Please note that all contributions to Meta Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Meta Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Dark mode
Contributions
Create account
Log in
Namespaces
Module
Discussion
English
Views
Read
Edit source
View history
More
Purge
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information
Get shortened URL