Module:Language/name/data: Difference between revisions

From Zoophilia Wiki
Jump to navigationJump to search
meta>Lfdder
No edit summary
meta>Lfdder
No edit summary
Line 4: Line 4:
         for k, v in pairs(t) do
         for k, v in pairs(t) do
             for x, y in pairs(v) do
             for x, y in pairs(v) do
                if not coalesced[k] then
                    coalesced[k] = {}
                end
                 table.insert(coalesced[k], y)
                 table.insert(coalesced[k], y)
             end
             end

Revision as of 14:35, 15 April 2014

This pulls data from data modules and bunches them together. Language names are gathered in this order:

  1. Module:Language/data/ISO 639-3 – as defined in ISO 639-3
  2. Module:Language/data/iana languages – as defined by the IETF-sanctioned IANA registry; names almost always the same as ISO, but does not include 3-letter codes for languages with 2-letter codes, hence the fallback
  3. Module:Language/data/wp languages – specific to Wikipedia; languages for which we've decided another name is better

In other words, a name set in wp languages will take precedence over one set in iana languages and that too would take precedence over one from iso 639-3. wp languages can be discarded by passing dataset="iana" to the parent module.

See also


local function __coalesce(...)
    local coalesced = {}
    for r, t in ipairs(arg) do
        for k, v in pairs(t) do
            for x, y in pairs(v) do
                if not coalesced[k] then
                    coalesced[k] = {}
                end
                table.insert(coalesced[k], y)
            end
        end
    end
 
    return coalesced
end

local function __preprocess(t, first_of_array_in_array)
    local preprocessed = {}
    if first_of_array_in_array then
        for k, v in pairs(t) do
            preprocessed[k:lower()] = {v[0]}
        end
    else
        for k, v in pairs(t) do
            preprocessed[k:lower()] = v
        end
    end

    return preprocessed
end

local __iso_639_3      = __preprocess(require("Module:Language/data/iso 639-3"))
local __iana_languages = __preprocess(require("Module:Language/data/iana languages"))
local __wp_languages   = __preprocess(require("Module:Language/data/wp languages"), true)
local iana_scripts     = __preprocess(require("Module:Language/data/iana scripts"))
local iana_regions     = __preprocess(require("Module:Language/data/iana regions"))
 
return {
    iana = {
        lang   = __coalesce(__iana_languages, __iso_639_3),
        script = iana_scripts,
        region = iana_regions
    },
    wikipedia = {
        lang   = __coalesce(__wp_languages, __iana_languages, __iso_639_3),
        script = iana_scripts,
        region = iana_regions
    }
}