Module:String2: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
Content added Content deleted
(update from sandbox) |
(added function "label" which capitalize only first letter for fetched wikidata labels d:Help:Label#Capitalization. Almost same as "sentence" function except that "label" doesn't lowering the rest of text.) |
||
Line 53: | Line 53: | ||
end |
end |
||
return table.concat(words, " ") |
return table.concat(words, " ") |
||
end |
|||
p.label = function (frame ) |
|||
-- Capitalizing only first letter for fetched Wikidata labels. |
|||
-- Wikidata English labels generally begin with a lowercase letter. [[:d:Help:Label#Capitalization]] |
|||
local s = mw.text.trim( frame.args[1] or "" ) |
|||
if string.find(s, "^%[%[[^|]+|[^%]]+%]%]") then |
|||
-- this is a piped wikilink, so we capitalise the text, not the pipe |
|||
local b, c = string.find(s, "|%A*%a") -- find the first letter after the pipe |
|||
return string.sub(s, 1, c-1) .. string.upper(string.sub(s, c, c)) .. string.sub(s, c+1) |
|||
end |
|||
local letterpos = string.find(s, '%a') |
|||
if letterpos then |
|||
local first = string.sub(s, 1, letterpos - 1) |
|||
local letter = string.sub(s, letterpos, letterpos) |
|||
local rest = string.sub(s, letterpos + 1) |
|||
return first .. string.upper(letter) .. rest |
|||
else |
|||
return s |
|||
end |
|||
end |
end |
||