Translations keyed by labels instead of English text
tr('pnis.delivery_2_to_6_weeks') instead of tr('Delivery: 2 to 6 weeks'): the
English lives once, in src/i18n/en.js (inlined into the page at build, so no
extra request), and it/pt/fr map the same labels. Changing English wording no
longer renames a key in every dictionary.
- 2,899 labels, made from where each text is used and its first words; short
shared words are common.*
- plurals are one label with {one, other}: trn('label', n)
- static markup: data-i18n="label", data-i18n-aria-label, data-i18n-title
- saves from 1.33 and older stored English text in a few places; tr() still
resolves it
- i18n-check: undefined/unused labels, markup drift, plural shape; i18n-add.js
works on labels and --rename updates src/ too
- the old-branch port tool gives old English-keyed code and dictionaries the
same labels
This commit is contained in:
parent
d0ba85ef8f
commit
e817beed1a
94 changed files with 13681 additions and 10633 deletions
|
|
@ -1,6 +1,7 @@
|
|||
// Static markup: data-i18n text and every aria-label/title go through the dictionary once at boot.
|
||||
function i18nDom(){if(LANG==='en')return;for(const el of document.querySelectorAll('[data-i18n]'))el.textContent=tr(el.textContent);
|
||||
for(const a of ['aria-label','title'])for(const el of document.querySelectorAll('['+a+']'))el.setAttribute(a,tr(el.getAttribute(a)));}
|
||||
// Static markup: elements with data-i18n="label" get their text, and data-i18n-aria-label / data-i18n-title
|
||||
// their attribute, from the dictionary once at boot. The English stays in the markup for search engines.
|
||||
function i18nDom(){if(LANG==='en')return;for(const el of document.querySelectorAll('[data-i18n]'))el.textContent=tr(el.dataset.i18n);
|
||||
for(const a of ['aria-label','title'])for(const el of document.querySelectorAll(`[data-i18n-${a}]`))el.setAttribute(a,tr(el.getAttribute('data-i18n-'+a)));}
|
||||
// One button per [value,label] option; the current one is highlighted.
|
||||
function segBtns(act,cur,opts){return opts.map(([v,l])=>btn(l,act,{v},cur===v?'pink sm':'ghost sm')).join('');}
|
||||
/* Animation setting: auto follows the system's reduced-motion preference, or force it on or off. */
|
||||
|
|
@ -11,20 +12,20 @@ const pref=k=>typeof PREFS[k]==='boolean'?PREFS[k]:PREF_DEF[k];
|
|||
function setPref(k,v){if(!own(PREF_DEF,k))return;PREFS[k]=!!v;try{localStorage.setItem('sot-prefs',JSON.stringify(PREFS));}catch(e){}}
|
||||
// Stop the clock for something the player must see. Nothing happens if the game is already paused.
|
||||
function autoPause(){if(!S||!UI.speed)return false;UI.resumeSpeed=UI.speed;UI.speed=0;renderHUD();return true;}
|
||||
const resumeAct=()=>({l:tr('Resume'),act:'speed',args:{v:UI.resumeSpeed||1}});
|
||||
const resumeAct=()=>({l:tr('common.resume'),act:'speed',args:{v:UI.resumeSpeed||1}});
|
||||
function settingsHtml(){const seg=(lab,act,cur,opts,note)=>`<div class="setline"><span>${lab}</span><div class="seg">${segBtns(act,cur,opts)}</div></div>${note?`<p class="meta" style="margin:0 0 6px">${note}</p>`:''}`;
|
||||
const onoff=k=>[[k+':1',tr('On')],[k+':0',tr('Off')]],cur=k=>k+':'+(pref(k)?1:0);
|
||||
return `<div style="display:flex;align-items:center"><h2 style="font-size:26px">⚙️ ${tr('Settings')}</h2><button class="x" data-act="settingsClose" aria-label="${tr('Close')}">×</button></div><p class="tagline">${tr('Saved on this device.')}</p>
|
||||
<h3 class="sub4">${tr('Customers and alerts')}</h3>
|
||||
${seg(tr('Pause when a customer is furious'),'prefSet',cur('pauseFurious'),onoff('pauseFurious'),tr('The game stops so you can fix their service before they cancel. Most useful at high speed.'))}
|
||||
${seg(tr('Warn when a customer gets unhappy'),'prefSet',cur('warnUnhappy'),onoff('warnUnhappy'),tr('An early heads-up below 60% happiness, long before they are furious.'))}
|
||||
${seg(tr('Pause on outages that hurt'),'prefSet',cur('pauseIncident'),onoff('pauseIncident'),tr('Stops the game when a failure costs you real traffic, not when it reroutes by itself.'))}
|
||||
<h3 class="sub4">${tr('Display and sound')}</h3>
|
||||
${seg(tr('Animations'),'animSet',UI.anim||'auto',[['auto',tr('Auto')],['on',tr('On')],['off',tr('Off')]],tr('Auto follows your device’s reduce-motion setting. Off freezes the map: no moving packets, pulses or floating text.'))}
|
||||
${seg(tr('Sound'),'soundSet',UI.muted?'off':'on',[['on',tr('On')],['off',tr('Off')]])}
|
||||
${seg(tr('Language'),'langSet',LANG,Object.entries(LANGS))}
|
||||
${seg(tr('Viewport info'),'vpSet',VP_T?'on':'off',[['on',tr('On')],['off',tr('Off')]],tr('For reporting layout bugs: shows what your screen tells the game.'))}
|
||||
${installRow()}<div class="btns" style="margin-top:12px">${btn(tr('Done'),'settingsClose',{},'pink')}</div>`;}
|
||||
const onoff=k=>[[k+':1',tr('common.on')],[k+':0',tr('common.off')]],cur=k=>k+':'+(pref(k)?1:0);
|
||||
return `<div style="display:flex;align-items:center"><h2 style="font-size:26px">⚙️ ${tr('common.settings')}</h2><button class="x" data-act="settingsClose" aria-label="${tr('common.close')}">×</button></div><p class="tagline">${tr('settings.saved_on_this_device')}</p>
|
||||
<h3 class="sub4">${tr('settings.customers_and_alerts')}</h3>
|
||||
${seg(tr('settings.pause_when_a_customer_is_furious'),'prefSet',cur('pauseFurious'),onoff('pauseFurious'),tr('settings.the_game_stops_so_you_can'))}
|
||||
${seg(tr('settings.warn_when_a_customer_gets_unhappy'),'prefSet',cur('warnUnhappy'),onoff('warnUnhappy'),tr('settings.an_early_heads_up_below_60'))}
|
||||
${seg(tr('settings.pause_on_outages_that_hurt'),'prefSet',cur('pauseIncident'),onoff('pauseIncident'),tr('settings.stops_the_game_when_a_failure'))}
|
||||
<h3 class="sub4">${tr('settings.display_and_sound')}</h3>
|
||||
${seg(tr('common.animations'),'animSet',UI.anim||'auto',[['auto',tr('common.auto')],['on',tr('common.on')],['off',tr('common.off')]],tr('settings.auto_follows_your_device_s_reduce'))}
|
||||
${seg(tr('common.sound'),'soundSet',UI.muted?'off':'on',[['on',tr('common.on')],['off',tr('common.off')]])}
|
||||
${seg(tr('common.language'),'langSet',LANG,Object.entries(LANGS))}
|
||||
${seg(tr('common.viewport_info'),'vpSet',VP_T?'on':'off',[['on',tr('common.on')],['off',tr('common.off')]],tr('settings.for_reporting_layout_bugs_shows_what'))}
|
||||
${installRow()}<div class="btns" style="margin-top:12px">${btn(tr('common.done_8dd3'),'settingsClose',{},'pink')}</div>`;}
|
||||
const refreshSettings=()=>{if(UI.setOpen)openModal(settingsHtml());};
|
||||
function animOn(){const m=UI.anim||'auto';if(m==='on')return true;if(m==='off')return false;try{return !matchMedia('(prefers-reduced-motion: reduce)').matches;}catch(e){return true;}}
|
||||
function applyAnim(){const r=document.documentElement;r.classList.toggle('no-anim',UI.anim==='off');r.classList.toggle('anim-force',UI.anim==='on');if(!animOn())FLOATS.length=0;}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue