模块:I18n:修订间差异
来自星露谷物语扩展百科
更多操作
删除的内容 添加的内容
创建页面 |
无编辑摘要 |
||
| (未显示2个用户的2个中间版本) | |||
| 第1行: | 第1行: | ||
local Utils = require("Module:Utils") |
local Utils = require("Module:Utils") |
||
local ZH = Utils.LazyLoad("Module: |
local ZH = Utils.LazyLoad("Module:i18n/zh", true) |
||
local EN = Utils.LazyLoad("Module: |
local EN = Utils.LazyLoad("Module:i18n/en", true) |
||
local p = {} |
local p = {} |
||
| 第24行: | 第24行: | ||
function p.getEnglishText(input) |
function p.getEnglishText(input) |
||
local key = cleanKey(getArg(input)) |
local key = cleanKey(getArg(input)) |
||
return EN[key] or key |
return EN[key:lower()] or key |
||
end |
end |
||
function p.getChineseText(input) |
function p.getChineseText(input) |
||
local key = cleanKey(getArg(input)) |
local key = cleanKey(getArg(input)) |
||
return ZH[ |
return ZH[key:lower()] or key |
||
end |
end |
||
2025年12月21日 (日) 17:59的最新版本
local Utils = require("Module:Utils")
local ZH = Utils.LazyLoad("Module:i18n/zh", true)
local EN = Utils.LazyLoad("Module:i18n/en", true)
local p = {}
local function getArg(input)
if type(input) == "string" then
return input
end
return input.args[1] or input:getParent().args[1]
end
local function cleanKey(str)
local match = string.match(str, "{{i18n:(.-)}}")
if match then
return match
else
return str
end
end
function p.getEnglishText(input)
local key = cleanKey(getArg(input))
return EN[key:lower()] or key
end
function p.getChineseText(input)
local key = cleanKey(getArg(input))
return ZH[key:lower()] or key
end
-- =p.zh_string{args={"Gifts.Sophia.Loved"}}
function p.zh_string(frame)
local text = frame.args[1]
if not text then
return ""
end
local lowerText = string.lower(text)
local result = ZH[lowerText] or ""
result = result:gsub('@', '<span class="player-name">玩家名</span>')
return result
end
-- =p.getDefaultString{args={"<玩家名>"}}
function p.getDefaultString(frame)
local text = frame.args[1]
if not text then
return ""
end
local keyForText = nil
for key, value in pairs(ZH) do
if value == text then
keyForText = key
break
end
end
if keyForText then
return EN[keyForText] or ""
else
return ""
end
end
return p