infobox/Utilities

infobox/Utilities Tài liệu mô đun
require('strict'); local getArgs = require ('Module:Arguments').getArgs;   --[[--------------------------< I S _ C J K _ C O D E >--------------------------------------------------------  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.  |italics={{#invoke:Infobox/utilities|set_italics|{{{orig_lang_code|}}}|{{{title_orig}}}}}}}  ]]  local function set_italics (frame) local args=getArgs(frame);  local code = args[1] or args['code'] or '';-- empty string causes 'yes' return; {{lang}} will handle the missing code error local text = args[2] or 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:Unicode data return  'no';-- only case for 'no'  end return 'yes';-- everything else is yes end   --[[--------------------------< C O M P >----------------------------------------------------------------------  compare function for result{} table descending sort  ]]  local function comp (a, b) return tonumber (a[1]) > tonumber (b[1]); end   --[[--------------------------< S O R T _ C O M M O N >--------------------------------------------------------  common function to render sorted distribution, ethnicity, and occupation lists.  inputs: result - table of percentages and labels ref - value from |distribution ref=, |ethnicity ref=, or |occupation ref= as appropriate frame - calling frame required for expandTemplate()  returns sorted list on success; empty string else  ]]  local function sort_common (result, ref, frame) for i=#result, 1, -1 do if not tonumber (result[i][1]) then-- if cannot be converted to a number table.remove (result, i);-- delete end end  if 0 == #result then-- if we get here and the result table is empty return '';-- abandon returning empty string end  table.sort (result, comp);-- sort what remains  for i, v in ipairs (result) do result[i] = table.concat (result[i]);-- make each table in result{} a string end  result[1] = table.concat ({result[1], ref and ref or ''});-- add reference(s) from | ref= to first item in the list  return frame:expandTemplate { title = 'Unbulleted list', args = result};-- render the unbulleted list end   --[[--------------------------< D I S R I B U T I O N _ S O R T >----------------------------------------------  {{#invoke:Infobox/utilities|distribution_sort|{{{percent urban|}}}|{{{percent rural|}}}|{{{distribution ref|}}} }}  ]]  local function distribution_sort (frame) local args=getArgs(frame);  local result = {-- initialize; table will be sorted according to values in result[n][1] {args[1], '% đô thị'}, {args[2], '% nông thôn'}, };  return sort_common (result, args[#result+1], frame); end   --[[--------------------------< E T H N I C I T Y _ S O R T >--------------------------------------------------  {{#invoke:Infobox/utilities|ethnicity_sort|{{{percent white|}}}|{{{percent black|}}}|{{{percent asian|}}}|{{{percent hispanic|}}}|{{{percent native american|}}}|{{{percent native hawaiian|}}}|{{{percent more than one race|}}}|{{{percent other race|}}}|{{{ethnicity ref|}}} }}  ]]  local function ethnicity_sort (frame) local args=getArgs(frame);  local result = {-- initialize; table will be sorted according to values in result[n][1] {args[1], '% [[Người Mỹ da trắng|Da trắng]]'}, {args[2], '% [[Người Mỹ gốc Phi|Da đen]]'}, {args[3], '% [[Người Mỹ gốc Á|Gốc Á]]'}, {args[4], '% [[Người Mỹ gốc Latinh và Tây Ban Nha|Tây Ban Nha hoặc Latinh]]'}, {args[5], '% [[Người Mỹ bản địa tại Hoa Kỳ|Bản địa]]'}, {args[6], '% [[Pacific Islander Americans]]'}, {args[7], '% [[Multiracial Americans|Two or more races]]'}, {args[8], '% other'},-- TODO: make other always last? };  return sort_common (result, args[#result+1], frame); end   --[[--------------------------< O C C U P A T I O N _ S O R T >------------------------------------------------  {{#invoke:Infobox/utilities|distribution_sort|{{{percent blue collar|}}}|{{{percent white collar|}}}|{{{percent grey collar|}}}|{{{occupation ref|}}} }}  ]]  local function occupation_sort (frame) local args=getArgs(frame);  local result = {-- initialize; table will be sorted according to values in result[n][1] {args[1], '% [[Blue-collar worker|Blue-collar]]'}, {args[2], '% [[White-collar worker|White-collar]]'}, {args[3], '% [[Gray-collar]]'}, };  return sort_common (result, args[#result+1], frame) end   --[[--------------------------< E X P O R T E D   F U N C T I O N S >------------------------------------------  ]]  return { distribution_sort = distribution_sort,-- {{Infobox U.S. congressional district}} ethnicity_sort = ethnicity_sort, occupation_sort = occupation_sort,  set_italics = set_italics,-- {{Infobox book}} } 

🔥 Trending searches on Wiki Tiếng Việt:

BruneiNha TrangThủy triềuDanh sách tỷ phú thế giớiChiến tranh Cách mạng MỹVăn hóa Việt NamQuang TrungTrần Đức LươngHồi giáoTrần Bình TrọngĐắk LắkLịch sử Việt NamĐảng Cộng sản Việt NamLa bànNhà ĐườngSúng trường tự động KalashnikovCác ngày lễ ở Việt NamViênTổng Bí thư Ban Chấp hành Trung ương Đảng Cộng sản Việt NamChristopher NolanBộ đội Biên phòng Việt NamMười hai vị thần trên đỉnh OlympusTwitterThích Nhất HạnhKung Fu Panda 4Hoa KỳNhật thựcCúc Tịnh YChùa Bái ĐínhĐồng ThápVụ án Hồ Duy HảiChiến tranh biên giới Việt Nam – CampuchiaQuân khu 1, Quân đội nhân dân Việt NamNapoléon BonaparteNguyễn Văn NênQuân khu 7, Quân đội nhân dân Việt NamĐài Truyền hình Kỹ thuật số VTCNgô Đình DiệmLãnh thổ Việt Nam qua từng thời kỳNelson MandelaVụ án Lê Văn LuyệnNguyễn Xuân PhúcAlexandros Đại đếPhan Văn Mãi2023Can ChiVõ Nguyên GiápBrasilChợ Bến ThànhTình yêuLiverpool F.C. mùa bóng 2018–19Manchester United F.C.Quốc gia Việt NamVõ Trần ChíBangladeshVụ sập cầu Francis Scott KeyBình ThuậnDoraemonĐiện BiênGia KhánhRoman CatholicNguyễn Hồng NhungHai nguyên lý của phép biện chứng duy vậtỦy ban Kiểm tra Trung ương Đảng Cộng sản Việt NamVirgil van DijkNhà Lê trung hưngFIFAYên NhậtMalaysiaAngkor WatĐội tuyển bóng đá quốc gia GruziaLâm ĐồngNgười ViệtHiệp định Genève 1954Vương quốc Liên hiệp Anh và Bắc IrelandĐài Á Châu Tự Do🡆 More