SHA256
Локализовать интерфейс SHiNE на русский и английский
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { t, th } from '../i18n/index.js';
|
||||
// «Уведомления» в настройках: звук сообщений, разрешение системных уведомлений и чаты
|
||||
// «без звука». Всё – настройки этого устройства, сервер про них не знает.
|
||||
import { createTopBar } from '../components/topbar.js';
|
||||
@@ -9,7 +10,7 @@ import {
|
||||
import { DEVICE_PREFS_EVENT, getDevicePref, setDevicePref } from '../services/device-prefs.js';
|
||||
import { showToast } from '../services/channels-ux.js';
|
||||
|
||||
export const pageMeta = { id: 'notification-settings-view', title: 'Уведомления' };
|
||||
export const pageMeta = { id: 'notification-settings-view', get title() { return t('screens.notification_settings_view.text_001'); } };
|
||||
|
||||
function permissionState() {
|
||||
if (typeof Notification === 'undefined') return 'unsupported';
|
||||
@@ -22,21 +23,21 @@ export function render({ navigate, chrome } = {}) {
|
||||
let disposed = false;
|
||||
|
||||
chrome?.setTopbar(createTopBar({
|
||||
title: 'Уведомления',
|
||||
title: t('screens.notification_settings_view.text_002'),
|
||||
back: { onClick: () => navigate('settings-view') },
|
||||
}));
|
||||
|
||||
const soundTitle = document.createElement('p');
|
||||
soundTitle.className = 'nav-list__title';
|
||||
soundTitle.textContent = 'Сообщения';
|
||||
soundTitle.textContent = t('screens.notification_settings_view.text_003');
|
||||
const soundList = document.createElement('div');
|
||||
soundList.className = 'nav-list';
|
||||
const soundRow = document.createElement('label');
|
||||
soundRow.className = 'nav-row nav-row--switch';
|
||||
soundRow.innerHTML = `
|
||||
<span class="nav-row__text">
|
||||
<span class="nav-row__label">Звук в открытом приложении</span>
|
||||
<span class="nav-row__hint">Короткий сигнал о новом сообщении</span>
|
||||
<span class="nav-row__label">${th('screens.notification_settings_view.text_020')}</span>
|
||||
<span class="nav-row__hint">${th('screens.notification_settings_view.text_021')}</span>
|
||||
</span>
|
||||
<input class="switch" type="checkbox" />
|
||||
`;
|
||||
@@ -55,10 +56,10 @@ export function render({ navigate, chrome } = {}) {
|
||||
function renderSystemRow() {
|
||||
const permission = permissionState();
|
||||
const texts = {
|
||||
granted: ['Уведомления на устройстве', 'Разрешены: придут, даже когда приложение свёрнуто'],
|
||||
denied: ['Уведомления на устройстве', 'Запрещены. Разрешите их для этого сайта в настройках браузера'],
|
||||
default: ['Уведомления на устройстве', 'Пока не разрешены – без них не узнать о сообщении, когда приложение свёрнуто'],
|
||||
unsupported: ['Уведомления на устройстве', 'Этот браузер их не поддерживает'],
|
||||
granted: [t('screens.notification_settings_view.text_009'), t('screens.notification_settings_view.text_010')],
|
||||
denied: [t('screens.notification_settings_view.text_011'), t('screens.notification_settings_view.text_012')],
|
||||
default: [t('screens.notification_settings_view.text_013'), t('screens.notification_settings_view.text_014')],
|
||||
unsupported: [t('screens.notification_settings_view.text_015'), t('screens.notification_settings_view.text_016')],
|
||||
};
|
||||
const [label, hint] = texts[permission] || texts.unsupported;
|
||||
systemRow.innerHTML = `
|
||||
@@ -73,14 +74,14 @@ export function render({ navigate, chrome } = {}) {
|
||||
const allow = document.createElement('button');
|
||||
allow.type = 'button';
|
||||
allow.className = 'primary-btn nav-row__button';
|
||||
allow.textContent = 'Разрешить';
|
||||
allow.textContent = t('screens.notification_settings_view.text_004');
|
||||
allow.addEventListener('click', async () => {
|
||||
allow.disabled = true;
|
||||
try {
|
||||
const result = await Notification.requestPermission();
|
||||
if (result === 'granted') showToast('Уведомления разрешены');
|
||||
if (result === 'granted') showToast(t('screens.notification_settings_view.text_007'));
|
||||
} catch {
|
||||
showToast('Не удалось запросить разрешение', { kind: 'error' });
|
||||
showToast(t('screens.notification_settings_view.text_008'), { kind: 'error' });
|
||||
}
|
||||
if (!disposed) renderSystemRow();
|
||||
});
|
||||
@@ -96,7 +97,7 @@ export function render({ navigate, chrome } = {}) {
|
||||
mutedList.className = 'notification-settings-muted';
|
||||
const mutedEmpty = document.createElement('p');
|
||||
mutedEmpty.className = 'meta-muted appearance-hint';
|
||||
mutedEmpty.textContent = 'Нет. Выключить звук чата можно в его меню «•••» или долгим нажатием в списке чатов.';
|
||||
mutedEmpty.textContent = t('screens.notification_settings_view.text_005');
|
||||
let peersRequested = false;
|
||||
|
||||
function mutedRow({ chatId, until }) {
|
||||
@@ -109,9 +110,9 @@ export function render({ navigate, chrome } = {}) {
|
||||
firstName: peer.firstName,
|
||||
lastName: peer.lastName,
|
||||
avatar: peer.avatar || null,
|
||||
sub: [fullName ? login : '', until ? formatDmMuteUntil(until) : 'навсегда'].filter(Boolean).join(' · '),
|
||||
sub: [fullName ? login : '', until ? formatDmMuteUntil(until) : t('screens.notification_settings_view.text_017')].filter(Boolean).join(' · '),
|
||||
onClick: () => navigate(`chat/${encodeURIComponent(normalizeDmChatId(chatId))}`),
|
||||
actions: [{ icon: 'bell', label: 'Включить звук', onClick: () => setDmChatMuted(chatId, false) }],
|
||||
actions: [{ icon: 'bell', label: t('screens.notification_settings_view.text_006'), onClick: () => setDmChatMuted(chatId, false) }],
|
||||
});
|
||||
}
|
||||
|
||||
@@ -135,7 +136,7 @@ export function render({ navigate, chrome } = {}) {
|
||||
|
||||
function renderMuted() {
|
||||
const muted = getMutedDmChats();
|
||||
mutedTitle.textContent = muted.length ? `Чаты без звука · ${muted.length}` : 'Чаты без звука';
|
||||
mutedTitle.textContent = muted.length ? t('screens.notification_settings_view.text_019', { value1: muted.length }) : t('screens.notification_settings_view.text_018');
|
||||
mutedList.hidden = !muted.length;
|
||||
mutedEmpty.hidden = Boolean(muted.length);
|
||||
mutedList.replaceChildren(...muted.map(mutedRow));
|
||||
|
||||
Reference in New Issue
Block a user