Difference between revisions of "Module:Language/name/data"

From annadreambrush.com/wiki
Jump to navigation Jump to search
imported>Lfdder
m (Lfdder moved page Module:ISO 639 name/data to Module:Language/name/data without leaving a redirect)
imported>Verdy p
(documenting)
Line 2: Line 2:
 
local function __coalesce(...)
 
local function __coalesce(...)
 
     local coalesced = {}
 
     local coalesced = {}
     for r, t in ipairs(arg) do
+
     for _, langslist in ipairs(arg) do
         for k, v in pairs(t) do
+
         for langcode, langnames in pairs(langslist) do
             for x, y in pairs(v) do
+
             for _, langname in pairs(langnames) do
                 if not coalesced[k] then
+
                 if not coalesced[langcode] then
                     coalesced[k] = {}
+
                     coalesced[langcode] = {}
 
                 end
 
                 end
                 table.insert(coalesced[k], y)
+
                 table.insert(coalesced[langcode], langname)
 
             end
 
             end
 
         end
 
         end
Line 20: Line 20:
 
     local preprocessed = {}
 
     local preprocessed = {}
 
     if first_of_array_in_array then
 
     if first_of_array_in_array then
 +
    -- keep only the 1st language name for each code, excluding synonyms
 
         for k, v in pairs(t) do
 
         for k, v in pairs(t) do
 
             preprocessed[k:lower()] = {v[1]}
 
             preprocessed[k:lower()] = {v[1]}
Line 32: Line 33:
 
end
 
end
  
 +
-- all valid primary language subtags for BCP47 from IANA (most of them from ISO 639-1, -2 and -3 with some exclusions)
 +
local __iana_languages = __preprocess(require("Module:Language/data/iana languages"))
 +
-- ISO 639-3 contains additional 3-letter codes not inserted in the IANA database as they are aliased to 2-letter codes,
 +
-- but excludes some deleted codes still valid in BCP47 (some of them are aliased)
 
local __iso_639_3      = __preprocess(require("Module:Language/data/iso 639-3"))
 
local __iso_639_3      = __preprocess(require("Module:Language/data/iso 639-3"))
local __iana_languages = __preprocess(require("Module:Language/data/iana languages"))
+
-- Wikimedia wikis uses some non-standard codes and a subset of IANA codes, plus composite codes
 
local __wp_languages  = __preprocess(require("Module:Language/data/wp languages"), true)
 
local __wp_languages  = __preprocess(require("Module:Language/data/wp languages"), true)
 +
-- all valid script subtags for BCP47 from IANA (excluding special ISO 15924 codes)
 
local iana_scripts    = __preprocess(require("Module:Language/data/iana scripts"))
 
local iana_scripts    = __preprocess(require("Module:Language/data/iana scripts"))
 +
-- all valid region subtags for BCP47 from IANA (derived from ISO 3166-1 excluding special codes, and from 3-digit UN M.49 codes for groups of countries)
 
local iana_regions    = __preprocess(require("Module:Language/data/iana regions"))
 
local iana_regions    = __preprocess(require("Module:Language/data/iana regions"))
 
   
 
   

Revision as of 06:43, 6 May 2014

Documentation for this module may be created at Module:Language/name/data/doc

-- put tables and their tables together
local function __coalesce(...)
    local coalesced = {}
    for _, langslist in ipairs(arg) do
        for langcode, langnames in pairs(langslist) do
            for _, langname in pairs(langnames) do
                if not coalesced[langcode] then
                    coalesced[langcode] = {}
                end
                table.insert(coalesced[langcode], langname)
            end
        end
    end
 
    return coalesced
end

-- make the keys lowercase
local function __preprocess(t, first_of_array_in_array)
    local preprocessed = {}
    if first_of_array_in_array then
    	-- keep only the 1st language name for each code, excluding synonyms
        for k, v in pairs(t) do
            preprocessed[k:lower()] = {v[1]}
        end
    else
        for k, v in pairs(t) do
            preprocessed[k:lower()] = v
        end
    end

    return preprocessed
end

-- all valid primary language subtags for BCP47 from IANA (most of them from ISO 639-1, -2 and -3 with some exclusions)
local __iana_languages = __preprocess(require("Module:Language/data/iana languages"))
-- ISO 639-3 contains additional 3-letter codes not inserted in the IANA database as they are aliased to 2-letter codes,
-- but excludes some deleted codes still valid in BCP47 (some of them are aliased)
local __iso_639_3      = __preprocess(require("Module:Language/data/iso 639-3"))
-- Wikimedia wikis uses some non-standard codes and a subset of IANA codes, plus composite codes
local __wp_languages   = __preprocess(require("Module:Language/data/wp languages"), true)
-- all valid script subtags for BCP47 from IANA (excluding special ISO 15924 codes)
local iana_scripts     = __preprocess(require("Module:Language/data/iana scripts"))
-- all valid region subtags for BCP47 from IANA (derived from ISO 3166-1 excluding special codes, and from 3-digit UN M.49 codes for groups of countries)
local iana_regions     = __preprocess(require("Module:Language/data/iana regions"))
 
return {
    lang   = __coalesce(__wp_languages, __iana_languages, __iso_639_3),
    lang_iana = __iana_languages,
    script = iana_scripts,
    region = iana_regions
}