Editing Module:Card/models/Locale
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.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
This page is not enabled for semantic in-text annotations due to namespace restrictions. Details about how to enable the namespace can be found on the configuration help page.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
-- Base object for the Locale | -- Base object for the Locale | ||
-- Represents a card's details in a particular language | -- Represents a card's details in a particular language | ||
Line 21: | Line 9: | ||
-- @field pendulumEffect string The card's Penudlum Effect | -- @field pendulumEffect string The card's Penudlum Effect | ||
-- @field material string The material portion of the card's lore | -- @field material string The material portion of the card's lore | ||
− | |||
− | |||
-- @field lore string The card description/effect portion of the lore (Should not include italic markup) | -- @field lore string The card description/effect portion of the lore (Should not include italic markup) | ||
− | -- @field | + | -- @field archetypeCondition string The archetype condition portion of the lore (Should not include parentheses) |
local Locale = { | local Locale = { | ||
lang = nil, | lang = nil, | ||
name = nil, | name = nil, | ||
romanizedName = nil, | romanizedName = nil, | ||
− | |||
translatedName = nil, | translatedName = nil, | ||
− | |||
pendulumEffect = nil, | pendulumEffect = nil, | ||
material = nil, | material = nil, | ||
− | |||
lore = nil, | lore = nil, | ||
− | + | archetypeCondition = nil, | |
} | } | ||
Line 46: | Line 29: | ||
romanizedNames = false, | romanizedNames = false, | ||
italicLores = true, | italicLores = true, | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
}, | }, | ||
fr = { | fr = { | ||
Line 59: | Line 36: | ||
romanizedNames = false, | romanizedNames = false, | ||
italicLores = true, | italicLores = true, | ||
− | |||
}, | }, | ||
de = { | de = { | ||
Line 67: | Line 43: | ||
romanizedNames = false, | romanizedNames = false, | ||
italicLores = true, | italicLores = true, | ||
− | |||
}, | }, | ||
it = { | it = { | ||
Line 75: | Line 50: | ||
romanizedNames = false, | romanizedNames = false, | ||
italicLores = true, | italicLores = true, | ||
− | |||
}, | }, | ||
pt = { | pt = { | ||
Line 83: | Line 57: | ||
romanizedNames = false, | romanizedNames = false, | ||
italicLores = true, | italicLores = true, | ||
− | |||
}, | }, | ||
es = { | es = { | ||
Line 91: | Line 64: | ||
romanizedNames = false, | romanizedNames = false, | ||
italicLores = true, | italicLores = true, | ||
− | |||
}, | }, | ||
ja = { | ja = { | ||
Line 99: | Line 71: | ||
romanizedNames = true, | romanizedNames = true, | ||
italicLores = false, | italicLores = false, | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
}, | }, | ||
zh = { | zh = { | ||
Line 112: | Line 78: | ||
romanizedNames = true, | romanizedNames = true, | ||
italicLores = false, | italicLores = false, | ||
− | |||
}, | }, | ||
tc = { | tc = { | ||
Line 118: | Line 83: | ||
langCode = 'zh', | langCode = 'zh', | ||
scriptCode = 'Hant', | scriptCode = 'Hant', | ||
− | romanizedNames = | + | romanizedNames = false, |
− | italicLores = | + | italicLores = true, |
− | |||
}, | }, | ||
sc = { | sc = { | ||
Line 128: | Line 92: | ||
romanizedNames = true, | romanizedNames = true, | ||
italicLores = false, | italicLores = false, | ||
− | |||
}, | }, | ||
ko = { | ko = { | ||
Line 136: | Line 99: | ||
romanizedNames = true, | romanizedNames = true, | ||
italicLores = false, | italicLores = false, | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
}, | }, | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
Line 159: | Line 108: | ||
function Locale:new(lang, params) | function Locale:new(lang, params) | ||
-- Create a new instance of the Locale class with all the default values | -- Create a new instance of the Locale class with all the default values | ||
− | local l = | + | local l = {} |
+ | setmetatable(l, Locale) | ||
+ | Locale.__index = Locale | ||
-- English parameters don't have a prefix e.g. `name`, `lore` | -- English parameters don't have a prefix e.g. `name`, `lore` | ||
Line 167: | Line 118: | ||
l.lang = lang | l.lang = lang | ||
l.language = languages[lang] | l.language = languages[lang] | ||
− | l.name = params[prefix .. 'name'] | + | l.name = params[prefix .. 'name'] or nil |
− | l.romanizedName = params[prefix .. 'romanized_name'] | + | l.romanizedName = params[prefix .. 'romanized_name'] or nil |
− | + | l.translatedName = params[prefix .. 'translated_name'] or nil | |
− | l.translatedName = params[prefix .. 'translated_name'] | + | l.pendulumEffect = params[prefix .. 'pendulum_effect'] or nil |
− | + | l.material = params[prefix .. 'material'] or nil | |
− | l.pendulumEffect = params[prefix .. 'pendulum_effect'] | + | l.lore = params[prefix .. 'lore'] or nil |
− | l.material = params[prefix .. 'material'] | + | l.archetypeCondition = params[prefix .. 'archetype_condition'] or nil |
− | |||
− | |||
− | l.lore = params[prefix .. 'lore'] | ||
− | l. | ||
return l | return l | ||
Line 209: | Line 156: | ||
-- table mapping labels to standardized ones | -- table mapping labels to standardized ones | ||
local mappings = { | local mappings = { | ||
− | romaji_name | + | romaji_name = 'ja_romanized_name', |
− | + | trans_name = 'ja_translated_name', | |
− | trans_name | + | ko_rr_name = 'ko_romanized_name' |
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
Line 240: | Line 182: | ||
-- Check if at least one param is supplied for the language | -- Check if at least one param is supplied for the language | ||
return ( | return ( | ||
− | + | params[lang .. '_name'] or | |
− | + | params[lang .. '_lore'] or | |
− | + | params[lang .. '_pendulum_effect'] or | |
− | + | params[lang .. '_material'] or | |
− | + | params[lang .. '_archetype_condition'] or | |
− | + | params[lang .. '_romanized_name'] or | |
− | + | params[lang .. '_translated_name'] | |
− | + | ) and true or false | |
− | ) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | -- Get the name | + | -- Get the name of the instance's language |
− | |||
-- @return string | -- @return string | ||
− | function Locale: | + | function Locale:getLanguageName() |
− | return | + | return self.language.name |
end | end | ||
Line 282: | Line 215: | ||
function Locale:getRomanizedHtmlLang() | function Locale:getRomanizedHtmlLang() | ||
return self.language.langCode .. '-Latn' | return self.language.langCode .. '-Latn' | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
-- Put the material, lore and archetype condition together to form the full lore | -- Put the material, lore and archetype condition together to form the full lore | ||
− | -- @param card | + | -- @param boolean isNormalMonster - If the card is a Normal monster |
-- @return string | -- @return string | ||
− | function Locale:getFullLore( | + | function Locale:getFullLore(isNormalMonster) |
local output = '' | local output = '' | ||
− | local | + | local archetypeCondition = nil |
− | if (self. | + | if (self.archetypeCondition) then |
− | + | archetypeCondition = '(' .. self.archetypeCondition .. ')' | |
end | end | ||
-- Handle Normal Monsters | -- Handle Normal Monsters | ||
-- Lore (with italics depending on language, followed by archetype condition) | -- Lore (with italics depending on language, followed by archetype condition) | ||
− | if ( | + | if (isNormalMonster) then |
− | local output = | + | local output = self.lore |
− | + | ||
− | if (self.language.italicLores | + | if (self.language.italicLores) then |
− | output = '<i>' .. | + | output = output .. '<i>' .. output .. '</i>' |
end | end | ||
− | if ( | + | if (archetypeCondition) then |
− | output = output .. '<br /><br />' .. | + | output = output .. '<br /><br />' .. archetypeCondition |
end | end | ||
Line 324: | Line 245: | ||
-- Handle everything else | -- Handle everything else | ||
− | + | -- Array of different lore comporenents | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | -- Array of different lore | ||
local loreParts = { | local loreParts = { | ||
self.material or nil, | self.material or nil, | ||
− | + | archetypeCondition or nil, | |
− | self. | + | self.lore or nil |
− | |||
− | |||
} | } | ||
− | + | ||
-- Remove empty values | -- Remove empty values | ||
loreParts = TableTools.compressSparseArray(loreParts) | loreParts = TableTools.compressSparseArray(loreParts) |