模块:Phrases:修订间差异
来自「荏苒之境」
无编辑摘要 |
无编辑摘要 |
||
第1行: | 第1行: | ||
local translation = require("Module:Template translation") | local translation = require("Module:Template translation") | ||
local utils_str = require("Module:Utils/String") | |||
local cargo = mw.ext.cargo | local cargo = mw.ext.cargo | ||
local escape_sql = utils_str.escape_sql | |||
local PHRASE_THEMES_TABLE = "PhraseThemes" | |||
local phrases = {} | local phrases = {} | ||
phrases.show = function(frame) | phrases.show = function(frame) | ||
local | local args = frame.args | ||
local theme = | local table_name = escape_sql(args.table) | ||
local theme = escape_sql(args.theme) | |||
local parent_frame = frame:getParent() | local parent_frame = frame:getParent() | ||
第14行: | 第20行: | ||
end | end | ||
cargo. | local theme_query = cargo.query(PHRASE_THEMES_TABLE, "_ID", { | ||
PhraseTable = table_name | where = "PhraseTable='"..table_name.."' AND Theme='"..theme.."'" | ||
}) | }) | ||
if #theme_query == 0 then | |||
cargo.store(PHRASE_THEMES_TABLE, { | |||
PhraseTable = table_name, | |||
Theme = theme | |||
}) | |||
end | |||
local t = {"<p>[[世界标识码]]:", theme, "</p><ul>"} | local t = {"<p>[[世界标识码]]:", theme, "</p><ul>"} |
2025年8月23日 (六) 19:50的版本
此模块的文档可以在模块:Phrases/doc创建
local translation = require("Module:Template translation")
local utils_str = require("Module:Utils/String")
local cargo = mw.ext.cargo
local escape_sql = utils_str.escape_sql
local PHRASE_THEMES_TABLE = "PhraseThemes"
local phrases = {}
phrases.show = function(frame)
local args = frame.args
local table_name = escape_sql(args.table)
local theme = escape_sql(args.theme)
local parent_frame = frame:getParent()
local language = translation.getCurrentLanguageSubpage()
if language == nil or language == "" then
language = "zh-cn"
end
local theme_query = cargo.query(PHRASE_THEMES_TABLE, "_ID", {
where = "PhraseTable='"..table_name.."' AND Theme='"..theme.."'"
})
if #theme_query == 0 then
cargo.store(PHRASE_THEMES_TABLE, {
PhraseTable = table_name,
Theme = theme
})
end
local t = {"<p>[[世界标识码]]:", theme, "</p><ul>"}
for _, phrase in ipairs(parent_frame.args) do
cargo.store(table_name, {
Language = language,
Phrase = phrase,
Theme = theme
})
t[#t+1] = "<li>"
t[#t+1] = frame:preprocess(phrase)
t[#t+1] = "</li>"
end
t[#t+1] = "</ul>"
return table.concat(t)
end
return phrases