Creates a version of Module:etymology languages/data in which there is just one code per language. Codes that have the same language data are reduced to the most language-codiest one. For instance, Austrian German has three codes (Austrian German
, AG.
, de-AT
) by which it can be accessed in etymology templates like {{cog}}
. de-AT
is chosen as the only language code for Austrian German because it looks the most like a language code.
The following criteria are used successively to weed out candidates for language-codiest code:
This list shows those etymology languages that have multiple codes, together with the code chosen by this module and the other codes:
fr-aca
): Acadian French
, fra-aca
en-US
): AE.
, American English
atn
): xme-ast
de-AT
): AG.
, Austrian German
en-GB
): BE.
, British English
fr-CA
): CF.
, Canadian French
ckm
): sh-cha
sco-osc
): Early Scots
, O.Sc.
, Old Scots
bgp
): bal-eas
la-ecc
): EL.
, Ecclesiastical Latin
xme-gaz
): gzi
nrf-grn
): roa-grn
sco-ins
): Ins.Sc.
, Insular Scots
nrf-jer
): roa-jer
kjv
): sh-kaj
bsh-kam
): xvi
kfm
): xme-xun
ksh
): Kölsch
LL
): LL.
, Late Latin
, la-lat
lng
): Lombardic
, goh-lng
es-lun
): Lunfardo
la-med
): ML
, ML.
, Medieval Latin
ira-mid
): MIr.
sco-smi
): Mid.Sc.
, Middle Scots
ntz
): xme-nat
xme-nay
): nyq
la-new
): NL.
, New Latin
sco-nor
): Nor.Sc.
, Northern Scots
ira-old
): OIr.
it-oit
): roa-oit
fro-nor
): ONF.
, Old Northern French
qfa-sub-grc
): pregrc
oc-pro
): prv
la-ren
): RL.
, Renaissance Latin
soj
): xme-soi
bal-sou
): bcc
sco-sou
): Borders Scots
, Sou.Sc.
, Southern Scots
it-CH
): Swiss Italian
fr-CH
): Swiss French
, Switzerland French
sco-uls
): Uls.Sc.
, Ulster Scots
xme-vaf
): vaf
de-AT-vie
): VG.
, Viennese German
la-vul
): VL.
, Vulgar Latin
gbz
): xme-dar
qfa-pyg
): pygmy
gkm
): Medieval Greek
grc-koi
): Koine
mul-tax
): Tax.
local language_codes = require "Module:languages/code to canonical name"
local function determine_preferred_etymology_language_code(code1, code2)
if code2:find "^+$" then
if code1:find "^+$" then
if not code2:find "%u%l" then
if not code1:find "%u%l" then
if #code2 < #code1 then
return code2
else
-- Prefer nrf-grn and nrf-jer over roa-grn and roa-jer
-- (Guernsey and Jersey).
local first_word1, first_word2 =
code1:match "^+", code2:match "^+"
if first_word1 and first_word2
and language_codes then
return code1
else
return code2
end
end
else
return code2
end
else
return code1
end
else
return code2
end
else
return code1
end
end
local function fold(t, accum, func)
for k, v in pairs(t) do
accum = func(k, v, accum)
end
return accum
end
local function invert(t)
local inverted = {}
for k, v in pairs(t) do
inverted = k
end
return inverted
end
return invert(fold(
require "Module:etymology languages/data",
{},
function (code, data, data_to_code)
if data_to_code then
local preferred_code = determine_preferred_etymology_language_code(data_to_code, code)
data_to_code = preferred_code
table.insert(data.codes, code)
else
data_to_code = code
data.codes = { code }
end
return data_to_code
end))