đŸ‡źđŸ‡· Iran Proxy | https://www.wikipedia.org/wiki/Module_talk:String/Archive_2
Jump to content

Module talk:String/Archive 2

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
Archive 1Archive 2

Protected edit request on 21 September 2023

On Latin Wikipedia I have created a tiny module named Module:Translitteratio, which contains a single function named abecedaria. The function accepts three parameters and works exactly like the translit M4 macro (but with the order of arguments changed to chars, replacement, string). For example,

{{#invoke:translitteratio|abecedaria|aeiou|ÀëÏ|Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam mollis, metus ac volutpat auctor, sem ligula interdum nulla, ac pellentesque nibh erat sed nisi. Integer nec auctor orci. Quisque nibh metus, viverra et viverra nec, laoreet in mi. Integer aliquet, mauris vitae tristique fringilla, ante odio ultrices quam, et fermentum orci purus nec lorem. Integer quis vehicula arcu, et laoreet enim. Nulla euismod neque velit, eget iaculis massa tempor ut. Nulla convallis maximus neque et porttitor. In nunc eros, convallis id posuere ac, egestas et arcu. Aenean faucibus sollicitudin ipsum, in condimentum mauris maximus in. Etiam facilisis eros vel tortor tincidunt iaculis. Vestibulum lorem lectus, posuere sed enim in, varius pharetra lorem. Morbi nisl lacus, eleifend ut urna vitae, interdum consequat ipsum. Cras ut imperdiet ante. Sed quis luctus purus, quis porta erat. Ut gravida gravida augue a euismod.}}

generates

Lrëm Ïpsm dlr sÏt Àmët, cnsëctëtr ÀdÏpÏscÏng ëlÏt. NÀm mllÏs, mëts Àc vltpÀt Àctr, sëm lÏglÀ Ïntërdm nllÀ, Àc pëllëntësqë nÏbh ërÀt sëd nÏsÏ. Intëgër nëc Àctr rcÏ. QÏsqë nÏbh mëts, vÏvërrÀ ët vÏvërrÀ nëc, lÀrëët Ïn mÏ. Intëgër ÀlÏqët, mÀrÏs vÏtÀë trÏstÏqë frÏngÏllÀ, Àntë dÏ ltrÏcës qÀm, ët fërmëntm rcÏ prs nëc lrëm. Intëgër qÏs vëhÏclÀ Àrc, ët lÀrëët ënÏm. NllÀ ëÏsmd nëqë vëlÏt, ëgët ÏÀclÏs mÀssÀ tëmpr t. NllÀ cnvÀllÏs mÀxÏms nëqë ët prttÏtr. In nnc ërs, cnvÀllÏs Ïd psërë Àc, ëgëstÀs ët Àrc. AënëÀn fÀcÏbs sllÏcÏtdÏn Ïpsm, Ïn cndÏmëntm mÀrÏs mÀxÏms Ïn. EtÏÀm fÀcÏlÏsÏs ërs vël trtr tÏncÏdnt ÏÀclÏs. VëstÏblm lrëm lëcts, psërë sëd ënÏm Ïn, vÀrÏs phÀrëtrÀ lrëm. MrbÏ nÏsl lÀcs, ëlëÏfënd t rnÀ vÏtÀë, Ïntërdm cnsëqÀt Ïpsm. CrÀs t ÏmpërdÏët Àntë. Sëd qÏs lcts prs, qÏs prtÀ ërÀt. Ut grÀvÏdÀ grÀvÏdÀ Àgë À ëÏsmd.

(You can experiment with it in the Latin Wikipedia sandbox page)

This allowed to write the {{la:Sine notis diacriticis}} template, which transforms vowels with various accents into simple vowels, and the {{la:Ufrac}} template, which writes fractions using only Unicode characters (no HTML).

I think that Module:String would benefit from this function, with its name changed from abecedaria to translit.

Translated into English, the code to add to this module would be:

str.translit = function( frame )

	local args = frame.args

	if args[1] == nil or args[1] == '' or args[3] == nil or args[3] == '' then
		return ''
	end

	local npairs
	local text = mw.text.split(args[3], '', true)
	local removenda = mw.text.split(args[1], '', true)
	local substituenda

	if args[2] ~= nil then
		substituenda = mw.text.split(args[2], '', true)
	else
		substituenda = {}
	end

	if #removenda > #substituenda then
		npairs = #substituenda
	else
		npairs = #removenda
	end

	for idx1 = 1, npairs do
		for idx2 = 1, #text do
			if text[idx2] == removenda[idx1] then
				text[idx2] = substituenda[idx1]
			end
		end
	end

	for idx1 = npairs + 1, #removenda do
		for idx2 = 1, #text do
			if text[idx2] == removenda[idx1] then
				table.remove(text, idx2)
			end
		end
	end

	return table.concat(text)

end

return str

Grufo (talk) 17:40, 21 September 2023 (UTC)

This feels sufficiently obscure that it doesn't belong in this module, unless some actual use case can be presented here unrelated to what other wikis do. * Pppery * it has begun... 22:02, 21 September 2023 (UTC)
What is obscure, what it does or its code? What it does is well explained by the documentation of M4's translit (this is just a clone). As for what can be done with it, I believe template {{la:Ufrac}} has no languages. --Grufo (talk) 01:28, 22 September 2023 (UTC)
Yes, and why should we care? Why is the Unicode system for fractions superior to the one currently in use? Why should we invent more ways to do the same thing? * Pppery * it has begun... 01:33, 22 September 2023 (UTC)
I believe this discussion started with the wrong foot. This is a generic function proposal, it is not a proposal about the {{la:Ufrac}} template. In fact, the other template that uses this proposal ({{la:Sine notis diacriticis}}) does something completely different (i.e. removing accents from vowels). I have no problem answering questions about {{la:Ufrac}}, but I would kindly ask you to stay on topic on this function proposal. Re: Why should we invent more ways to do the same thing? Because there are many cases where you have no alternatives. For instance, you can write,
  • 100 {{Abbr|carats|A carat is Âč⁄₁₇₂₈ of a pound.}}
    ↳ 100 carats
but you cannot use the CSS/HTML solution used by {{Fraction}} inside {{Abbr}}. But again, since it is a generic function proposal, frankly I think it will find most of its applications in the transliteration of alphabets rather than in fractions (that was indeed only one example). It is such a basic functionality that it has been part of Unix since the old days. For instance, if you look at the code of {{la:Ufrac/par}} you will find
{{#invoke:translitteratio|abecedaria|0123456789|⁰ÂčÂȳ⁎⁔⁶⁷⁞âč|{{{1}}}}}
All that does is mapping each digit to its superscript unicode character. If we wanted to do the same using {{#invoke:string|replace}} we would need ten module invocations. --Grufo (talk) 01:55, 22 September 2023 (UTC)
We already have Module:MultiReplace for that. Yes, the syntax you used is slightly terser than that module's syntax, but there's no need to shake up the world. * Pppery * it has begun... 02:09, 22 September 2023 (UTC)
I have not done a speed test, but I suspect that syntax will not be the only thing where this function will greatly beat Module:MultiReplace. In fact, I suspect that performance will be tremendously less expensive here. This function is less powerful (the mapping happens verbatim character by character), hence, exactly for this reason, it is possible to map without problems strings that are page-long – while I suspect that Module:MultiReplace will break the servers in that case. If all this seems unrealistic, think about the amount of Unicode characters: just to map four types of accents in {{la:Sine notis diacriticis}} I had to write the following string:
ĀĒÄȘÌĆȘÈČĂĔĬƎƬÀÈÌÒÙá»ČĂĂ‰ĂĂ“ĂšĂĂ‚ĂŠĂŽĂ”Ă›Ć¶ÄÄ“Ä«ĆĆ«ÈłÄƒÄ•Ä­ĆĆ­Ă ĂšĂŹĂČĂčỳåéíóĂșĂœĂąĂȘĂźĂŽĂ»Ć·Ì„Ì†
I assure you, there can be way more complex transliterations than this. And last but not least: in terms of both computational complexity and ease of use, what you call “shaking up the world” is rather a going back to the old days. --Grufo (talk) 02:26, 22 September 2023 (UTC)
Yes, and do we really care? Don't make speculative claims about breaking the servers - see WP:PERF. I'm still not convinced that we need any of this level of complexity instead of just letting people type what they want to type rather than relying on templates to fix it for them and it's clear we won't convince each other at this point. * Pppery * it has begun... 02:33, 22 September 2023 (UTC)
Fine. Continuing with this spirit interface-wise Latin Wikipedia will soon beat English Wikipedia. --Grufo (talk) 02:41, 22 September 2023 (UTC)