Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Discord server
Recent changes
Random page
Community
Discord
Steam
Search
Search
English
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Module:Lang
Module
Discussion
English
Read
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit source
View history
Purge
General
What links here
Related changes
Special pages
Page information
Languages
Appearance
move to sidebar
hide
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 p = {} local util_module = require("Module:Utilities") local lang_codes_set = mw.loadJsonData("Data:LangCodes.json") local dictionary_module = require("Module:Dictionary") -- Overrides applied to searches by key. Designed to handle edge cases where -- the expected key does not have a localization entry local KEY_OVERRIDES = { MoveSlowPercent_label = 'MovementSlow_label', BonusHealthRegen_label = 'HealthRegen_label', BarbedWireRadius_label = 'Radius_label', BarbedWireDamagePerMeter_label = 'DamagePerMeter_label', BuildUpDuration_label = 'BuildupDuration_label', TechArmorDamageReduction_label = 'TechArmorDamageReduction_Label', DamageAbsorb_label = 'DamageAbsorb_Label', InvisRegen_label = 'InvisRegen_Label', EvasionChance_label = 'EvasionChance_Label', DelayBetweenShots_label = 'DelayBetweenShots_Label', } function get_lang_file(lang_code) local file_name = string.format("Data:Lang_%s.json", lang_code) local success, data = pcall(mw.loadJsonData, file_name) if success then return data else return nil end end -- Helper function to handle newline conversion local function process_newlines(text) if not text then return text end -- Replace "n with newline character text = text:gsub('"n', '\n') return text end -- Get a localized string by the raw key p.get_string = function(key, lang_code_override, fallback_str, remove_var_index) -- Get frame object (either passed directly or via first argument) local frame if type(key) == "table" and key.args then frame = key key = frame.args[1] lang_code_override = frame.args["lang_code_override"] fallback_str = frame.args["fallback_str"] remove_var_index = frame.args["remove_var_index"] else frame = mw.getCurrentFrame() end -- Determine lang_code if not overridden local lang_code = lang_code_override if (lang_code == '' or lang_code == nil) then lang_code = p.get_lang_code() end -- Retrieve lang data local data = get_lang_file(lang_code) if (data == nil) then return string.format("Lang code '%s' does not have a json file", lang_code) end -- Localize local label = data[KEY_OVERRIDES[key] or key] if (label == nil) then -- Apply fallback local fallback_tooltip = frame:expandTemplate{title = "MissingValveTranslationTooltip"} local fallback if (fallback_str == 'en') then fallback = p.get_string(key, 'en', key .. fallback_tooltip, remove_var_index) elseif fallback_str == 'dictionary' then return dictionary_module.translate(key, lang_code_override) elseif fallback_str ~= nil then fallback = fallback_str else return '' end return fallback .. fallback_tooltip end -- Apply remove_var if (remove_var_index ~= nil) then label = util_module.remove_var(label, remove_var_index) end -- Process newlines and return label = process_newlines(label) return label end -- Search for a localized string using its English label p.search_string = function(frame) local label = frame.args[1] local lang_code_override = frame.args[2] local result = p._search_string(label, lang_code_override) result = process_newlines(result) return result end -- search_string, but for internal use by other modules p._search_string = function(label, lang_code_override) lang_code = lang_code_override if (lang_code == '' or lang_code == nil) then lang_code = p.get_lang_code() end -- Load the language files local data_en = get_lang_file('en') -- English data local data_lang = get_lang_file(lang_code) -- Target language data if (data_lang == nil) then error("Lang code '%s' does not have a json file", lang_code) end -- Search for the key in the English data local key = nil for k, v in pairs(data_en) do if v == label then key = k -- Find the key corresponding to the label break end end -- Default to input label if localized string is not found if (key == nil) then return label end if (data_lang[key] == nil) then return label end return data_lang[key] end p.get_lang_code = function() local title = mw.title.getCurrentTitle() local lang_code = title.fullText:match(".*/(.*)$") if lang_code == nil or lang_codes_set[lang_code] == nil then return 'en' end return lang_code end return p
Summary:
Please note that all contributions to Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
Deadlock:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, 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.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Preview page with this template
Templates used on this page:
Template:MissingValveTranslationTooltip
(
edit
)
Template:Tooltip
(
edit
)
Module:Dictionary
(
edit
)
Module:Lang
(
edit
)
Module:Lang/doc
(
edit
)
Module:Utilities
(
edit
)
Data:Dictionary
(
edit
)
Data:LangCodes.json
(
edit
)
Data:Lang en.json
(
edit
)
Data:Lang es.json
(
edit
)