Content deleted Content added
Alistair3149 (talk | contribs) No edit summary |
Alistair3149 (talk | contribs) No edit summary |
||
(25 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
require( 'strict' ) |
require( 'strict' ) |
||
local |
local p = {} |
||
local metatable = {} |
|||
local methodtable = {} |
|||
metatable.__index = methodtable |
|||
local MODULE_NAME = 'Food' |
|||
local i18n = require( 'Module:i18n' ):new() |
|||
local TNT = require( 'Module:Translate' ):new() |
local TNT = require( 'Module:Translate' ):new() |
||
local |
local smwCommon = require( 'Module:Common/SMW' ) |
||
local data = mw.loadJsonData( 'Module:Item/' .. MODULE_NAME .. '/data.json' ) |
|||
-- Intentionally re-use the config from Module:Item |
|||
local config = mw.loadJsonData( 'Module:Item/config.json' ) |
local config = mw.loadJsonData( 'Module:Item/config.json' ) |
||
--- Wrapper function for Module:i18n.translate |
|||
local lang |
|||
--- |
|||
if config.module_lang then |
|||
--- @param key string The translation key |
|||
lang = mw.getLanguage( config.module_lang ) |
|||
--- @return string If the key was not found, the key is returned |
|||
else |
|||
local function t( key ) |
|||
lang = mw.getContentLanguage() |
|||
return i18n:translate( key ) |
|||
end |
end |
||
--- Wrapper function for Module:Translate.translate |
|||
--- FIXME: This should go to somewhere else, like Module:Common |
|||
--- Calls TNT with the given key |
|||
--- |
--- |
||
--- @param key string The translation key |
--- @param key string The translation key |
||
--- @param addSuffix boolean Adds a language suffix if config.smw_multilingual_text is true |
--- @param addSuffix boolean|nil Adds a language suffix if config.smw_multilingual_text is true |
||
--- @return string If the key was not found in the .tab page, the key is returned |
--- @return string If the key was not found in the .tab page, the key is returned |
||
local function translate( key, addSuffix, ... ) |
local function translate( key, addSuffix, ... ) |
||
return TNT:translate( 'Module:Item/' .. MODULE_NAME .. '/i18n.json', config, key, addSuffix, {...} ) |
|||
addSuffix = addSuffix or false |
|||
local success, translation |
|||
local function multilingualIfActive( input ) |
|||
if addSuffix and config.smw_multilingual_text == true then |
|||
return string.format( '%s@%s', input, config.module_lang or mw.getContentLanguage():getCode() ) |
|||
end |
|||
return input |
|||
end |
|||
if config.module_lang ~= nil then |
|||
success, translation = pcall( TNT.formatInLanguage, config.module_lang, 'Module:Item/Food/i18n.json', key or '', ... ) |
|||
else |
|||
success, translation = pcall( TNT.format, 'Module:Item/Food/i18n.json', key or '', ... ) |
|||
end |
|||
if not success or translation == nil then |
|||
return multilingualIfActive( key ) |
|||
end |
|||
return multilingualIfActive( translation ) |
|||
end |
end |
||
Line 59: | Line 34: | ||
--- |
--- |
||
--- @param smwSetObject table |
--- @param smwSetObject table |
||
function |
function p.addSmwProperties( apiData, frameArgs, smwSetObject ) |
||
smwCommon.addSmwProperties( |
|||
local smwCommon = require( 'Module:Common/SMW' ) |
|||
apiData, |
|||
frameArgs, |
|||
smwSetObject, |
|||
translate, |
|||
config, |
|||
data, |
|||
'Item/' .. MODULE_NAME |
|||
) |
|||
--- Not sure if size matters, not like there is a S12 Double Dog |
|||
smwCommon.addSmwProperties( |
|||
--- FIXME: SMW_Size is from Module:Item, I made a duplicated entry in Module:Item/Food/i18n.json to make this work |
|||
self.apiData, |
|||
smwSetObject[ t( 'SMW_Size' ) ] = nil |
|||
self.frameArgs, |
|||
smwSetObject, |
|||
translate, |
|||
config, |
|||
data, |
|||
'Item/Food' |
|||
) |
|||
--- GEND and GENF are placeholders |
|||
-- We only know whether the item is single use or not |
|||
--- FIXME: Same as above |
|||
if smwSetObject[ translate( 'SMW_Uses' ) ] == true then |
|||
smwSetObject[ |
if smwSetObject[ t( 'SMW_Manufacturer' ) ] == '[[GEND]]' or smwSetObject[ t( 'SMW_Manufacturer' ) ] == '[[GENF]]' then |
||
smwSetObject[ t( 'SMW_Manufacturer' ) ] = nil |
|||
else |
|||
end |
|||
smwSetObject[ translate( 'SMW_Uses' ) ] = nil |
|||
end |
|||
--- We only know whether the item is single use or not |
|||
if smwSetObject[ t( 'SMW_Uses' ) ] == true then |
|||
smwSetObject[ t( 'SMW_Uses' ) ] = 1 |
|||
else |
|||
smwSetObject[ t( 'SMW_Uses' ) ] = nil |
|||
end |
|||
if smwSetObject[ t( 'SMW_Effect' ) ] == 'None' then |
|||
smwSetObject[ t( 'SMW_Effect' ) ] = nil |
|||
end |
|||
end |
end |
||
--- Adds all SMW parameters set by this Module to the ASK object |
|||
function methodtable.addSmwAskProperties( self, smwAskObject ) |
|||
--- |
|||
require( 'Module:Common/SMW' ).addSmwQueryParams( |
|||
--- @param smwAskObject table |
|||
smwAskObject, |
|||
--- @return nil |
|||
translate, |
|||
function p.addSmwAskProperties( smwAskObject ) |
|||
config, |
|||
smwCommon.addSmwAskProperties( |
|||
data |
|||
smwAskObject, |
|||
) |
|||
translate, |
|||
config, |
|||
data |
|||
) |
|||
end |
end |
||
--- Adds entries to the infobox |
|||
function methodtable.addInfoboxData( self, infobox, smwData ) |
|||
--- |
|||
infobox:renderSection( { |
|||
--- @param infobox table The Module:InfoboxNeue instance |
|||
--- @param smwData table Data from Semantic MediaWiki |
|||
--- @return nil |
|||
function p.addInfoboxData( infobox, smwData ) |
|||
infobox:renderSection( { |
|||
content = { |
content = { |
||
infobox:renderItem( { |
infobox:renderItem( { |
||
label = translate( ' |
label = translate( 'LBL_Effect' ), |
||
data = smwData[ |
data = infobox.tableToCommaList( smwData[ t( 'SMW_Effect' ) ] ), |
||
colspan = 2 |
|||
} ), |
} ), |
||
infobox:renderItem( { |
|||
label = translate( 'LBL_NutritionalDensityRating' ), |
label = translate( 'LBL_NutritionalDensityRating' ), |
||
data = smwData[ |
data = smwData[ t( 'SMW_NutritionalDensityRating' ) ], |
||
} ), |
} ), |
||
infobox:renderItem( { |
|||
label = translate( 'LBL_HydrationEfficacyIndex' ), |
label = translate( 'LBL_HydrationEfficacyIndex' ), |
||
data = smwData[ |
data = smwData[ t( 'SMW_HydrationEfficacyIndex' ) ], |
||
} ), |
|||
infobox:renderItem( { |
|||
label = translate( 'LBL_Uses' ), |
|||
data = smwData[ t( 'SMW_Uses' ) ], |
|||
} ) |
} ) |
||
}, |
}, |
||
col = |
col = 4 |
||
} ) |
} ) |
||
end |
end |
||
--- Add categories that are set on the page. |
|||
--- New Instance |
|||
--- The categories table should only contain category names, no MW Links, i.e. 'Foo' instead of '[[Category:Foo]]' |
|||
function Food.new( self, apiData, frameArgs ) |
|||
--- |
|||
local instance = { |
|||
--- @param categories table The categories table |
|||
apiData = apiData, |
|||
--- @param frameArgs table Frame arguments from Module:Arguments |
|||
frameArgs = frameArgs |
|||
--- @param smwData table Data from Semantic MediaWiki |
|||
} |
|||
--- @return nil |
|||
function p.addCategories( categories, frameArgs, smwData ) |
|||
end |
|||
setmetatable( instance, metatable ) |
|||
--- Return the short description for this object |
|||
--- |
|||
--- @param frameArgs table Frame arguments from Module:Arguments |
|||
--- @param smwData table Data from Semantic MediaWiki |
|||
--- @return string|nil |
|||
function p.getShortDescription( frameArgs, smwData ) |
|||
return instance |
|||
end |
end |
||
return |
return p |
Latest revision as of 22:05, 8 May 2024
This documentation is transcluded from Module:Item/Food/doc. Changes can be proposed in the talk page.
Module:Item/Food is shared across the Star Citizen Wikis.
This module is shared across the Star Citizen Wikis. Any changes should also be relayed to the GitHub repository.
Module:Item/Food loads messages from Module:Item/Food/i18n.json.
This module is designed to be language-neutral. All of the messages are saved in the i18n.json subpage.
This module is unused.
This module is neither invoked by a template nor required/loaded by another module. If this is in error, make sure to add
{{Documentation}}
/{{No documentation}}
to the calling template's or parent's module documentation.Function list |
---|
require( 'strict' )
local p = {}
local MODULE_NAME = 'Food'
local i18n = require( 'Module:i18n' ):new()
local TNT = require( 'Module:Translate' ):new()
local smwCommon = require( 'Module:Common/SMW' )
local data = mw.loadJsonData( 'Module:Item/' .. MODULE_NAME .. '/data.json' )
local config = mw.loadJsonData( 'Module:Item/config.json' )
--- Wrapper function for Module:i18n.translate
---
--- @param key string The translation key
--- @return string If the key was not found, the key is returned
local function t( key )
return i18n:translate( key )
end
--- Wrapper function for Module:Translate.translate
---
--- @param key string The translation key
--- @param addSuffix boolean|nil Adds a language suffix if config.smw_multilingual_text is true
--- @return string If the key was not found in the .tab page, the key is returned
local function translate( key, addSuffix, ... )
return TNT:translate( 'Module:Item/' .. MODULE_NAME .. '/i18n.json', config, key, addSuffix, {...} )
end
--- Adds the properties valid for this item to the SMW Set object
---
--- @param smwSetObject table
function p.addSmwProperties( apiData, frameArgs, smwSetObject )
smwCommon.addSmwProperties(
apiData,
frameArgs,
smwSetObject,
translate,
config,
data,
'Item/' .. MODULE_NAME
)
--- Not sure if size matters, not like there is a S12 Double Dog
--- FIXME: SMW_Size is from Module:Item, I made a duplicated entry in Module:Item/Food/i18n.json to make this work
smwSetObject[ t( 'SMW_Size' ) ] = nil
--- GEND and GENF are placeholders
--- FIXME: Same as above
if smwSetObject[ t( 'SMW_Manufacturer' ) ] == '[[GEND]]' or smwSetObject[ t( 'SMW_Manufacturer' ) ] == '[[GENF]]' then
smwSetObject[ t( 'SMW_Manufacturer' ) ] = nil
end
--- We only know whether the item is single use or not
if smwSetObject[ t( 'SMW_Uses' ) ] == true then
smwSetObject[ t( 'SMW_Uses' ) ] = 1
else
smwSetObject[ t( 'SMW_Uses' ) ] = nil
end
if smwSetObject[ t( 'SMW_Effect' ) ] == 'None' then
smwSetObject[ t( 'SMW_Effect' ) ] = nil
end
end
--- Adds all SMW parameters set by this Module to the ASK object
---
--- @param smwAskObject table
--- @return nil
function p.addSmwAskProperties( smwAskObject )
smwCommon.addSmwAskProperties(
smwAskObject,
translate,
config,
data
)
end
--- Adds entries to the infobox
---
--- @param infobox table The Module:InfoboxNeue instance
--- @param smwData table Data from Semantic MediaWiki
--- @return nil
function p.addInfoboxData( infobox, smwData )
infobox:renderSection( {
content = {
infobox:renderItem( {
label = translate( 'LBL_Effect' ),
data = infobox.tableToCommaList( smwData[ t( 'SMW_Effect' ) ] ),
colspan = 2
} ),
infobox:renderItem( {
label = translate( 'LBL_NutritionalDensityRating' ),
data = smwData[ t( 'SMW_NutritionalDensityRating' ) ],
} ),
infobox:renderItem( {
label = translate( 'LBL_HydrationEfficacyIndex' ),
data = smwData[ t( 'SMW_HydrationEfficacyIndex' ) ],
} ),
infobox:renderItem( {
label = translate( 'LBL_Uses' ),
data = smwData[ t( 'SMW_Uses' ) ],
} )
},
col = 4
} )
end
--- Add categories that are set on the page.
--- The categories table should only contain category names, no MW Links, i.e. 'Foo' instead of '[[Category:Foo]]'
---
--- @param categories table The categories table
--- @param frameArgs table Frame arguments from Module:Arguments
--- @param smwData table Data from Semantic MediaWiki
--- @return nil
function p.addCategories( categories, frameArgs, smwData )
end
--- Return the short description for this object
---
--- @param frameArgs table Frame arguments from Module:Arguments
--- @param smwData table Data from Semantic MediaWiki
--- @return string|nil
function p.getShortDescription( frameArgs, smwData )
end
return p