Editing Module:Card/models/Locale

Jump to: navigation, search

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:
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
 
-- 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 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 lore              string    The card description/effect portion of the lore (Should not include italic markup)
-- @field condition          string    The condition portion of the lore (Should not include parentheses)
+
-- @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,
baseRomanizedName = nil,
 
 
translatedName = nil,
 
translatedName = nil,
baseTranslatedName = nil,
 
 
pendulumEffect = nil,
 
pendulumEffect = nil,
 
material = nil,
 
material = nil,
requirement = nil,
 
 
lore = nil,
 
lore = nil,
condition = nil,
+
archetypeCondition = nil,
 
}
 
}
  
Line 46: Line 29:
 
romanizedNames = false,
 
romanizedNames = false,
 
italicLores    = true,
 
italicLores    = true,
text          = {
 
['Requirement']        = '[REQUIREMENT]',
 
['Effect']              = '[EFFECT]',
 
['Continuous Effect']  = '[CONTINUOUS EFFECT]',
 
['Multi-Choice Effect'] = '[MULTI-CHOICE EFFECT]'
 
}
 
 
},
 
},
 
fr = {
 
fr = {
Line 59: Line 36:
 
romanizedNames = false,
 
romanizedNames = false,
 
italicLores    = true,
 
italicLores    = true,
text          = {}
 
 
},
 
},
 
de = {
 
de = {
Line 67: Line 43:
 
romanizedNames = false,
 
romanizedNames = false,
 
italicLores    = true,
 
italicLores    = true,
text          = {}
 
 
},
 
},
 
it = {
 
it = {
Line 75: Line 50:
 
romanizedNames = false,
 
romanizedNames = false,
 
italicLores    = true,
 
italicLores    = true,
text          = {}
 
 
},
 
},
 
pt = {
 
pt = {
Line 83: Line 57:
 
romanizedNames = false,
 
romanizedNames = false,
 
italicLores    = true,
 
italicLores    = true,
text          = {}
 
 
},
 
},
 
es = {
 
es = {
Line 91: Line 64:
 
romanizedNames = false,
 
romanizedNames = false,
 
italicLores    = true,
 
italicLores    = true,
text          = {}
 
 
},
 
},
 
ja = {
 
ja = {
Line 99: Line 71:
 
romanizedNames = true,
 
romanizedNames = true,
 
italicLores    = false,
 
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 = {
 
zh = {
Line 112: Line 78:
 
romanizedNames = true,
 
romanizedNames = true,
 
italicLores    = false,
 
italicLores    = false,
text          = {}
 
 
},
 
},
 
tc = {
 
tc = {
Line 118: Line 83:
 
langCode      = 'zh',
 
langCode      = 'zh',
 
scriptCode    = 'Hant',
 
scriptCode    = 'Hant',
romanizedNames = true,
+
romanizedNames = false,
italicLores    = false,
+
italicLores    = true,
text          = {}
 
 
},
 
},
 
sc = {
 
sc = {
Line 128: Line 92:
 
romanizedNames = true,
 
romanizedNames = true,
 
italicLores    = false,
 
italicLores    = false,
text          = {}
 
 
},
 
},
 
ko = {
 
ko = {
Line 136: Line 99:
 
romanizedNames = true,
 
romanizedNames = true,
 
italicLores    = false,
 
italicLores    = false,
text          = {
 
['Requirement']        = '【조건】',
 
['Effect']              = '【효과】',
 
['Continuous Effect']  = '【지속 효과】',
 
['Multi-Choice Effect'] = '【선택 효과】'
 
}
 
 
},
 
},
ru = {
 
name          = 'Russian',
 
langCode      = 'ru',
 
scriptCode    = nil,
 
romanizedNames = true,
 
italicLores    = false,
 
text          = {}
 
}
 
 
}
 
}
  
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 = mw.clone(Locale)
+
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']                 or nil
+
l.name              = params[prefix .. 'name']               or nil
l.romanizedName      = params[prefix .. 'romanized_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.translatedName    = params[prefix .. 'translated_name']     or nil
+
l.pendulumEffect    = params[prefix .. 'pendulum_effect']     or nil
l.baseTranslatedName = params[prefix .. 'base_translated_name'] or nil
+
l.material          = params[prefix .. 'material']           or nil
l.pendulumEffect    = params[prefix .. 'pendulum_effect']     or nil
+
l.lore              = params[prefix .. 'lore']               or nil
l.material          = params[prefix .. 'material']             or nil
+
l.archetypeCondition = params[prefix .. 'archetype_condition'] 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.condition          = params[prefix .. 'condition'] or nil
 
  
 
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     = 'ja_romanized_name',
+
romaji_name = 'ja_romanized_name',
base_romaji_name = 'ja_base_romanized_name',
+
trans_name = 'ja_translated_name',
trans_name       = 'ja_translated_name',
+
ko_rr_name = 'ko_romanized_name'
base_trans_name = 'ja_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'
 
 
}
 
}
  
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 (
isFilled(params[lang .. '_name']) or
+
params[lang .. '_name'] or
isFilled(params[lang .. '_lore']) or
+
params[lang .. '_lore'] or
isFilled(params[lang .. '_pendulum_effect']) or
+
params[lang .. '_pendulum_effect'] or
isFilled(params[lang .. '_material']) or
+
params[lang .. '_material'] or
isFilled(params[lang .. '_archetype_condition']) or
+
params[lang .. '_archetype_condition'] or
isFilled(params[lang .. '_summoning_condition']) or
+
params[lang .. '_romanized_name'] or
isFilled(params[lang .. '_romanized_name']) or
+
params[lang .. '_translated_name']
isFilled(params[lang .. '_translated_name'])
+
) and true or false
)
 
end
 
 
 
-- Get the name without any ruby annotations
 
-- e.g. デーモンの{{Ruby|召|しょう}}{{Ruby|喚|かん}} → デーモンの召喚
 
-- @return string
 
function Locale:getBaseName()
 
return Ruby.split(self.name)
 
 
end
 
end
  
-- Get the name favoring "top" text over base text for ruby annotations
+
-- Get the name of the instance's language
-- e.g. デーモンの{{Ruby|召|しょう}}{{Ruby|喚|かん}} → デーモンのしょうかん
 
 
-- @return string
 
-- @return string
function Locale:getTopName()
+
function Locale:getLanguageName()
return Ruby.split(self.name, 'top')
+
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
 
 
-- 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
 
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   Card    The full card object
+
-- @param boolean isNormalMonster - If the card is a Normal monster
 
-- @return string
 
-- @return string
function Locale:getFullLore(card)
+
function Locale:getFullLore(isNormalMonster)
 
local output = ''
 
local output = ''
local condition = nil
+
local archetypeCondition = nil
  
if (self.condition) then
+
if (self.archetypeCondition) then
condition = '(' .. self.condition .. ')'
+
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 (card.isNormalMonster) then
+
if (isNormalMonster) then
local output = isFilled(self.lore) and self.lore or ''
+
local output = self.lore
+
 
if (self.language.italicLores and isFilled(self.lore)) then
+
if (self.language.italicLores) then
output = '<i>' .. self.lore .. '</i>'
+
output = output .. '<i>' .. output .. '</i>'  
 
end
 
end
  
if (condition) then
+
if (archetypeCondition) then
output = output .. '<br /><br />' .. condition
+
output = output .. '<br /><br />' .. archetypeCondition
 
end
 
end
  
Line 324: Line 245:
  
 
-- Handle everything else
 
-- Handle everything else
lore = self.lore
+
-- Array of different lore comporenents
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 components
 
 
local loreParts = {
 
local loreParts = {
 
self.material or nil,
 
self.material or nil,
condition or nil,
+
archetypeCondition or nil,
self.summoningCondition or nil,
+
self.lore or nil
requirement,
 
lore or nil,
 
 
}
 
}
+
 
 
-- Remove empty values
 
-- Remove empty values
 
loreParts = TableTools.compressSparseArray(loreParts)
 
loreParts = TableTools.compressSparseArray(loreParts)

Please note that all contributions to Yugipedia are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 International License (see Yugipedia:Licensing for more details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)
Preview page with this template
Below are some commonly used wiki markup codes. Simply click on what you want to use and it will appear in the edit box above.

View this template