Module:In lang/sandbox: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 1:
require ('Module:No globals');
 
 
--[[--------------------------< I S _ C J K >------------------------------------------------------------------
 
return true if code is one of the listed Chinese, Japanese, Korean ISO 639 codes, false else.
 
]]
 
local function is_cjk_code (code)
local cjk =
{
['zh'] = true, ['cdo'] = true, ['cjy'] = true, ['cmn'] = true, -- Chinese language codes
['cpi'] = true, ['cpx'] = true, ['czh'] = true, ['czo'] = true,
['gan'] = true, ['hak'] = true, ['hsn'] = true, ['ltc'] = true,
['lzh'] = true, ['mnp'] = true, ['nan'] = true, ['och'] = true,
['wuu'] = true, ['yue'] = true, ['zhx'] = true,
['ja'] = true, ['jpx'] = true, ['ojp'] = true, -- Japanese language codes
['ko'] = true, ['okm'] = true, ['oko'] = true, -- Korean language codes
}
 
return cjk[code] or false;
end
 
 
--[[--------------------------< S E T _ I T A L I C S >--------------------------------------------------------
 
Created for use with Template:Infobox book and Template:Infobox document and perhaps others to replace hard-coded
italic markup in the call to {{lang}}. This module attempts to make sure that {{lang}} correctly applies italic
markup according to MOS:FOREIGNITALIC.
 
]]
 
local function set_italics (frame)
local code = frame.args[1] or frame.args['code'] or ''; -- empty string causes 'yes' return; {{lang}} will handle the missing code error
local text = frame.args[2] or frame.args['text'] or ''; -- empty string causes 'yes' return; {{lang}} will handle the missing text error
local is_latn = require ("Module:Unicode data").is_Latin;
if is_cjk_code (code) and not is_latn (text) then -- is_latn() is in Module:Lang
return 'no'; -- only case for 'no'
end
return 'yes'; -- everything else is yes
end
 
 
Line 371 ⟶ 328:
end
 
 
--[[--------------------------< IC SA T _ CT JE S KT >------------------------------------------------------------------
 
support for {{Category articles containing non-English-language text}} that tests the language parameters provided
to that template against the category name.
 
{{#invoke:Lang/utilities/sandbox|cat_test}}
 
]]
 
local function is_cjk_code cat_test(code)
local is_latnlang_module = require ("'Module:Unicode data"Lang').is_Latin;
local args = require ('Module:Arguments').getArgs (frame);
local err = false; -- boolean set true when an error is detected; one error message only
local cat_page_title = mw.title.getCurrentTitle(); -- get the category title
 
for i, v in ipairs (args) do
if lang_module._is_ietf_tag (v) then
lang_name = lang_module._name_from_tag (v); -- is a tag so get the language name
else
lang_name = v;
end
if not mw.ustring.find (cat_page_title, lang_name, 1, true) then
err = true;
end
end
return err and '<span style=\"font-size:100%; font-style:normal;\" class=\"error\">error: template / category title language mismatch</span>[[Category:Lang and lang-xx template errors]]' or nil;
end
 
--[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------
Line 381 ⟶ 367:
nihongo3 = nihongo3,
nihongo_foot = nihongo_foot,
 
set_italics = set_italics,
cat_test = cat_test,
}