模組討論:WikitextLC

由Tigerzeng在話題提供批量單向轉換函數上作出的最新留言:3 年前

加一點洋文的文檔

編輯

  請求已處理

我給mw:Writing_systems#LanguageConverter加了行字,說可以用這玩意整個Lua的懶人接口。不過既然那麼整了就得搞點洋文的文檔了……

local p = {}

--- Construct an inline conversion from a table input.
-- @param content table of the form
--        { ["zh-cn"]='foobar', ["zh-tw"]='firecat', ["zh-hk"]='' }
-- @returns string
--       "-{zh-cn:foobar;zh-tw:firecat;zh-hk:<span></span>}-"
--
-- @fixme allow for generating output without "-{" "}-", so that
--        it can be used with the last three wrappers.
function p.selective( content )
    -- 内容略去
end

--- Write some text with a limited set of variants to convert to
--
-- @param content text to be written
-- @param variant a variant (string), or a list of variants
--        (semicolon-deliminated string, or table of strings)
-- @param[opt] force convert even under "zh" (no conversion) locale
function p.converted( content, variant, force )
    if type( variant ) == 'table' then
        variant = table.concat( variant, ';' )
    end
    return '-{' .. ( force and '' or 'zh;' ) .. variant .. '|' .. content .. '}-'
end

--- Wraps some "raw text" to not convert.
--
-- @fixme Is the "R" flag some undocumented/undefined no-op magic?
--        Are we using it instead of the old '-{' .. content .. '}-'
--        to avoid confusion caused by a flag in the "content"?
function p.raw( content )
    return '-{R|' .. content .. '}-'
end

--- Wraps a title conversion rule.
function p.title( content )
    return '-{T|' .. content .. '}-'
end

--- Wraps a (hidden) conversion rule definition.
function p.hidden( content )
    return '-{H|' .. content .. '}-'
end

return p

Fixme的問題順便看一下吧。 --Artoria2e5 討論要完整回覆請用ping 2018年4月30日 (一) 01:44 (UTC)回覆

提供批量單向轉換函數

編輯

  請求已拒絕

目前單向轉換沒有回落,用起來偶爾還是挺頭疼的:寫hk也要寫mo,寫cn也得要hans和sg。如果能提供一個生成多個單向轉換的函數,應該可以方便一點。請加入以下內容:

-- Generates multiple monodirection conversions
-- (str, str, str[]) → str
function p.mono(source, target, variants)
	local tmp = {}
	for _, var in ipairs(variants) do
		-- A=>zh-tw:B
		table.insert(tmp, source .. '=>' .. var .. ':' .. target)
	end
	return table.concat(tmp, ';')
end

--Artoria2e5 討論要完整回覆請用ping 2021年1月31日 (日) 09:26 (UTC)回覆

  • (-)反對:部分字詞只適宜在一個顯示模式下轉換,其他顯示模式下都不應該轉換(例如「南韓」應該在中國大陸模式下轉換為「韓國」,但在其他模式下都不應該轉換,包括新加坡簡體和大馬簡體)。請求進一步闡釋預期實際應用效果。SANMOSA SPQR 2021年1月31日 (日) 09:41 (UTC)回覆
    • sanmosa,不少hk的單向轉換都沒有加入mo項目,{ type = 'item', original = 'crème brûlée', rule = '烤布蕾 => zh-cn:法式燉蛋; 烤布蕾 => zh-hk:焦糖布甸;'}正為一例。使用 Google 搜尋就可以在各種美食點評網站上找到使用 hk 名稱的澳門店鋪。況且這只是方便批量生成的工具,具體同時出哪些 variant 是人類傳入的參數決定的。我真的不懂你在反對什麼。--Artoria2e5 討論要完整回覆請用ping 2021年2月2日 (二) 13:55 (UTC)回覆
      我反對的點在於有些時候單向轉換就是只能轉cn、不能轉sg和my;只能轉tw、不能轉hk和mo。上面的情況的單向轉換不在少數,這種批量生成的工具很容易誤用,你這樣無疑會衍生更嚴重的副作用。我認為應增加文字警示以提醒用戶。SANMOSA SPQR 2021年2月3日 (三) 00:13 (UTC)回覆
  • 存在異議,暫關閉。請討論得出結論後再提出編輯請求。--Tiger留言2021年2月22日 (一) 03:44 (UTC)回覆
返回 "WikitextLC" 頁面。