SHA256
Локализовать интерфейс SHiNE на русский и английский
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { t, th } from '../i18n/index.js';
|
||||
import { createTopBar } from '../components/topbar.js';
|
||||
import { renderUserAvatar } from '../components/avatar-image.js';
|
||||
import { authService, state } from '../state.js';
|
||||
@@ -30,23 +31,23 @@ function byGender(gender, male, female, neutral) {
|
||||
}
|
||||
|
||||
function connectionActionLabel(typeCode, gender = '') {
|
||||
const verb = (male, female) => byGender(gender, male, female, `${male}(а)`);
|
||||
const verb = (male, female) => byGender(gender, male, female, t('screens.notifications_view.text_032', { value1: male }));
|
||||
switch (Number(typeCode)) {
|
||||
case CONNECTION_CLOSE_FRIEND: return `${verb('Добавил', 'Добавила')} вас в близкие друзья`;
|
||||
case CONNECTION_UNCLOSE_FRIEND: return `${verb('Убрал', 'Убрала')} вас из близких друзей`;
|
||||
case CONNECTION_FRIEND: return `${verb('Добавил', 'Добавила')} вас в друзья`;
|
||||
case CONNECTION_UNFRIEND: return `${verb('Убрал', 'Убрала')} вас из друзей`;
|
||||
case CONNECTION_SHINE_CONFIRMED: return `${verb('Подтвердил', 'Подтвердила')}, что вы сияющий`;
|
||||
case CONNECTION_SHINE_UNCONFIRMED: return `${verb('Снял', 'Сняла')} подтверждение «сияющий»`;
|
||||
case CONNECTION_OFFICIAL_CONFIRMED: return `${verb('Подтвердил', 'Подтвердила')} официальный статус аккаунта`;
|
||||
case CONNECTION_OFFICIAL_UNCONFIRMED: return `${verb('Снял', 'Сняла')} подтверждение официального статуса`;
|
||||
default: return `${verb('Изменил', 'Изменила')} связь с вами`;
|
||||
case CONNECTION_CLOSE_FRIEND: return t('screens.notifications_view.text_033', { value1: verb(t('screens.notifications_view.text_047'), t('screens.notifications_view.text_048')) });
|
||||
case CONNECTION_UNCLOSE_FRIEND: return t('screens.notifications_view.text_034', { value1: verb(t('screens.notifications_view.text_049'), t('screens.notifications_view.text_050')) });
|
||||
case CONNECTION_FRIEND: return t('screens.notifications_view.text_035', { value1: verb(t('screens.notifications_view.text_051'), t('screens.notifications_view.text_052')) });
|
||||
case CONNECTION_UNFRIEND: return t('screens.notifications_view.text_036', { value1: verb(t('screens.notifications_view.text_053'), t('screens.notifications_view.text_054')) });
|
||||
case CONNECTION_SHINE_CONFIRMED: return t('screens.notifications_view.text_037', { value1: verb(t('screens.notifications_view.text_055'), t('screens.notifications_view.text_056')) });
|
||||
case CONNECTION_SHINE_UNCONFIRMED: return t('screens.notifications_view.text_038', { value1: verb(t('screens.notifications_view.text_057'), t('screens.notifications_view.text_058')) });
|
||||
case CONNECTION_OFFICIAL_CONFIRMED: return t('screens.notifications_view.text_039', { value1: verb(t('screens.notifications_view.text_059'), t('screens.notifications_view.text_060')) });
|
||||
case CONNECTION_OFFICIAL_UNCONFIRMED: return t('screens.notifications_view.text_040', { value1: verb(t('screens.notifications_view.text_061'), t('screens.notifications_view.text_062')) });
|
||||
default: return t('screens.notifications_view.text_041', { value1: verb(t('screens.notifications_view.text_063'), t('screens.notifications_view.text_064')) });
|
||||
}
|
||||
}
|
||||
|
||||
function eventActionLabel(typeCode, gender = '') {
|
||||
if (Number(typeCode) === CONNECTION_UNFOLLOW) return `${byGender(gender, 'Отписался', 'Отписалась', 'Отписался(-ась)')} от вашего канала`;
|
||||
return `${byGender(gender, 'Подписался', 'Подписалась', 'Подписался(-ась)')} на ваш канал`;
|
||||
if (Number(typeCode) === CONNECTION_UNFOLLOW) return t('screens.notifications_view.text_042', { value1: byGender(gender, t('screens.notifications_view.text_065'), t('screens.notifications_view.text_066'), t('screens.notifications_view.text_067')) });
|
||||
return t('screens.notifications_view.text_043', { value1: byGender(gender, t('screens.notifications_view.text_068'), t('screens.notifications_view.text_069'), t('screens.notifications_view.text_070')) });
|
||||
}
|
||||
|
||||
function actionLabel(item, activeTab) {
|
||||
@@ -56,7 +57,7 @@ function actionLabel(item, activeTab) {
|
||||
: eventActionLabel(item.sourceMsgSubType, gender);
|
||||
}
|
||||
|
||||
export const pageMeta = { id: 'notifications-view', title: 'Уведомления' };
|
||||
export const pageMeta = { id: 'notifications-view', get title() { return t('screens.notifications_view.text_001'); } };
|
||||
|
||||
function normalizeItem(item) {
|
||||
return {
|
||||
@@ -157,12 +158,12 @@ async function enrichItem(item, activeTab) {
|
||||
function renderEmpty(activeTab) {
|
||||
return createStateMessage({
|
||||
icon: activeTab === 'events' ? 'channels' : activeTab === 'connections' ? 'network' : 'reply',
|
||||
title: activeTab === 'events' ? 'Пока нет событий' : activeTab === 'connections' ? 'Пока нет новостей о связях' : 'Пока нет ответов',
|
||||
title: activeTab === 'events' ? t('screens.notifications_view.text_021') : activeTab === 'connections' ? t('screens.notifications_view.text_022') : t('screens.notifications_view.text_023'),
|
||||
text: activeTab === 'events'
|
||||
? 'Подписки и отписки от ваших каналов появятся здесь.'
|
||||
? t('screens.notifications_view.text_024')
|
||||
: activeTab === 'connections'
|
||||
? 'Когда вас добавят в друзья или подтвердят статус, это появится здесь.'
|
||||
: 'Когда кто-то ответит на ваше сообщение в канале или обсуждении, ответ появится здесь.',
|
||||
? t('screens.notifications_view.text_025')
|
||||
: t('screens.notifications_view.text_026'),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -188,7 +189,7 @@ function renderAvatar(item) {
|
||||
function renderHead(item) {
|
||||
const profile = item.profile;
|
||||
const fullName = [profileField(profile, 'first_name'), profileField(profile, 'last_name')].filter(Boolean).join(' ')
|
||||
|| item.sourceLogin || 'Пользователь';
|
||||
|| item.sourceLogin || t('screens.notifications_view.text_030');
|
||||
const head = document.createElement('div');
|
||||
head.className = 'notification-card__head';
|
||||
const name = document.createElement('strong');
|
||||
@@ -206,10 +207,10 @@ function renderEngagement(engagement) {
|
||||
if (!engagement) return null;
|
||||
|
||||
const stats = [
|
||||
{ key: 'likesCount', icon: 'heart', label: 'Лайки' },
|
||||
{ key: 'repliesCount', icon: 'message', label: 'Ответы' },
|
||||
{ key: 'repostsCount', icon: 'refresh', label: 'Репосты' },
|
||||
{ key: 'sharesCount', icon: 'forward', label: 'Отправки' },
|
||||
{ key: 'likesCount', icon: 'heart', label: t('screens.notifications_view.text_002') },
|
||||
{ key: 'repliesCount', icon: 'message', label: t('screens.notifications_view.text_003') },
|
||||
{ key: 'repostsCount', icon: 'refresh', label: t('screens.notifications_view.text_004') },
|
||||
{ key: 'sharesCount', icon: 'forward', label: t('screens.notifications_view.text_005') },
|
||||
].filter(({ key }) => Number(engagement[key] || 0) > 0);
|
||||
|
||||
if (!stats.length) return null;
|
||||
@@ -281,7 +282,7 @@ function renderItem(item, activeTab, navigate) {
|
||||
// Во вкладке «Ответы» всё – ответы: подпись «ответил(а)» не нужна, сразу текст.
|
||||
const text = document.createElement('p');
|
||||
text.className = 'notification-card__text';
|
||||
text.textContent = item.sourceText || 'Ответ без текста';
|
||||
text.textContent = item.sourceText || t('screens.notifications_view.text_031');
|
||||
body.append(text);
|
||||
const engagement = renderEngagement(item.engagement);
|
||||
if (engagement) body.append(engagement);
|
||||
@@ -320,15 +321,15 @@ export function render({ navigate, chrome } = {}) {
|
||||
const tabs = document.createElement('div');
|
||||
tabs.className = 'tabs tabs--three notification-feed-tabs';
|
||||
tabs.setAttribute('role', 'radiogroup');
|
||||
tabs.setAttribute('aria-label', 'Категория уведомлений');
|
||||
const tabDefs = [['replies','Ответы'],['connections','Связи'],['events','События']];
|
||||
tabs.setAttribute('aria-label', t('screens.notifications_view.text_071'));
|
||||
const tabDefs = [['replies',t('screens.notifications_view.text_027')],['connections',t('screens.notifications_view.text_028')],['events',t('screens.notifications_view.text_029')]];
|
||||
const topbar = createTopBar({
|
||||
title: 'Уведомления',
|
||||
title: t('screens.notifications_view.text_006'),
|
||||
className: 'topbar--root notifications-topbar',
|
||||
actions: [{
|
||||
icon: 'check-double',
|
||||
title: 'Прочитать все',
|
||||
ariaLabel: 'Отметить все уведомления прочитанными',
|
||||
title: t('screens.notifications_view.text_007'),
|
||||
ariaLabel: t('screens.notifications_view.text_008'),
|
||||
className: 'notifications-read-all',
|
||||
onClick: () => { void markAllRead(); },
|
||||
}],
|
||||
@@ -375,7 +376,7 @@ export function render({ navigate, chrome } = {}) {
|
||||
const count = document.createElement('span');
|
||||
count.className = 'tab-count';
|
||||
count.textContent = counts[key] > 99 ? '99+' : String(counts[key]);
|
||||
count.setAttribute('aria-label', `новых: ${counts[key]}`);
|
||||
count.setAttribute('aria-label', t('screens.notifications_view.text_044', { value1: counts[key] }));
|
||||
b.append(count);
|
||||
}
|
||||
b.addEventListener('click',()=>{ if(state.notificationsTab===key)return; state.notificationsTab=key; renderCurrent(); });
|
||||
@@ -420,9 +421,9 @@ export function render({ navigate, chrome } = {}) {
|
||||
const unread=items.filter(x=>x.createdAtMs>seenAt); const old=items.filter(x=>x.createdAtMs<=seenAt);
|
||||
const nodes=[];
|
||||
const groupTitle=(text)=>{const el=document.createElement('h2');el.className='notification-group-title';el.textContent=text;return el;};
|
||||
if(unread.length) nodes.push(groupTitle(`Новые · ${unread.length}`));
|
||||
if(unread.length) nodes.push(groupTitle(t('screens.notifications_view.text_045', { value1: unread.length })));
|
||||
unread.forEach(x=>{const n=renderItem(x,tab,navigate);n.classList.add('notification-card--new');n.dataset.createdAtMs=String(x.createdAtMs);rowByItem.set(x,n);nodes.push(n);});
|
||||
if(unread.length && old.length) nodes.push(groupTitle('Ранее'));
|
||||
if(unread.length && old.length) nodes.push(groupTitle(t('screens.notifications_view.text_014')));
|
||||
old.forEach(x=>{const n=renderItem(x,tab,navigate);rowByItem.set(x,n);nodes.push(n);}); list.replaceChildren(...nodes);
|
||||
void enrichInBackground(items, tab, rowByItem, seq);
|
||||
if (tab === 'connections') void offerFriendBack(items, rowByItem, seq);
|
||||
@@ -455,22 +456,22 @@ export function render({ navigate, chrome } = {}) {
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = 'secondary-btn notification-card__answer';
|
||||
button.textContent = 'Дружить в ответ';
|
||||
button.textContent = t('screens.notifications_view.text_009');
|
||||
button.addEventListener('click', async (event) => {
|
||||
event.stopPropagation();
|
||||
button.disabled = true;
|
||||
button.textContent = 'Сохраняю…';
|
||||
button.textContent = t('screens.notifications_view.text_010');
|
||||
try {
|
||||
await authService.setUserRelation({ login: self, toLogin: login, kind: 'friend', enabled: true, storagePwd: state.session.storagePwdInMemory });
|
||||
const done = document.createElement('span');
|
||||
done.className = 'notification-card__answered';
|
||||
done.innerHTML = `${iconHtml('check')}<span>Вы друзья</span>`;
|
||||
done.innerHTML = `${iconHtml('check')}<span>${th('screens.notifications_view.text_046')}</span>`;
|
||||
button.replaceWith(done);
|
||||
showToast('Теперь вы друзья');
|
||||
showToast(t('screens.notifications_view.text_015'));
|
||||
} catch (error) {
|
||||
button.disabled = false;
|
||||
button.textContent = 'Дружить в ответ';
|
||||
showToast(toUserMessage(error, 'Не удалось добавить в друзья.'), { kind: 'error' });
|
||||
button.textContent = t('screens.notifications_view.text_011');
|
||||
showToast(toUserMessage(error, t('screens.notifications_view.text_016')), { kind: 'error' });
|
||||
}
|
||||
});
|
||||
body.append(button);
|
||||
@@ -513,10 +514,10 @@ export function render({ navigate, chrome } = {}) {
|
||||
if (lastNotifications?.payload) lastNotifications = { ...lastNotifications, payload: structuredClone(payloadCache), signature: '' };
|
||||
updateToolbarBadge(payloadCache);
|
||||
await renderCurrent();
|
||||
showToast('Все уведомления прочитаны');
|
||||
showToast(t('screens.notifications_view.text_017'));
|
||||
} catch (error) {
|
||||
updateToolbarBadge(payloadCache);
|
||||
showToast(toUserMessage(error, 'Не удалось отметить уведомления прочитанными.'), { kind: 'error' });
|
||||
showToast(toUserMessage(error, t('screens.notifications_view.text_018')), { kind: 'error' });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -525,7 +526,7 @@ export function render({ navigate, chrome } = {}) {
|
||||
const login = state.session.login;
|
||||
const cached = lastNotifications?.login === login ? lastNotifications : null;
|
||||
if (cached) { payloadCache = structuredClone(cached.payload); void renderCurrent(); }
|
||||
else { renderTabs({}); if (!list.childElementCount) list.replaceChildren(createLoadingState({ label: 'Загружаю уведомления' })); }
|
||||
else { renderTabs({}); if (!list.childElementCount) list.replaceChildren(createLoadingState({ label: t('screens.notifications_view.text_012') })); }
|
||||
try {
|
||||
const fresh=await authService.getNotifications(); if(seq!==requestSeq)return;
|
||||
const signature = JSON.stringify(fresh);
|
||||
@@ -536,10 +537,10 @@ export function render({ navigate, chrome } = {}) {
|
||||
}
|
||||
catch(error){
|
||||
if(seq!==requestSeq)return;
|
||||
if (payloadCache) { showToast(toUserMessage(error, 'Не удалось обновить уведомления.'), { kind: 'error' }); return; }
|
||||
if (payloadCache) { showToast(toUserMessage(error, t('screens.notifications_view.text_019')), { kind: 'error' }); return; }
|
||||
list.replaceChildren(createErrorState({
|
||||
title: 'Не удалось загрузить уведомления',
|
||||
text: toUserMessage(error, 'Проверьте соединение и попробуйте ещё раз.'),
|
||||
title: t('screens.notifications_view.text_013'),
|
||||
text: toUserMessage(error, t('screens.notifications_view.text_020')),
|
||||
onRetry: () => { list.replaceChildren(); void load(); },
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user