menu menu_open
  • edit Edit

    Navigation

    • Main page
    • All pages
    • Recent changes
    • Random page
    • Help

    Tools

    • What links here
    • Related changes
    • Special pages
    • Printable version
    • Permanent link
    • Page information

    Variants

The Lab Rats 2 - Reformulate Wiki

Module:LangSwitch

14 article Pages
18 photo Files
2128 edit Edits
22 person Users
timeline photo_library leaderboard file_upload
palette
  • computer
code
  • computer
pages api security app_shortcut
more_vertical
  • timeline Recent changes
  • photo_library New Files
  • leaderboard Statistics
  • file_upload Upload file
  • palette CSS expand_more
    • computer
  • code JS expand_more
    • computer
  • pages All pages
  • apisandbox API sandbox
  • security System messages
  • app_shortcut Special pages
grid_view double_arrow forum file_download extension file_upload visibility book category delete_sweep
settings
contrast

  • brightness_auto hdr_auto
  • brightness_7 brightness_1
  • brightness_6 brightness_2
  • brightness_5 brightness_3
  • brightness_4
  • brightness_3 brightness_5
  • brightness_2 brightness_6
  • brightness_1 brightness_7
hdr_auto
  • brightness_auto
  • hdr_auto
  • light_mode
  • dark_mode

  • palette
  • tonality

  • brightness_auto hdr_auto
  • gradient gradient
  • thermostat thermostat
  • ac_unit storm
  • Duo
  • Solo
format_paint
  • emergency deployed_code
  • emergency opacity
  • square
  • contrast

  • deployed_code build square contrast
  • 1
  • 2
  • 3
  • 4
palette
  • brightness_auto
  • hdr_auto
  • light_mode
  • dark_mode

  • build
  • emergency invert_colors_off
  • contrast
  • format_paint
  • android
  • colorize
colorize
  • brightness_auto
  • hdr_auto
  • bedtime_off
  • bedtime

  • build
  • square
  • computer
  • invert_colors
  • brush
  • filter_b_and_w
  • contrast
  • smart_toy
  • 1
  • 2
  • 3
  • 4
brush
  • A
  • B
  • C
  • D
  • E
  • F
  • G
  • H
  • Welcome to the Lab Rats 2 - Reformulate Wiki.
  • Stay tuned here for news and changes...
  • This wiki is currently being built. Feel free to contribute to it and discuss any suggestions or changes.
  • Visit the Lab Rats 2 Discord to discuss any missing information!
  • Module
  • Discussion
  • Read
  • View source
  • View history

Module:LangSwitch

From The Lab Rats 2 - Reformulate Wiki

Documentation for this module may be created at Module:LangSwitch/doc

--[[
  __  __           _       _        _                      ____          _ _       _     
 |  \/  | ___   __| |_   _| | ___ _| |    __ _ _ __   __ _/ ___|_      _(_) |_ ___| |__  
 | |\/| |/ _ \ / _` | | | | |/ _ (_) |   / _` | '_ \ / _` \___ \ \ /\ / / | __/ __| '_ \ 
 | |  | | (_) | (_| | |_| | |  __/_| |__| (_| | | | | (_| |___) \ V  V /| | || (__| | | |
 |_|  |_|\___/ \__,_|\__,_|_|\___(_)_____\__,_|_| |_|\__, |____/ \_/\_/ |_|\__\___|_| |_|
                                                     |___/                               
 Authors and maintainers:
* User:Zolo   - original version in Module:Fallback
* User:Jarekt 
]]

-- add optional module 
-- used for debugging purposes as it detects cases of unintended global variables
require('Module:No globals') 

local p = {}

--[[
_langSwitch
 
This function is the core part of the LangSwitch template. 
 
Example usage from Lua:
text = _langSwitch({en='text in english', pl='tekst po polsku'}, lang)
 
Parameters:
  args - table with translations by language
  lang - desired language (often user's native language)

 Error Handling:

]]

function p._langSwitch(args, lang) -- args: table of translations
	-- Return error if there is not default and no english version
	if not args.en and not args.default then
		local err = '<b class="error">LangSwitch Error: no default</b>'
		if args.nocat == '1' then
			return err
		else
			return err .. '[[Category:LangSwitch template without default version]]'
		end
	end
	
	-- To improve performance try quick switch, and load fallback chain only if needed. 
	-- In the vast majority of cases fast switch is sufficient
	local val = args[lang]
	if val == '~' then 
		return ''
	elseif val and val ~= '' then 
		return val 
	elseif args.quick then
		return nil
	end
	
	-- get the list of accepetable language (lang + those in lang's fallback chain) and check their content
	assert(lang, 'LangSwitch Error: no lang')
	local langList = mw.language.getFallbacksFor(lang)
	table.insert(langList,1,lang)
	table.insert(langList,math.max(#langList,2),'default')
	for _, language in ipairs(langList) do 
		val = args[language]
		if val == '~' then 
			return ''
		elseif val and val ~= '' then 
			return val 
		end
	end
end

--[[
langSwitch
 
This function is the core part of the LangSwitch template. 
 
Example Usage from a template:
{{#invoke:fallback|langSwitch|en=text in english|pl=tekst po polsku|lang={{int:lang}} }}
 
Parameters:
  frame.args - table with translations by language
  frame.args.lang - desired language (often user's native language)

 Error Handling:

]]
function p.langSwitch(frame) -- version to be used from wikitext
	local args = frame.args
	-- if no expected args provided than check parent template/module args
	if args.en==nil and args.default==nil and args.nocat==nil then
		args = mw.getCurrentFrame():getParent().args 
	end
	local lang = args.lang
	if not lang or not mw.language.isKnownLanguageTag(lang) then
		lang = frame:callParserFunction( "int", "lang" ) -- get user's chosen language 
	end
	
	-- Try quick switch which checks the most likely option when fallback is not needed
	args.quick = true;
	local val = p._langSwitch(args, lang)
	if val then
		return val
	end
	
	-- Allow input in format: {{LangSwitch|de=Grün|es/it/pt=Verde|fr=Vert|en=Green |lang=en}}
	-- with multiple languages mapping to a single value
	local args1 = {}
	for name, value in pairs( args ) do 
		if value ~= '' and type(name)=='string' then 
    		for str in string.gmatch( name, "([^/]+)" ) do
				args1[str] = value
			end
		end
	end
	return p._langSwitch(args1, lang)
end

return p
Retrieved from "https://lr2wiki.porn-organizer.org/index.php?title=Module:LangSwitch&oldid=286"
  • Privacy policy
  • About The Lab Rats 2 - Reformulate Wiki
  • Disclaimers
    • This page was last edited on 22 December 2021, at 02:53.
    • Content is available under Creative Commons Attribution-ShareAlike unless otherwise noted.
    • Creative Commons Attribution-ShareAlike
    • Powered by MediaWiki

    timeline Recent changes
    arrow_forward_ios

    No changes during the given period match these criteria.

    info About The Lab Rats 2 - Reformulate Wiki
    edit

    The wiki for the adult sandbox game Lab Rabs 2 - Reformulate

    search saved_search
    search saved_search Search
    apps
    • live_help
    • hive
    • insert_link
    • timeline
    • visibility
    • shuffle
    • build
    • help
    • file_download
    • attachment
    public_off Not logged inReady
    widgets
    public StandardReady
    hive MirahezeReady
    Qora QoreReady
    • Privacy policy
    • About The Lab Rats 2 - Reformulate Wiki
    • Disclaimers
    insert_link timeline visibility shuffle build help file_download attachment
    account_circle
    • refresh

    • Create account
    • Log in
    refresh