Полностью поддерживает английский язык

This commit is contained in:
AidarKC
2026-11-10 14:02:34 +03:00
parent 405b9a91a7
commit 9c30b33b39
71 changed files with 2658 additions and 1445 deletions
+28 -37
View File
@@ -1,13 +1,8 @@
import { t } from '../i18n/index.js';
import { formatDate, formatTime, formatDateTime, formatRelative } from '../i18n/format.js';
import { iconHtml } from '../components/ui-icon.js';
const TOAST_HOST_ID = 'shine-toast-host';
const rtf = (() => {
try {
return new Intl.RelativeTimeFormat('ru', { numeric: 'always' });
} catch {
return null;
}
})();
function toNumber(value) {
const n = Number(value);
@@ -33,10 +28,10 @@ function pickUnit(seconds) {
export function formatClockTime(timestampMs) {
const ts = toNumber(timestampMs);
if (!ts) return '';
return new Intl.DateTimeFormat('ru-RU', { hour: '2-digit', minute: '2-digit' }).format(new Date(ts));
return formatTime(new Date(ts));
}
const SHORT_MONTHS = ['янв', 'фев', 'мар', 'апр', 'мая', 'июн', 'июл', 'авг', 'сен', 'окт', 'ноя', 'дек'];
const shortDay = (date) => formatDate(date, { day: 'numeric', month: 'short' });
// Дата записи в ряду действий: сегодня «10:24», раньше «25 сен, 10:24», в прошлом году «25 сен 2025».
export function formatPostStamp(timestampMs) {
@@ -46,7 +41,7 @@ export function formatPostStamp(timestampMs) {
const now = new Date();
const clock = formatClockTime(ts);
if (dt.toDateString() === now.toDateString()) return clock;
const day = `${dt.getDate()} ${SHORT_MONTHS[dt.getMonth()]}`;
const day = shortDay(dt);
if (dt.getFullYear() !== now.getFullYear()) return `${day} ${dt.getFullYear()}`;
return `${day}, ${clock}`;
}
@@ -59,10 +54,10 @@ export function formatDayLabel(timestampMs) {
const today = new Date();
const startOf = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
const diffDays = Math.round((startOf(today) - startOf(dt)) / 86400000);
if (diffDays === 0) return 'Сегодня';
if (diffDays === 1) return 'Вчера';
if (diffDays === 0) return formatRelative(0, 'day');
if (diffDays === 1) return formatRelative(-1, 'day');
const sameYear = dt.getFullYear() === today.getFullYear();
return new Intl.DateTimeFormat('ru-RU', { day: 'numeric', month: 'long', ...(sameYear ? {} : { year: 'numeric' }) }).format(dt);
return formatDate(dt, { day: 'numeric', month: 'long', ...(sameYear ? {} : { year: 'numeric' }) });
}
export function dayKey(timestampMs) {
@@ -81,17 +76,17 @@ export function formatListTime(timestampMs) {
const now = new Date();
const startOfToday = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime();
if (ts >= startOfToday) {
return new Intl.DateTimeFormat('ru-RU', { hour: '2-digit', minute: '2-digit' }).format(dt);
return formatTime(dt);
}
const dayMs = 86400000;
if (ts >= startOfToday - dayMs) return 'вчера';
if (ts >= startOfToday - dayMs) return formatRelative(-1, 'day');
if (ts >= startOfToday - 6 * dayMs) {
return new Intl.DateTimeFormat('ru-RU', { weekday: 'short' }).format(dt);
return formatDate(dt, { weekday: 'short' });
}
if (dt.getFullYear() === now.getFullYear()) {
return new Intl.DateTimeFormat('ru-RU', { day: '2-digit', month: '2-digit' }).format(dt);
return formatDate(dt, { day: '2-digit', month: '2-digit' });
}
return new Intl.DateTimeFormat('ru-RU', { day: '2-digit', month: '2-digit', year: '2-digit' }).format(dt);
return formatDate(dt, { day: '2-digit', month: '2-digit', year: '2-digit' });
}
// Возраст записи в шапке поста и ответа: «сейчас», «5 мин», «2 ч», «3 д», потом «12 окт», в прошлом году «12 окт 2025».
@@ -99,14 +94,14 @@ export function formatShortAge(timestampMs) {
const ts = toNumber(timestampMs);
if (!ts) return '';
const ageMinutes = Math.max(0, Math.floor((Date.now() - ts) / 60000));
if (ageMinutes < 1) return 'сейчас';
if (ageMinutes < 60) return `${ageMinutes} мин`;
if (ageMinutes < 1) return formatRelative(0, 'second');
if (ageMinutes < 60) return formatRelative(-ageMinutes, 'minute', { numeric: 'always', style: 'narrow' });
const ageHours = Math.floor(ageMinutes / 60);
if (ageHours < 24) return `${ageHours} ч`;
if (ageHours < 24) return formatRelative(-ageHours, 'hour', { numeric: 'always', style: 'narrow' });
const ageDays = Math.floor(ageHours / 24);
if (ageDays < 7) return `${ageDays} д`;
if (ageDays < 7) return formatRelative(-ageDays, 'day', { numeric: 'always', style: 'narrow' });
const dt = new Date(ts);
const day = `${dt.getDate()} ${SHORT_MONTHS[dt.getMonth()]}`;
const day = shortDay(dt);
return dt.getFullYear() === new Date().getFullYear() ? day : `${day} ${dt.getFullYear()}`;
}
@@ -121,26 +116,22 @@ export function formatRelativeTime(timestampMs) {
const ageSeconds = Math.max(0, (now - ts) / 1000);
const ageDays = ageSeconds / 86400;
if (ageSeconds < 60) return 'только что';
if (ageSeconds < 60) return formatRelative(0, 'second');
if (ageDays < 7) {
const [unit, value] = pickUnit(diffSeconds);
if (rtf) return rtf.format(value, unit);
const absValue = Math.abs(value);
const suffix = value <= 0 ? 'назад' : 'через';
const labels = { second: 'сек', minute: 'мин', hour: 'ч', day: 'д' };
return `${absValue} ${labels[unit] || ''} ${suffix}`.trim();
return formatRelative(value, unit, { numeric: 'always' });
}
if (dt.getFullYear() === nowDt.getFullYear()) {
return new Intl.DateTimeFormat('ru-RU', {
return formatDateTime(dt, {
day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit',
}).format(dt).replace(',', ',');
});
}
return new Intl.DateTimeFormat('ru-RU', {
return formatDate(dt, {
day: '2-digit', month: '2-digit', year: 'numeric',
}).format(dt);
});
}
function ensureToastHost() {
@@ -277,7 +268,7 @@ export function writeChannelNotificationsState(nextState) {
}
export function makeAuthorLabel(login, localNumber) {
const cleanLogin = String(login || 'автор');
const cleanLogin = String(login || t('remaining.channels.author'));
const n = Number(localNumber);
if (!Number.isFinite(n) || n < 1) return cleanLogin;
return `${cleanLogin} · #${n}`;
@@ -300,7 +291,7 @@ export function createSkeletonRows(kind = 'list', count = 4) {
const wrap = document.createElement('div');
wrap.className = `skeleton-rows skeleton-rows--${kind}`;
wrap.setAttribute('aria-busy', 'true');
wrap.setAttribute('aria-label', 'Загрузка');
wrap.setAttribute('aria-label', t('remaining.channels.loading'));
for (let i = 0; i < count; i += 1) {
const row = document.createElement('div');
row.className = 'skeleton-row';
@@ -379,7 +370,7 @@ export async function longPressFeel(el, delayMs = 130) {
// Когда появится, здесь вызывать настоящий обработчик.
export const REPOSTS_ENABLED = false;
export function notifyRepostSoon() {
showToast('Репосты скоро появятся', { kind: 'info' });
showToast(t('remaining.channels.reposts_are_coming_soon'), { kind: 'info' });
}
// Общая карточка «не удалось загрузить»: короткий заголовок, причина в пару строк и крупная кнопка снизу.
@@ -395,7 +386,7 @@ export function createLoadErrorCard({ title, message, onRetry, secondary = null
const retry = document.createElement('button');
retry.type = 'button';
retry.className = 'primary-btn';
retry.textContent = 'Повторить';
retry.textContent = t('remaining.channels.retry');
retry.addEventListener('click', onRetry);
card.append(heading, details, retry);
if (secondary) {