Skip to content

Commit

Permalink
tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorin-Oakenpants authored Oct 23, 2024
1 parent 22d4e45 commit fa2a92a
Showing 1 changed file with 12 additions and 60 deletions.
72 changes: 12 additions & 60 deletions js/region.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,5 @@
'use strict';

// https://searchfox.org/mozilla-central/source/intl/icu/source/data/lang/en.txt#44
// ^ note underscores in codes, replace with hyphens
let aSystemBaseLang = [
'aa','ab','ace','ach','ada','ady','ae','aeb','af','afh','agq','ain','ak','akk','akz','ale','aln','alt','am',
'an','ang','ann','anp','ar','ar-001','arc','arn','aro','arp','arq','ars','arw','ary','arz','as','asa','ase',
'ast','atj','av','avk','awa','ay','az','ba','bal','ban','bar','bas','bax','bbc','bbj','be','bej','bem','bew',
'bez','bfd','bfq','bg','bgc','bgn','bho','bi','bik','bin','bjn','bkm','bla','blt','bm','bn','bo','bpy','bqi',
'br','bra','brh','brx','bs','bss','bua','bug','bum','byn','byv','ca','cad','car','cay','cch','ccp','ce','ceb',
'cgg','ch','chb','chg','chk','chm','chn','cho','chp','chr','chy','cic','ckb','clc','co','cop','cps','cr','crg',
'crh','crj','crk','crl','crm','crr','crs','cs','csb','csw','cu','cv','cwd','cy','da','dak','dar','dav','de',
'de-at','de-ch','del','den','dgr','din','dje','doi','dsb','dtp','dua','dum','dv','dyo','dyu','dz','dzg','ebu',
'ee','efi','egl','egy','eka','el','elx','en','en-au','en-ca','en-gb','en-us','enm','eo','es','es-419','es-es',
'es-mx','esu','et','eu','ewo','ext','fa','fa-af','fan','fat','ff','fi','fil','fit','fj','fo','fon','fr','fr-ca',
'fr-ch','frc','frm','fro','frp','frr','frs','fur','fy','ga','gaa','gag','gan','gay','gba','gbz','gd','gez','gil',
'gl','glk','gmh','gn','goh','gom','gon','gor','got','grb','grc','gsw','gu','guc','gur','guz','gv','gwi','ha',
'hai','hak','haw','hax','hdn','he','hi','hi-latn','hif','hil','hit','hmn','hnj','ho','hr','hsb','hsn','ht','hu',
'hup','hur','hy','hz','ia','iba','ibb','id','ie','ig','ii','ik','ike','ikt','ilo','inh','io','is','it','iu','izh',
'ja','jam','jbo','jgo','jmc','jpr','jrb','jut','jv','ka','kaa','kab','kac','kaj','kam','kaw','kbd','kbl','kcg',
'kde','kea','ken','kfo','kg','kgp','kha','kho','khq','khw','ki','kiu','kj','kk','kkj','kl','kln','km','kmb','kn',
'ko','koi','kok','kos','kpe','kr','krc','kri','krj','krl','kru','ks','ksb','ksf','ksh','ku','kum','kut','kv',
'kw','kwk','ky','la','lad','lag','lah','lam','lb','lez','lfn','lg','li','lij','lil','liv','lkt','lmo','ln','lo',
'lol','lou','loz','lrc','lsm','lt','ltg','lu','lua','lui','lun','luo','lus','luy','lv','lzh','lzz','mad','maf',
'mag','mai','mak','man','mas','mde','mdf','mdr','men','mer','mfe','mg','mga','mgh','mgo','mh','mi','mic','min',
'mk','ml','mn','mnc','mni','moe','moh','mos','mr','mrj','ms','mt','mua','mul','mus','mwl','mwr','mwv','my','mye',
'myv','mzn','na','nan','nap','naq','nb','nd','nds','nds-nl','ne','new','ng','nia','niu','njo','nl','nl-be','nmg',
'nn','nnh','no','nog','non','nov','nqo','nr','nso','nus','nv','nwc','ny','nym','nyn','nyo','nzi','oc','oj','ojb',
'ojc','ojg','ojs','ojw','oka','om','or','os','osa','ota','pa','pag','pal','pam','pap','pau','pcd','pcm','pdc',
'pdt','peo','pfl','phn','pi','pis','pl','pms','pnt','pon','pqm','prg','pro','ps','pt','pt-br','pt-pt','qu','quc',
'qug','raj','rap','rar','rgn','rhg','rif','rm','rn','ro','ro-md','rof','rom','rtm','ru','rue','rug','rup','rw',
'rwk','sa','sad','sah','sam','saq','sas','sat','saz','sba','sbp','sc','scn','sco','sd','sdc','sdh','se','see',
'seh','sei','sel','ses','sg','sga','sgs','sh','shi','shn','shu','si','sid','sk','sl','slh','sli','sly','sm',
'sma','smj','smn','sms','sn','snk','so','sog','sq','sr','sr-me','srn','srr','ss','ssy','st','stq','str','su',
'suk','sus','sux','sv','sw','sw-cd','swb','syc','syr','szl','ta','tce','tcy','te','tem','teo','ter','tet','tg',
'tgx','th','tht','ti','tig','tiv','tk','tkl','tkr','tl','tlh','tli','tly','tmh','tn','to','tog','tok','tpi','tr',
'tru','trv','trw','ts','tsd','tsi','tt','ttm','ttt','tum','tvl','tw','twq','ty','tyv','tzm','udm','ug','uga','uk',
'umb','und','ur','uz','vai','ve','vec','vep','vi','vls','vmf','vo','vot','vro','vun','wa','wae','wal','war','was',
'wbp','wo','wuu','xal','xh','xmf','xog','yao','yap','yav','ybb','yi','yo','yrl','yue','za','zap','zbl','zea','zen',
'zgh','zh','zh-hans','zh-hant','zu','zun','zxx','zza'
]

/* HEADERS */

function get_nav_connection(METRIC) {
Expand Down Expand Up @@ -540,30 +500,23 @@ function get_language_locale() {
return
}

function set_language_system() {
// populate once
function get_language_system(METRIC) {
/* systemLanguages: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/systemLanguage
populate svg with nav entries to detects if anything added. To detect removals would mean
populating with all supported BCPs (lots) = not worth it: perf and it is unlikely _only_ removal
happens, i.e we already detect added. Also prior to FF127 = false positives with prefixs e.g. if
you were "en-US, en", all en-* would be be true. Not worth the footgun or hasssle
*/
let t0 = nowFn()
let value, data = '', el = dom.svgswitch
try {
// populate
let el = dom.svgswitch
el.innerHTML = ''
let aText = ['<switch id="switch">']
aSystemBaseLang.forEach(function(l){aText.push('<text systemLanguage="'+ l +'">' + l +'</text>')})
isLanguagesNav.forEach(function(l){aText.push('<text systemLanguage="'+ l +'">' + l +'</text>')})
aText.push('<text>unknown</text></switch>')
el.innerHTML = aText.join('')
} catch(e) {}
}

function get_language_system(METRIC) {
// systemLanguages
let t0 = nowFn()
let value, data = '', el = dom.svgswitch
try {
// if there anything in isLanguagesNav not in aSystemBaseLang
// then add add it and re-populate, else do nothing
let aNotInBase = isLanguagesNav.filter(x => !aSystemBaseLang.includes(x))
if (aNotInBase.length) {
aSystemBaseLang = aSystemBaseLang.concat(aNotInBase)
set_language_system()
}
// walk nodes
let aDetected = [], range = new Range()
const walker = document.createTreeWalker(dom['switch'], NodeFilter.SHOW_TEXT, null);
Expand All @@ -576,7 +529,7 @@ function get_language_system(METRIC) {
throw zErrType + 'empty array'
} else if (aDetected.length > 1) {
aDetected = aDetected.filter(x => !['unknown'].includes(x))
aDetected.sort() // sort the small ist not the huge aList
aDetected.sort()
}
value = aDetected.join(', ')
} catch(e) {
Expand Down Expand Up @@ -1430,5 +1383,4 @@ const outputHeaders = () => new Promise(resolve => {
})

set_oIntlTests()
set_language_system()
countJS(4)

0 comments on commit fa2a92a

Please sign in to comment.