Skip to content
54 changes: 54 additions & 0 deletions lua/wikis/commons/Widget/TranslationNeededList.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
-- @Liquipedia
-- page=Module:Widget/TranslationNeededList
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Lua = require('Module:Lua')

local Array = Lua.import('Module:Array')
local Class = Lua.import('Module:Class')
local Variables = Lua.import('Module:Variables')
local MathUtil = Lua.import('Module:MathUtil')

local Link = Lua.import('Module:Widget/Basic/Link')
local HtmlWidget = Lua.import('Module:Widget/Html/All')
local Widget = Lua.import('Module:Widget')

---@class TranslationNeededList: Widget
---@operator call(table): TranslationNeededList
local TranslationNeededList = Class.new(Widget)
TranslationNeededList.defaultProps = {
limit = 3,
}

---@return Widget[]
function TranslationNeededList:render()
local limit = assert(MathUtil.toInteger(self.props.limit), "Limit must be a number")

local translations = TranslationNeededList._getTranslations()
Variables.varDefine('total_number_of_translations', #translations)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use case of this variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be used to display the number of articles that are in need of translation via the Module:Widget/MainPage/WantToHelp.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Module:Widget/MainPage/WantToHelp uses a different wiki var
so i doubt this will work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the proposed var to the local version of that widget, line 160.

If needed I will add it to the repo version of that module but that would require additional code to exclude that block from the non-english (basically all but dota2gameru) wikis.


translations = Array.sub(Array.randomize(translations), 1, limit)

return HtmlWidget.Ul{children = Array.map(translations, function(translation)
return HtmlWidget.Li{
children = {
Link{link = translation.pagename, children = {translation.name}},
}
}
end)}
end

---Fetches "Translations" datapoints
---@private
---@return datapoint[]
function TranslationNeededList._getTranslations()
return mw.ext.LiquipediaDB.lpdb('datapoint', {
limit = 5000,
conditions = '[[type::translation]]'
})
end

return TranslationNeededList
Loading