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
|
|
@ -8,16 +8,16 @@ document.addEventListener('visibilitychange',()=>{if(document.visibilityState===
|
|||
function saveFileName(){const d=new Date().toISOString().slice(0,10),n=(S&&S.name||'network').toLowerCase().replace(/[^a-z0-9]+/g,'-').replace(/^-|-$/g,'')||'network';return `series-of-tubes-${n}-${d}.json`;}
|
||||
function exportSave(){if(!S)return;save();const blob=new Blob([JSON.stringify({app:'series-of-tubes',version:APP_VERSION,exported:new Date().toISOString(),S},null,1)],{type:'application/json'});
|
||||
const a=document.createElement('a');a.href=URL.createObjectURL(blob);a.download=saveFileName();document.body.appendChild(a);a.click();setTimeout(()=>{URL.revokeObjectURL(a.href);a.remove();},1000);
|
||||
toast(tr('<b>Save exported.</b><br>{file} is in your downloads. Open it on another device with “Import a save”.',{file:esc(saveFileName())}),'good');}
|
||||
function parseSave(txt){if(typeof txt!=='string')return {err:tr('That file is not valid JSON.')};let j;try{j=JSON.parse(txt);}catch(e){return {err:tr('That file is not valid JSON.')};}
|
||||
toast(tr('save.save_exported_file_is_in_your',{file:esc(saveFileName())}),'good');}
|
||||
function parseSave(txt){if(typeof txt!=='string')return {err:tr('save.that_file_is_not_valid_json')};let j;try{j=JSON.parse(txt);}catch(e){return {err:tr('save.that_file_is_not_valid_json')};}
|
||||
const s=j&&j.app==='series-of-tubes'&&j.S?j.S:j;
|
||||
if(!s||typeof s!=='object'||s.v!==1||typeof s.day!=='number'||typeof s.cash!=='number'||!s.pops||typeof s.pops!=='object'||!Array.isArray(s.links))return {err:tr('That does not look like a Series of Tubes save.')};
|
||||
if(s.lost)return {err:tr('That network went bankrupt. It cannot be brought back, only mourned.')};
|
||||
for(const c of Object.keys(s.pops))if(!isCity(c))return {err:tr('That save has a POP in a city this version does not know ({city}).',{city:esc(String(c).slice(0,12))})};
|
||||
return {s,ver:j.version||'?',name:String(s.name||tr('Unnamed network'))};}
|
||||
function importFile(file){if(!file)return;if(file.size>8e6){toast(tr('<b>That file is too big to be a save.</b>'),'bad');return;}
|
||||
const rd=new FileReader();rd.onload=()=>{const r=parseSave(String(rd.result));if(r.err){toast(tr('<b>Import failed.</b><br>{err}',{err:esc(r.err)}),'bad');sfx('err');return;}
|
||||
UI.importing=r.s;openModal(`<div class="eyebrow">${tr('Import a save')}</div><h2 style="font-size:26px">${tr('Load {name}?',{name:esc(r.name)})}</h2><p class="tagline">${esc(dateStr(r.s.day))} · ${tr('{cash} in the bank',{cash:fmt$(r.s.cash)})} · ${trn('{n} POP','{n} POPs',Object.keys(r.s.pops).length)} · ${tr('saved by v{ver}',{ver:esc(r.ver)})}</p>${S&&UI.started&&!S.lost?`<p class="note" style="color:var(--bad)">${tr('This replaces {name}. Export it first if you want to keep it.',{name:esc(S.name)})}</p>`:''}<div class="btns">${btn(tr('Load this network'),'importGo',{},'pink big')}${btn(tr('Cancel'),UI.started?'closeModal':'helpClose',{},'ghost big')}</div>`);};
|
||||
if(!s||typeof s!=='object'||s.v!==1||typeof s.day!=='number'||typeof s.cash!=='number'||!s.pops||typeof s.pops!=='object'||!Array.isArray(s.links))return {err:tr('save.that_does_not_look_like_a')};
|
||||
if(s.lost)return {err:tr('save.that_network_went_bankrupt_it_cannot')};
|
||||
for(const c of Object.keys(s.pops))if(!isCity(c))return {err:tr('save.that_save_has_a_pop_in',{city:esc(String(c).slice(0,12))})};
|
||||
return {s,ver:j.version||'?',name:String(s.name||tr('common.unnamed_network'))};}
|
||||
function importFile(file){if(!file)return;if(file.size>8e6){toast(tr('save.that_file_is_too_big_to'),'bad');return;}
|
||||
const rd=new FileReader();rd.onload=()=>{const r=parseSave(String(rd.result));if(r.err){toast(tr('save.import_failed_err',{err:esc(r.err)}),'bad');sfx('err');return;}
|
||||
UI.importing=r.s;openModal(`<div class="eyebrow">${tr('common.import_a_save')}</div><h2 style="font-size:26px">${tr('save.load_name',{name:esc(r.name)})}</h2><p class="tagline">${esc(dateStr(r.s.day))} · ${tr('save.cash_in_the_bank',{cash:fmt$(r.s.cash)})} · ${trn('save.n_pop',Object.keys(r.s.pops).length)} · ${tr('save.saved_by_v_ver',{ver:esc(r.ver)})}</p>${S&&UI.started&&!S.lost?`<p class="note" style="color:var(--bad)">${tr('save.this_replaces_name_export_it_first',{name:esc(S.name)})}</p>`:''}<div class="btns">${btn(tr('save.load_this_network'),'importGo',{},'pink big')}${btn(tr('common.cancel'),UI.started?'closeModal':'helpClose',{},'ghost big')}</div>`);};
|
||||
rd.readAsText(file);}
|
||||
function loadSave(){try{const t=localStorage.getItem('sot-save-v1');if(t){const s=JSON.parse(t);if(s&&s.v===1&&!s.lost)return s;}}catch(e){}return null;}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue