On Latin Wikipedia I have created a tiny module named Module:Translitteratio, which contains a single function named abecedaria. The function accepts three para…
| This is an archive of past discussions about Module:String. Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page. |
| Archive 1 | Archive 2 |
This edit request to Module:String has been answered. Set the |answered= parameter to no to reactivate your request. |
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
(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)
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)
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.}}
{{#invoke:translitteratio|abecedaria|0123456789|⁰¹²³⁴⁵⁶⁷⁸⁹|{{{1}}}}}
ĀĒĪŌŪȲĂĔĬŎŬÀÈÌÒÙỲÁÉÍÓÚÝÂÊÎÔÛŶāēīōūȳăĕĭŏŭàèìòùỳáéíóúýâêîôûŷ̄̆
This edit request to Module:String has been answered. Set the |answered= parameter to no to reactivate your request. |
Please, add r to the word fist (resulting in first), line number 61. Nishimoto, Gilberto Kiyoshi (talk) 18:11, 25 October 2023 (UTC)
This edit request has been answered. Set the |answered= parameter to no to reactivate your request. |
All of the Lua pseudo-regex special characters are in the ASCII range. See en:UTF-8#Encoding. Therefore, we don't need at all to use the (costly) mw.ustring.* functions in some parts I have reviewed.
My request is to replace:
function str._escapePattern( pattern_str )
return mw.ustring.gsub( pattern_str, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" )
end
with:
function str._escapePattern( pattern_str )
return ( string.gsub( pattern_str, "[%(%)%.%%%+%-%*%?%[%^%$%]]", "%%%0" ) )
end
(I am also removing the capture group, which is unneeded as we can use the "%0" whole capture)
(edit: I am also taking the opportunity, for extra robustness, to add parentheses in order to discard the 2nd value (number of replacements) returned by these gsub() functions, then subsequently by _escapePattern(). The more I encounter this "multiple values returned" Lua feature, the more I think it was a terrible design idea)
Second change: line 409, we can similarly replace:
replace = mw.ustring.gsub( replace, "%%", "%%%%" ) --Only need to escape replacement sequences.
with:
replace = string.gsub( replace, "%%", "%%%%" ) --Only need to escape replacement sequences.
These changes would significantly decrease the overhead of having the "plain mode" enabled in this module's functions.
Od1n (talk) 03:26, 3 September 2024 (UTC)
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.