Module:Lang: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
No edit summary |
No edit summary |
||
Line 31: | Line 31: | ||
require('Module:No globals'); |
require('Module:No globals'); |
||
local getArgs = require('Module:Arguments').getArgs; |
local getArgs = require('Module:Arguments').getArgs; |
||
local lang_name_table = mw.loadData ('Module:Language/data/iana languages'); |
|||
local p = {}; |
local p = {}; |
||
--[[--------------------------< C O D E _ F A L L B A C K >---------------------------------------------------- |
|||
List of ISO 639-2 and -3 codes that fall back to ISO 639-1 codes supported by MediaWiki |
|||
]] |
|||
local code_fallback = { |
|||
['aar'] = 'aa', -- Afar |
|||
['ara'] = 'ar', -- Arabic |
|||
['asm'] = 'as', -- Assamese |
|||
['fry'] = 'fy', -- Western Frisian |
|||
} |
|||
--[[--------------------------< C O D E _ 2 _ N A M E >-------------------------------------------------------- |
|||
list of ISO 639-2 and -3 codes that DO NOT fall back to ISO 639-1 codes |
|||
]] |
|||
local code_2_name = { |
|||
['aae'] = 'Arbëresh', |
|||
['abq'] = 'Abaza', |
|||
['aec'] = 'Sa\'idi Arabic', |
|||
['aii'] = 'Assyrian Neo-Aramaic', |
|||
['amh'] = 'Amharic', |
|||
['anm'] = 'Anal', |
|||
['apm'] = 'Mescalero-Chiricahua', |
|||
['apw'] = 'Western Apache', |
|||
['arm'] = 'Armenian', |
|||
['ave'] = 'Avestan', |
|||
['bal'] = 'Balochi', |
|||
['bam'] = 'Bambara', |
|||
['bar'] = 'Bavarian', |
|||
['bft'] = 'Balti', |
|||
['bho'] = 'Bhojpuri', |
|||
['bla'] = 'Siksika', |
|||
['brx'] = 'Bodo', |
|||
['bxr'] = 'Buryat', |
|||
['ca-valencia'] = 'Valencian', |
|||
['cdo'] = 'Eastern Min', |
|||
['ceb'] = 'Cebuano', |
|||
['hop'] = 'Hopi', |
|||
} |
|||
Line 160: | Line 114: | ||
local out = {}; |
local out = {}; |
||
local language_name = |
local language_name = lang_name_table[args.code][1]; -- table entries someites have multiple names, always take the first one |
||
if not is_set (language_name) then |
if not is_set (language_name) then |
||
⚫ | |||
if code_fallback [args.code] then |
|||
language_name = mw.language.fetchLanguageName(code_fallback [args.code], mw.getContentLanguage():getCode()); -- try again with fallback code or 639-2 or -3 code |
|||
if not is_set (language_name) then |
|||
return 'error: unknown language code: ' .. args.code; -- if here then there is an error in the fall back table |
|||
end |
|||
elseif code_2_name [args.code] then -- try to get name from table of 639-2, -3 names |
|||
language_name = code_2_name [args.code]; |
|||
else |
|||
⚫ | |||
end |
|||
end |
end |
||