模块:Phrases:修订间差异
来自「荏苒之境」
无编辑摘要 |
无编辑摘要 |
||
第18行: | 第18行: | ||
local theme_text = parent_frame.args.theme_text | local theme_text = parent_frame.args.theme_text | ||
if theme_text == nil or theme_text == "" then | if theme_text == nil or theme_text == "" then | ||
theme_text = escape_sql(trim(theme_text)) | theme_text = escape_sql(trim(theme_text)) | ||
end | end | ||
第27行: | 第25行: | ||
if language == nil or language == "" then | if language == nil or language == "" then | ||
language = "zh-cn" | language = "zh-cn" | ||
end | |||
local theme_translation | |||
if theme_text ~= nil and theme_text ~= "" then | |||
theme_translation = {language, theme_text} | |||
end | end | ||
第36行: | 第39行: | ||
PhraseTable = table_name, | PhraseTable = table_name, | ||
Theme = theme, | Theme = theme, | ||
Translations = mw.text.jsonEncode { | Translations = theme_translation and mw.text.jsonEncode {theme_translation} | ||
}) | }) | ||
elseif theme_translation ~= nil then | |||
local trans = mw.text.jsonDecode(theme_query[1].Translations) | local trans = mw.text.jsonDecode(theme_query[1].Translations) | ||
trans[#trans+1] = {language, theme_text} | trans[#trans+1] = {language, theme_text} |
2025年8月23日 (六) 23:29的版本
此模块的文档可以在模块: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 trim = utils_str.trim
local PHRASE_THEMES_TABLE = "PhraseThemes"
local phrases = {}
phrases.show = function(frame)
local args = frame.args
local table_name = escape_sql(args.table)
local parent_frame = frame:getParent()
local theme = escape_sql(trim(parent_frame.args[1]))
local theme_text = parent_frame.args.theme_text
if theme_text == nil or theme_text == "" then
theme_text = escape_sql(trim(theme_text))
end
local language = translation.getCurrentLanguageSubpage()
if language ~= "zh-cn" then
if language == nil or language == "" then
language = "zh-cn"
end
local theme_translation
if theme_text ~= nil and theme_text ~= "" then
theme_translation = {language, theme_text}
end
local theme_query = cargo.query(PHRASE_THEMES_TABLE, "_ID,Translations", {
where = "PhraseTable='"..table_name.."' AND Theme='"..theme.."'"
})
if #theme_query == 0 then
cargo.store(PHRASE_THEMES_TABLE, {
PhraseTable = table_name,
Theme = theme,
Translations = theme_translation and mw.text.jsonEncode {theme_translation}
})
elseif theme_translation ~= nil then
local trans = mw.text.jsonDecode(theme_query[1].Translations)
trans[#trans+1] = {language, theme_text}
cargo.store(PHRASE_THEMES_TABLE, {
_ID = theme_query[1]._ID,
Translations = mw.text.jsonEncode(trans)
})
end
for i, phrase in ipairs(parent_frame.args) do
if i ~= 1 then
cargo.store(table_name, {
Language = language,
Phrase = escape_sql(trim(phrase)),
Theme = theme
})
end
end
end
local t = {"<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