Module:Lang: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Saag (talk | contribs)
Created lang module for loading localized strings from their relevant json file
 
Saag (talk | contribs)
No edit summary
Line 6: Line 6:
return string.format("Language code '%s' not found")  
return string.format("Language code '%s' not found")  
end
end
return data
end
end



Revision as of 12:09, 15 September 2024

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

local p = {}

function get_lang_file(lang_code)
	local data = mw.loadJsonData(string.format("Data:%s.json", lang_code))
	if (data == nil) then 
		return string.format("Language code '%s' not found") 
	end
	return data
end

-- Get a localized string by the raw key
p.get_string = function(frame)
	local lang_code = frame.args[1]
	local key = frame.args[2]
	local data = get_lang_file(lang_code)
	local label = data[key]
	if (label == nil) then 
		return string.format("Key '%s' not found", key) 
	end
	
	return label
end

-- Search for a localized string using its English label
p.search_string = function(frame)
	local lang_code = frame.args[1]
	local attr_key = frame.args[2]
	local data = get_lang_file(lang_code)
end

return p