diff --git a/carino-clock.js b/carino-clock.js
index 1aa9529..9ba11c8 100644
--- a/carino-clock.js
+++ b/carino-clock.js
@@ -15,6 +15,11 @@
* .beats = Swatch Internet Time (Biel Mean Time = UTC+1, 1 beat = 86.4s)
Change the clock here once; every site picks it up on next load.
+
+ Language: the tooltip and the local city name come from a small
+ dictionary here (es, pt-BR, ja, ru), picked by CarinoLang.current or
+ ; a site's window.t wins when it has the string. UTC,
+ EPOCH, TAI and BEATS are names, not words, and stay as they are.
============================================================ */
(function () {
'use strict';
@@ -24,11 +29,58 @@
function pad(n) { return String(n).padStart(2, '0'); }
+ var TIP = 'Click to toggle Local / UTC / Epoch / TAI / .beats';
+
+ // The tooltip, plus the city names of the zones the fleet's visitors are
+ // most often in. Any other zone shows its IANA city name as it is.
+ var L10N = {
+ es: {
+ 'Click to toggle Local / UTC / Epoch / TAI / .beats': 'Haz clic para alternar Local / UTC / Epoch / TAI / .beats',
+ 'LOCAL': 'LOCAL', 'Mexico City': 'Ciudad de México', 'New York': 'Nueva York', 'Sao Paulo': 'São Paulo',
+ 'London': 'Londres', 'Tokyo': 'Tokio', 'Moscow': 'Moscú', 'Bogota': 'Bogotá',
+ },
+ 'pt-BR': {
+ 'Click to toggle Local / UTC / Epoch / TAI / .beats': 'Clique para alternar Local / UTC / Epoch / TAI / .beats',
+ 'LOCAL': 'LOCAL', 'Mexico City': 'Cidade do México', 'New York': 'Nova York', 'Sao Paulo': 'São Paulo',
+ 'London': 'Londres', 'Madrid': 'Madri', 'Tokyo': 'Tóquio', 'Moscow': 'Moscou', 'Bogota': 'Bogotá',
+ },
+ ja: {
+ 'Click to toggle Local / UTC / Epoch / TAI / .beats': 'クリックで切り替え: ローカル / UTC / Epoch / TAI / .beats',
+ 'LOCAL': 'ローカル', 'Mexico City': 'メキシコシティ', 'New York': 'ニューヨーク', 'Los Angeles': 'ロサンゼルス',
+ 'Chicago': 'シカゴ', 'Sao Paulo': 'サンパウロ', 'Bogota': 'ボゴタ', 'Madrid': 'マドリード',
+ 'London': 'ロンドン', 'Tokyo': '東京', 'Moscow': 'モスクワ',
+ },
+ ru: {
+ 'Click to toggle Local / UTC / Epoch / TAI / .beats': 'Нажмите, чтобы переключить: местное / UTC / Epoch / TAI / .beats',
+ 'LOCAL': 'МЕСТНОЕ', 'Mexico City': 'Мехико', 'New York': 'Нью-Йорк', 'Los Angeles': 'Лос-Анджелес',
+ 'Chicago': 'Чикаго', 'Sao Paulo': 'Сан-Паулу', 'Bogota': 'Богота', 'Madrid': 'Мадрид',
+ 'London': 'Лондон', 'Tokyo': 'Токио', 'Moscow': 'Москва',
+ },
+ };
+ function langNow() {
+ var l = String((window.CarinoLang && window.CarinoLang.current) || document.documentElement.lang || 'en');
+ return /^pt/i.test(l) ? 'pt-BR' : l.slice(0, 2).toLowerCase();
+ }
+ function tr(s) {
+ if (typeof window.t === 'function') {
+ try { var v = window.t(s); if (typeof v === 'string' && v && v !== s) return v; } catch (e) { /* not i18n */ }
+ }
+ var d = L10N[langNow()];
+ return (d && d[s]) || s;
+ }
+
var LOCAL_TZ = 'LOCAL';
try {
LOCAL_TZ = (Intl.DateTimeFormat().resolvedOptions().timeZone || 'LOCAL')
.split('/').pop().replace(/_/g, ' ') || 'LOCAL';
} catch (e) { LOCAL_TZ = 'LOCAL'; }
+ // Looked up once per language, not on every one-second tick.
+ var tzLang = null, tzLabel = LOCAL_TZ;
+ function localTz() {
+ var l = langNow();
+ if (l !== tzLang) { tzLang = l; tzLabel = tr(LOCAL_TZ); }
+ return tzLabel;
+ }
function beats(d) { // Swatch .beats — UTC+1, 1000 beats/day
return '@' + String(Math.floor(((d.getTime() + 3600000) % 86400000) / 86400) % 1000).padStart(3, '0');
@@ -46,7 +98,7 @@
} else if (mode === 4) {
time = beats(d); tz = 'BEATS';
} else {
- time = pad(d.getHours()) + ':' + pad(d.getMinutes()) + ':' + pad(d.getSeconds()); tz = LOCAL_TZ;
+ time = pad(d.getHours()) + ':' + pad(d.getMinutes()) + ':' + pad(d.getSeconds()); tz = localTz();
}
return { time: time, tz: tz };
}
@@ -75,7 +127,7 @@
// partner, double-tapping the clock to cycle modes selects the digits on
// any slightly older iPhone or Mac.
box.style.webkitUserSelect = 'none';
- box.setAttribute('title', 'Click to toggle Local / UTC / Epoch / TAI / .beats');
+ box.setAttribute('title', tr(TIP));
if (!box.hasAttribute('role')) box.setAttribute('role', 'button');
if (!box.hasAttribute('tabindex')) box.setAttribute('tabindex', '0');
function cycle() { c.mode = (c.mode + 1) % MODES; tickAll(); }
@@ -104,6 +156,14 @@
if (!document.hidden) tickAll();
});
window.addEventListener('pageshow', tickAll);
+ // A tick late, so a site's own langchange handler has switched window.t.
+ function relabel() {
+ tzLang = null;
+ for (var i = 0; i < clocks.length; i++) clocks[i].box.setAttribute('title', tr(TIP));
+ tickAll();
+ }
+ window.addEventListener('carino:langchange', function () { setTimeout(relabel, 0); });
+ document.addEventListener('DOMContentLoaded', function () { setTimeout(relabel, 0); });
// The shared navbar injects its header shortly after load, so re-scan a
// few times to catch a `.header-clock` that appears just after we boot.
var tries = 0;
diff --git a/carino-lang.js b/carino-lang.js
index e4c02e9..f40ddf7 100644
--- a/carino-lang.js
+++ b/carino-lang.js
@@ -29,7 +29,9 @@
window.CarinoLang.set(code) // programmatic switch
window.addEventListener('carino:langchange', (e) => e.detail.lang)
An app with no dictionary simply stays English — the choice
- still persists for the sites that do translate.
+ still persists for the sites that do translate. The switcher's
+ own words (its tooltip, "Auto", the legal shield's tooltip) are
+ translated here, with a site's window.t winning when it has them.
Self-contained: styles are inlined and scoped under #cnLangBtn /
#cnLangBox with hard-coded colours, so it is safe on light-themed
@@ -199,8 +201,12 @@
updateBtn();
renderRows();
window.dispatchEvent(new CustomEvent('carino:langchange', { detail: { lang: current } }));
+ // Again a tick later, once the site's own handler has switched window.t.
+ setTimeout(relabel, 0);
}
+ function relabel() { updateBtn(); renderRows(); }
+
function label(code) {
for (var i = 0; i < LANGS.length; i++) if (LANGS[i][0] === code) return LANGS[i][1];
return 'EN';
@@ -221,9 +227,28 @@
var LEGAL = { en: 'Legal notice & privacy', es: 'Aviso legal y privacidad', 'pt-BR': 'Aviso legal e privacidade',
ja: '法的通知とプライバシー', ru: 'Правовая информация и конфиденциальность' };
+ var TIP = 'Language — Auto follows your browser';
+ var L10N = {
+ es: { 'Language — Auto follows your browser': 'Idioma: Auto sigue a tu navegador', 'Auto': 'Auto' },
+ 'pt-BR': { 'Language — Auto follows your browser': 'Idioma: Auto segue o seu navegador', 'Auto': 'Auto' },
+ ja: { 'Language — Auto follows your browser': '言語 — 自動はブラウザーの設定に従います', 'Auto': '自動' },
+ ru: { 'Language — Auto follows your browser': 'Язык — «Авто» следует настройкам браузера', 'Auto': 'Авто' },
+ };
+ function tr(s) {
+ if (typeof window.t === 'function') {
+ try { var v = window.t(s); if (typeof v === 'string' && v && v !== s) return v; } catch (e) { /* not i18n */ }
+ }
+ var d = L10N[current];
+ return (d && d[s]) || s;
+ }
+
function updateBtn() {
var btn = document.getElementById('cnLangBtn');
- if (btn) btn.innerHTML = ICON + '' + (manual ? label(current) : 'AUTO') + '';
+ if (btn) {
+ btn.innerHTML = ICON + '' + (manual ? label(current) : 'AUTO') + '';
+ btn.title = tr(TIP);
+ btn.setAttribute('aria-label', btn.title);
+ }
var legal = document.getElementById('cnLegal');
if (legal) { legal.title = LEGAL[current] || LEGAL.en; legal.setAttribute('aria-label', legal.title); }
}
@@ -235,7 +260,7 @@
var auto = document.createElement('button');
auto.type = 'button';
auto.className = manual ? '' : 'active';
- auto.innerHTML = 'Auto' + label(resolve(navigator.language) || 'en') + '';
+ auto.innerHTML = '' + tr('Auto') + '' + label(resolve(navigator.language) || 'en') + '';
auto.addEventListener('click', function (e) {
e.stopPropagation();
set('auto');
@@ -267,11 +292,14 @@
var btn = document.createElement('button');
btn.id = 'cnLangBtn';
btn.type = 'button';
- btn.title = 'Language — Auto follows your browser';
btn.setAttribute('aria-haspopup', 'true');
if (beforeEl) right.insertBefore(btn, beforeEl); else right.appendChild(btn);
updateBtn();
+ // window.t (the site's i18n.js) loads after this file, still before
+ // DOMContentLoaded; adding the listener once that has passed is harmless.
+ document.addEventListener('DOMContentLoaded', function () { setTimeout(relabel, 0); });
+ setTimeout(relabel, 0);
var box = document.createElement('div');
box.id = 'cnLangBox';
diff --git a/carino-navbar.js b/carino-navbar.js
index f438fdd..e024952 100644
--- a/carino-navbar.js
+++ b/carino-navbar.js
@@ -70,6 +70,13 @@
needs it only some of the time (Asobi: while a game is open, not on
its scrolling chooser) switches it at run time instead:
window.CarinoNav.immersive(true | false).
+
+ Language. The bar's own words (tooltips, aria-labels, the greeting,
+ "More") come from a small dictionary in this file for es, pt-BR, ja
+ and ru, picked by CarinoLang.current (or ), so a site with
+ no i18n.js of its own still gets them. A site's window.t wins when it
+ has the string. They re-render on carino:langchange, one tick late so
+ the site's own handler has switched its dictionary first.
============================================================ */
(function () {
'use strict';
@@ -146,11 +153,91 @@
var LEGAL_URL = 'https://carino.systems/legal.html';
var LEGAL = 'Legal notice & privacy';
+ var L10N = {
+ es: {
+ 'Carino Systems — back to hub': 'Carino Systems — volver al hub',
+ '{app} — reload': '{app} — recargar',
+ '{repo} on GitHub': '{repo} en GitHub',
+ 'LinkedIn profile': 'Perfil en LinkedIn',
+ 'More': 'Más',
+ 'Ready.': 'Listo.',
+ 'Late shift.': 'Turno nocturno.',
+ 'Good morning.': 'Buenos días.',
+ 'Good afternoon.': 'Buenas tardes.',
+ 'Good evening.': 'Buenas noches.',
+ },
+ 'pt-BR': {
+ 'Carino Systems — back to hub': 'Carino Systems — voltar ao hub',
+ '{app} — reload': '{app} — recarregar',
+ '{repo} on GitHub': '{repo} no GitHub',
+ 'LinkedIn profile': 'Perfil no LinkedIn',
+ 'More': 'Mais',
+ 'Ready.': 'Pronto.',
+ 'Late shift.': 'Turno da noite.',
+ 'Good morning.': 'Bom dia.',
+ 'Good afternoon.': 'Boa tarde.',
+ 'Good evening.': 'Boa noite.',
+ },
+ ja: {
+ 'Carino Systems — back to hub': 'Carino Systems — ハブに戻る',
+ '{app} — reload': '{app} — 再読み込み',
+ '{repo} on GitHub': 'GitHub の {repo}',
+ 'LinkedIn profile': 'LinkedIn プロフィール',
+ 'More': 'その他',
+ 'Ready.': '準備完了。',
+ 'Late shift.': '夜勤お疲れさま。',
+ 'Good morning.': 'おはようございます。',
+ 'Good afternoon.': 'こんにちは。',
+ 'Good evening.': 'こんばんは。',
+ },
+ ru: {
+ 'Carino Systems — back to hub': 'Carino Systems — вернуться в хаб',
+ '{app} — reload': '{app} — перезагрузить',
+ '{repo} on GitHub': '{repo} на GitHub',
+ 'LinkedIn profile': 'Профиль в LinkedIn',
+ 'More': 'Ещё',
+ 'Ready.': 'Готово.',
+ 'Late shift.': 'Ночная смена.',
+ 'Good morning.': 'Доброе утро.',
+ 'Good afternoon.': 'Добрый день.',
+ 'Good evening.': 'Добрый вечер.',
+ },
+ };
+
+ function langNow() {
+ var l = String((window.CarinoLang && window.CarinoLang.current) || document.documentElement.lang || 'en');
+ return /^pt/i.test(l) ? 'pt-BR' : l.slice(0, 2).toLowerCase();
+ }
+ // A site's window.t answers first; only a string it does not know (t
+ // hands the key back) falls to the dictionary above. `literal` is the
+ // finished English ("Learn — reload"), which is how site dictionaries key
+ // it; `key` is the template with {name} slots, tried after it.
+ function tr(key, vars, literal) {
+ var fill = function (s) {
+ return String(s).replace(/\{(\w+)\}/g, function (m, k) { return vars && k in vars ? vars[k] : m; });
+ };
+ var en = literal || fill(key);
+ if (typeof window.t === 'function') {
+ try {
+ var v = window.t(en);
+ if (typeof v === 'string' && v && v !== en) return v;
+ if (vars) { v = window.t(key); if (typeof v === 'string' && v && v !== key) return fill(v); }
+ } catch (e) { /* not an i18n function after all */ }
+ }
+ var d = L10N[langNow()];
+ return d && d[key] ? fill(d[key]) : en;
+ }
+ function label(el, text, aria) {
+ if (!el) return;
+ el.title = text;
+ if (aria) el.setAttribute('aria-label', text);
+ }
+
var MARKUP = ''
+ '