diff --git a/README.md b/README.md index dcf811a..c668969 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A local web dashboard for BPQ32: node status, BBS, Winlink, forwarding, chat, tr ## Interface language -Choose **Auto · System**, **Italiano** or **English** in the login screen or dashboard header. Auto follows the first preferred browser language (normally inherited from the PC): Italian for `it` / `it-*`, English otherwise. The choice is saved in that browser and applies immediately, without signing out or interrupting a radio session. Dates and numbers follow the selected language; the local timezone is unchanged. Mail, bulletin subjects and bodies, chat messages, attachment contents, terminal output and radio traffic remain original. No online translation service is used. +Use the Italian / UK flag switch in the login screen or dashboard header to select **Italiano** or **English**. On the first visit, the initial language is chosen from the first preferred browser language: Italian for `it` / `it-*`, English otherwise. After that the saved choice is used; there is no Auto mode. Switching language applies immediately, without signing out or interrupting a radio session. Dates and numbers follow the selected language; the local timezone is unchanged. Mail, bulletin subjects and bodies, chat messages, attachment contents, terminal output and radio traffic remain original. No online translation service is used. Interface copy is maintained in `public/i18n.js`; add new UI phrases and parameterised status patterns there. Mark custom data widgets with `data-no-i18n` so their content is preserved. diff --git a/i18n.test.mjs b/i18n.test.mjs index 7d42b79..df6f88b 100644 --- a/i18n.test.mjs +++ b/i18n.test.mjs @@ -8,17 +8,17 @@ function client(languages=['it-IT'],saved=null){ const context=vm.createContext({navigator:{languages},localStorage:{getItem:k=>storage.get(k),setItem:(k,v)=>storage.set(k,v)},document:{documentElement:{lang:''},readyState:'loading',body:null,addEventListener(){},querySelectorAll:()=>[],dispatchEvent:e=>events.push(e)},addEventListener(){},CustomEvent:class{constructor(type,options){Object.assign(this,{type,...options});}}}); vm.runInContext(source,context);return {api:context.BPQI18n,document:context.document,storage,events}; } -test('automatic UI language follows the first browser language, with English fallback',()=>{ +test('first visit chooses a concrete saved language from the browser, with English fallback',()=>{ for(const [languages,expected]of [[['it-IT','en-US'],'it'],[['en-US','it'],'en'],[['de-DE'],'en'],[[],'en']]){ - const {api,document}=client(languages);assert.equal(api.language,expected);assert.equal(document.documentElement.lang,expected); + const {api,document,storage}=client(languages);assert.equal(api.language,expected);assert.equal(document.documentElement.lang,expected);assert.equal(api.preference,expected);assert.equal(storage.get('bpq-language'),expected); } }); test('explicit language overrides automatic detection and is saved per browser',()=>{ const {api,storage,document}=client(['en-US'],'it');assert.equal(api.t('Connetti'),'Connetti'); api.setLanguage('en');assert.equal(api.t('Connetti'),'Connect');assert.equal(storage.get('bpq-language'),'en');assert.equal(document.documentElement.lang,'en');assert.equal(api.locale(),'en-GB'); api.setLanguage('it');assert.equal(api.t('Connetti'),'Connetti');assert.equal(api.locale(),'it-IT'); - api.setLanguage('auto');assert.equal(api.language,'en');assert.equal(api.preference,'auto'); - api.setLanguage('invalid');assert.equal(api.preference,'auto'); + api.setLanguage('auto');assert.equal(api.language,'it');assert.equal(api.preference,'it'); + api.setLanguage('invalid');assert.equal(api.preference,'it'); }); test('UI translations handle counters, statuses, decorative icons and dynamic values',()=>{ const {api}=client(['en']); @@ -32,3 +32,5 @@ test('UI translations handle counters, statuses, decorative icons and dynamic va assert.equal(api.t('HB9ON-2'),'HB9ON-2'); assert.equal(api.t('Custom unknown text'),'Custom unknown text'); }); + +test('legacy Auto preference migrates to a concrete language',()=>{const {api,storage}=client(['en-US'],'auto');assert.equal(api.preference,'en');assert.equal(storage.get('bpq-language'),'en');}); diff --git a/public/i18n.css b/public/i18n.css index 6fe0ab6..6825c32 100644 --- a/public/i18n.css +++ b/public/i18n.css @@ -1,6 +1,16 @@ -.language-picker{display:inline-flex;align-items:center;gap:7px;color:#a5b8ba;flex:none;font-size:13px} -.language-picker select{font:inherit;color:#dce8e5;background:#111c22;border:1px solid #34454c;border-radius:7px;padding:6px 25px 6px 9px;max-width:145px;cursor:pointer;min-height:32px} -.language-picker select:focus-visible{outline:2px solid #91c7b5;outline-offset:2px} -.language-login{justify-content:center;margin-top:16px;width:100%} -.language-toolbar{margin-right:8px} -@media(max-width:700px){.language-toolbar{margin-right:0;gap:3px}.language-toolbar>span{display:none}.language-toolbar select{max-width:113px;padding-left:6px;font-size:12px}.topbar>div{gap:6px}} +.language-switch{position:relative;display:inline-flex;align-items:center;isolation:isolate;flex:none;width:116px;height:36px;padding:3px;border:1px solid #34434e;border-radius:20px;background:#0c141c;color:#82939f;cursor:pointer;box-shadow:inset 0 1px 5px #0003;vertical-align:middle} +.language-switch .language-thumb{position:absolute;z-index:-1;left:3px;top:3px;bottom:3px;width:53px;border-radius:16px;background:linear-gradient(145deg,#334c60,#253d50);box-shadow:0 1px 4px #0005,inset 0 1px #ffffff12;transition:transform .2s ease} +.language-switch[aria-checked="true"] .language-thumb{transform:translateX(55px)} +.language-choice{width:50%;display:inline-flex;align-items:center;justify-content:center;gap:6px;font:600 10px/1 system-ui,sans-serif;letter-spacing:.04em;opacity:.55;transition:opacity .2s ease,color .2s ease} +.language-switch[aria-checked="false"] .language-choice:nth-child(2),.language-switch[aria-checked="true"] .language-choice:nth-child(3){opacity:1;color:#f0f6fc} +.language-flag{width:20px;height:14px;display:block;border-radius:2px;overflow:hidden;box-shadow:0 0 0 1px #ffffff20} +.language-switch:hover{border-color:#647e90} +.language-switch:focus-visible{outline:2px solid #9acac4;outline-offset:4px} +.language-login{display:flex;margin:24px auto 0} +.language-toolbar{margin-right:4px} +.login-byline{font:500 12px/1.5 system-ui,sans-serif;letter-spacing:.12em;color:#899eae} +.login-art .login-byline{margin-top:12px;font-size:14px;color:#a6b9c9} +.login-card .login-brand{margin-bottom:40px} +.login-card .login-brand .brand{margin-bottom:5px} +@media(prefers-reduced-motion:reduce){.language-switch .language-thumb,.language-choice{transition:none}} +@media(max-width:700px){.language-toolbar{width:100px;margin-right:0}.language-toolbar .language-thumb{width:45px}.language-toolbar[aria-checked="true"] .language-thumb{transform:translateX(47px)}.language-choice{gap:4px}.language-flag{width:18px;height:12px}.topbar>div{gap:6px}} diff --git a/public/i18n.js b/public/i18n.js index 8010ecc..52a33e5 100644 --- a/public/i18n.js +++ b/public/i18n.js @@ -8,7 +8,6 @@ Accedi con l’utente e la password Telnet del tuo BPQ.|Sign in with your BPQ Te Utente|Username Il tuo utente BPQ|Your BPQ username Entra nel pannello|Open dashboard -Created by IU2EUG · PC e rete locale|Created by IU2EUG · PC and local network LA TUA STAZIONE|YOUR STATION Panoramica|Overview Rete & nodi|Network & nodes @@ -545,7 +544,6 @@ CPU sistema|System CPU traffico BPQ TX RX|BPQ TX RX traffic cronologia|history Invio per inviare|Enter to send -Auto · Sistema|Auto · System Account sysop configurato non trovato|Configured sysop account not found Timeout BPQ|BPQ timeout WebMail BPQ non disponibile|BPQ WebMail unavailable @@ -612,12 +610,12 @@ Collega prima il terminale|Connect the terminal first Invia un solo comando, massimo 1000 caratteri|Send one command, up to 1000 characters `; const dictionary=new Map(entries.trim().split('\n').map(line=>line.split('|'))); - function resolveLanguage(preference='auto',languages=[]){ + function resolveLanguage(preference=null,languages=[]){ if(preference==='it'||preference==='en')return preference; // The first browser language is the user's preferred UI language; English is the fallback. return /^it(?:-|$)/i.test(languages[0]||'')?'it':'en'; } - let preference='auto',language='it'; + let preference=null,language='it'; const patterns=[ [/^Stazione \/ (.+)$/,m=>'Station / '+translate(m[1])], [/^(\d+) bollettini · (\d+) personali$/,m=>m[1]+' bulletins · '+m[2]+' personal'], @@ -662,9 +660,9 @@ Invia un solo comando, massimo 1000 caratteri|Send one command, up to 1000 chara const api={t,resolveLanguage,get language(){return language},get preference(){return preference},locale:()=>language==='it'?'it-IT':'en-GB'}; globalThis.BPQI18n=api; if(typeof document==='undefined')return; - try{const saved=localStorage.getItem('bpq-language');if(['it','en','auto'].includes(saved))preference=saved;}catch{} + try{const saved=localStorage.getItem('bpq-language');if(['it','en'].includes(saved))preference=saved;}catch{} const browserLanguages=()=>navigator.languages?.length?navigator.languages:[navigator.language]; - language=resolveLanguage(preference,browserLanguages());document.documentElement.lang=language; + language=resolveLanguage(preference,browserLanguages());preference=language;try{localStorage.setItem('bpq-language',language);}catch{}document.documentElement.lang=language; const originals=new WeakMap(),attributes=new WeakMap(); // These are user/protocol data, never interface copy. Do not translate their labels or contents. const protectedContent='script,style,textarea,pre,code,[contenteditable],[data-no-i18n],.reader-body,.mail-subject,.mail-from,.mail-category,.reader-header h2,.reader-meta b,.chat-message-content p,.chat-message-meta strong,.chat-user-name,.chat-user b,.chat-user small,.room-button,#chat-room-name,.attachment-row b,#attachment-title,#delete-subject,.arrival-toast small,.side-station,.profile>div,.mission-heading h1,.mission-location,.modem-brand,#caller-call,#called-call,.service-call,#nodes,.wl-account,#wl-gateway-rows td:nth-child(2),#category option:not([value]),#terminal-output,.monitor-frame'; @@ -696,9 +694,9 @@ Invia un solo comando, massimo 1000 caratteri|Send one command, up to 1000 chara } let observer; function observe(){observer.observe(document.body,{subtree:true,childList:true,characterData:true,attributes:true,attributeFilter:['title','placeholder','aria-label']});} - function syncControls(){document.querySelectorAll('[data-language-select]').forEach(select=>{select.value=preference;});} + function syncControls(){document.querySelectorAll('[data-language-switch]').forEach(control=>{control.setAttribute('aria-checked',String(language==='en'));control.setAttribute('title',language==='en'?'Switch to Italian':'Passa all’inglese');});} api.setLanguage=value=>{ - if(!['auto','it','en'].includes(value))return; + if(!['it','en'].includes(value))return; preference=value;try{localStorage.setItem('bpq-language',value);}catch{} language=resolveLanguage(value,browserLanguages());document.documentElement.lang=language; observer?.disconnect();apply();syncControls();if(observer)observe(); @@ -707,7 +705,11 @@ Invia un solo comando, massimo 1000 caratteri|Send one command, up to 1000 chara globalThis.bpqConfirm=message=>globalThis.confirm(t(message)); globalThis.bpqPrompt=(message,defaultValue='')=>globalThis.prompt(t(message),defaultValue); function mount(){ - const picker=place=>{const label=document.createElement('label');label.className='language-picker '+place;label.innerHTML='';label.querySelector('select').onchange=e=>api.setLanguage(e.target.value);return label;}; + const picker=place=>{ + const control=document.createElement('button');control.type='button';control.className='language-switch '+place;control.dataset.languageSwitch='';control.setAttribute('role','switch');control.setAttribute('aria-label','English / Italiano'); + control.innerHTML=''; + control.onclick=()=>api.setLanguage(language==='it'?'en':'it');control.onkeydown=e=>{if(e.key==='ArrowLeft'||e.key==='ArrowRight'){e.preventDefault();api.setLanguage(e.key==='ArrowRight'?'en':'it');}};return control; + }; document.querySelector('.login-card')?.append(picker('language-login')); document.querySelector('.topbar > div')?.prepend(picker('language-toolbar')); syncControls();apply();observer=new MutationObserver(records=>{ @@ -717,5 +719,4 @@ Invia un solo comando, massimo 1000 caratteri|Send one command, up to 1000 chara });observe(); } if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',mount,{once:true});else mount(); - globalThis.addEventListener('languagechange',()=>{if(preference==='auto')api.setLanguage('auto');}); })(); diff --git a/public/index.html b/public/index.html index 3b01178..6129f7f 100644 --- a/public/index.html +++ b/public/index.html @@ -1,7 +1,7 @@ BPQ Console -

BPQ Console

La tua stazione, in un unico pannello.

BPQ Console

Benvenuto in stazione.

Accedi con l’utente e la password Telnet del tuo BPQ.

Created by IU2EUG · PC e rete locale
+

BPQ Console

La tua stazione, in un unico pannello.

Benvenuto in stazione.

Accedi con l’utente e la password Telnet del tuo BPQ.