Changes

Jump to: navigation, search

Module:Card/models/Locale

3,472 bytes added, 5 months ago
It should still be okay to make this local.
local Ruby = require('Module:Ruby')
 
-- Generic functions
 
-- Check if a value is filled (i.e. not `nil` or an empty string)
-- @param value mixed
-- @return boolean
local function isFilled(value)
return (value ~= nil and value ~= '')
end
 
 
-- Base object for the Locale
-- Represents a card's details in a particular language
-- @field pendulumEffect string The card's Penudlum Effect
-- @field material string The material portion of the card's lore
-- @field summoningCondition string The Summoning condition portion of the card's lore
-- @field requirement string The requirement portion of the card's lore (Should not include the '[REQUIREMENT]' prefix)
-- @field lore string The card description/effect portion of the lore (Should not include italic markup)
-- @field archetypeCondition condition string The archetype condition portion of the lore (Should not include parentheses)
local Locale = {
lang = nil,
name = nil,
romanizedName = nil,
baseRomanizedName = nil,
translatedName = nil,
baseTranslatedName = nil,
pendulumEffect = nil,
material = nil,
requirement = nil,
lore = nil,
archetypeCondition condition = nil,
}
romanizedNames = false,
italicLores = true,
text = {
['Requirement'] = '[REQUIREMENT]',
['Effect'] = '[EFFECT]',
['Continuous Effect'] = '[CONTINUOUS EFFECT]',
['Multi-Choice Effect'] = '[MULTI-CHOICE EFFECT]'
}
},
fr = {
romanizedNames = false,
italicLores = true,
text = {}
},
de = {
romanizedNames = false,
italicLores = true,
text = {}
},
it = {
romanizedNames = false,
italicLores = true,
text = {}
},
pt = {
romanizedNames = false,
italicLores = true,
text = {}
},
es = {
romanizedNames = false,
italicLores = true,
text = {}
},
ja = {
romanizedNames = true,
italicLores = false,
text = {
['Requirement'] = '【<ruby><rb>条</rb><rt>じょう</rt><rb>件</rb><rt>けん</rt>】',
['Effect'] = '【<ruby><rb>効</rb><rt>こう</rt><rb>果</rb><rt>か</rt>】',
['Continuous Effect'] = '【<ruby><rb>永</rb><rt>えい</rt><rb>続</rb><rt>ぞく</rt><rb>効</rb><rt>こう</rt><rb>果</rb><rt>か</rt></ruby>】',
['Multi-Choice Effect'] = '【<ruby><rb>選</rb><rt>せん</rt><rb>択</rb><rt>たく</rt><rb>効</rb><rt>こう</rt><rb>果</rb><rt>か</rt></ruby>】'
}
},
zh = {
romanizedNames = true,
italicLores = false,
text = {}
},
tc = {
langCode = 'zh',
scriptCode = 'Hant',
romanizedNames = falsetrue, italicLores = truefalse, text = {}
},
sc = {
romanizedNames = true,
italicLores = false,
text = {}
},
ko = {
romanizedNames = true,
italicLores = false,
text = {
['Requirement'] = '【조건】',
['Effect'] = '【효과】',
['Continuous Effect'] = '【지속 효과】',
['Multi-Choice Effect'] = '【선택 효과】'
}
},
ru = {
name = 'Russian',
langCode = 'ru',
scriptCode = nil,
romanizedNames = true,
italicLores = false,
text = {}
}
}
function Locale:new(lang, params)
-- Create a new instance of the Locale class with all the default values
local l = {} setmetatablemw.clone(l, Locale) Locale.__index = Locale
-- English parameters don't have a prefix e.g. `name`, `lore`
l.lang = lang
l.language = languages[lang]
l.name = params[prefix .. 'name'] or nil l.romanizedName = params[prefix .. 'romanized_name'] or nil l.baseRomanizedName = params[prefix .. 'base_romanized_name'] or nil l.translatedName = params[prefix .. 'translated_name'] or nil l.baseTranslatedName = params[prefix .. 'base_translated_name'] or nil l.pendulumEffect = params[prefix .. 'pendulum_effect'] or nil l.material = params[prefix .. 'material'] or nil l.summoningCondition = params[prefix .. 'summoning_condition'] or nil l.requirement = params[prefix .. 'requirement'] or nil l.lore = params[prefix .. 'lore'] or nil l.archetypeCondition condition = params[prefix .. 'archetype_conditioncondition'] or nil
return l
-- table mapping labels to standardized ones
local mappings = {
romaji_name = 'ja_romanized_name', base_romaji_name = 'ja_base_romanized_name', trans_name = 'ja_translated_name', base_trans_name = 'ja_translated_nameja_base_translated_name', zh_pinyin_name = 'zh_romanized_name', tc_pinyin_name = 'tc_romanized_name', sc_pinyin_name = 'sc_romanized_name', ko_rr_name = 'ko_romanized_name'
}
-- Check if at least one param is supplied for the language
return (
isFilled(params[lang .. '_name'] ) or isFilled(params[lang .. '_lore'] ) or isFilled(params[lang .. '_pendulum_effect'] ) or isFilled(params[lang .. '_material'] ) or isFilled(params[lang .. '_archetype_condition'] ) or isFilled(params[lang .. '_summoning_condition']) or isFilled(params[lang .. '_romanized_name'] ) or isFilled(params[lang .. '_translated_name']) ) and true or falseend -- Get the name without any ruby annotations-- e.g. デーモンの{{Ruby|召|しょう}}{{Ruby|喚|かん}} → デーモンの召喚-- @return stringfunction Locale:getBaseName() return Ruby.split(self.name)
end
-- Get the name of the instance's languagefavoring "top" text over base text for ruby annotations-- e.g. デーモンの{{Ruby|召|しょう}}{{Ruby|喚|かん}} → デーモンのしょうかん
-- @return string
function Locale:getLanguageNamegetTopName() return Ruby.split(self.language.name, 'top')
end
function Locale:getRomanizedHtmlLang()
return self.language.langCode .. '-Latn'
end
 
-- Get a piece of text in the current language
-- @param message string
-- @return string
function Locale:getText(message)
-- If the language has a translation for the message use that
return self.language.text[message]
-- Otherwise use the English one if it exists
or languages.en[message]
-- Otherwise just return the supplied text
or message
end
-- Put the material, lore and archetype condition together to form the full lore
-- @param boolean isNormalMonster - If the card is a Normal monster Card The full card object
-- @return string
function Locale:getFullLore(isNormalMonstercard)
local output = ''
local archetypeCondition condition = nil
if (self.archetypeConditioncondition) then archetypeCondition condition = '(' .. self.archetypeCondition condition .. ')'
end
-- Handle Normal Monsters
-- Lore (with italics depending on language, followed by archetype condition)
if (card.isNormalMonster) then local output = isFilled(self.lore) and self.loreor '' if (self.language.italicLoresand isFilled(self.lore)) then output = output .. '<i>' .. output self.lore .. '</i>'
end
if (archetypeConditioncondition) then output = output .. '<br /><br />' .. archetypeConditioncondition
end
-- Handle everything else
lore = self.lore requirement = self.requirement  -- If there is a requirement, prefix the lore and requirement with their labels if (isFilled(self.requirement)) then requirement = '<b>' .. self:getText('Requirement') .. '</b> ' .. requirement lore = '<b>' .. self:getText(card.mainEffectType or 'Effect') .. '</b> ' .. lore end  -- Array of different lore comporenentscomponents
local loreParts = {
self.material or nil,
archetypeCondition condition or nil, self.summoningCondition or nil, requirement, lore or nil,
}
-- Remove empty values
loreParts = TableTools.compressSparseArray(loreParts)

Navigation menu