模块:Phrases:修订间差异
来自「荏苒之境」
无编辑摘要 |
无编辑摘要 |
||
第4行: | 第4行: | ||
local cargo = mw.ext.cargo | local cargo = mw.ext.cargo | ||
local trim = utils_str.trim | local trim = utils_str.trim | ||
local escape_sql = utils_str.escape_sql | |||
local PHRASE_THEMES_TABLE = "PhraseThemes" | local PHRASE_THEMES_TABLE = "PhraseThemes" | ||
第23行: | 第24行: | ||
if language == nil or language == "" then | if language == nil or language == "" then | ||
language = "zh-cn" | language = "zh-cn" | ||
end | |||
local currentTitle = mw.title.getCurrentTitle() | |||
local existingPhrases = cargo.query(table_name, "Phrase", { | |||
where = "_pageName = '"..escape_sql(currentTitle.fullText).."'" | |||
}) | |||
for i = 1, #existingPhrases do | |||
existingPhrases[existingPhrases[i]] = true | |||
end | end | ||
第33行: | 第42行: | ||
for i, phrase in ipairs(parent_frame.args) do | for i, phrase in ipairs(parent_frame.args) do | ||
if i ~= 1 then | if i ~= 1 and existingPhrases[phrase] == nil then | ||
cargo.store(table_name, { | cargo.store(table_name, { | ||
Language = language, | Language = language, |
2025年8月28日 (四) 13:55的版本
此模块的文档可以在模块:Phrases/doc创建
local translation = require("Module:Template translation")
local utils_str = require("Module:Utils/String")
local cargo = mw.ext.cargo
local trim = utils_str.trim
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 = args.table
local theme_text = args.theme_text
if theme_text == "" then theme_text = nil end
local parent_frame = frame:getParent()
local theme = trim(parent_frame.args[1])
local language = translation.getCurrentLanguageSubpage()
if language ~= "zh-cn" then
if language == nil or language == "" then
language = "zh-cn"
end
local currentTitle = mw.title.getCurrentTitle()
local existingPhrases = cargo.query(table_name, "Phrase", {
where = "_pageName = '"..escape_sql(currentTitle.fullText).."'"
})
for i = 1, #existingPhrases do
existingPhrases[existingPhrases[i]] = true
end
cargo.store(PHRASE_THEMES_TABLE, {
PhraseTable = table_name,
Theme = theme,
Language = language,
Translation = theme_text
})
for i, phrase in ipairs(parent_frame.args) do
if i ~= 1 and existingPhrases[phrase] == nil then
cargo.store(table_name, {
Language = language,
Phrase = trim(phrase),
Theme = theme,
Time = os.time()
})
end
end
end
local t = {}
t[#t+1] = "<ul>"
for i, phrase in ipairs(parent_frame.args) do
if i ~= 1 then
t[#t+1] = "<li>"
t[#t+1] = frame:preprocess(phrase)
t[#t+1] = "</li>"
end
end
t[#t+1] = "</ul>"
return table.concat(t)
end
return phrases