style: add translation for com.msgbyte.notify

pull/56/head
moonrailgun 3 years ago
parent 801cdcf145
commit 5db553aa7c

@ -2,23 +2,26 @@ import {
regGroupPanelBadge, regGroupPanelBadge,
regPluginGroupTextPanelExtraMenu, regPluginGroupTextPanelExtraMenu,
sharedEvent, sharedEvent,
showToasts,
} from '@capital/common'; } from '@capital/common';
import { Icon } from '@capital/component'; import { Icon } from '@capital/component';
import React from 'react'; import React from 'react';
import { appendSilent, hasSilent, removeSilent } from './silent'; import { appendSilent, hasSilent, removeSilent } from './silent';
import { initNotify } from './notify'; import { initNotify } from './notify';
import { Translate } from './translate';
const PLUGIN_NAME = 'com.msgbyte.notify'; const PLUGIN_NAME = 'com.msgbyte.notify';
if ('Notification' in window) { if ('Notification' in window) {
initNotify(); initNotify();
} else { } else {
console.warn('浏览器不支持 Notification'); showToasts(Translate.nosupport, 'warning');
console.warn(Translate.nosupport);
} }
regPluginGroupTextPanelExtraMenu({ regPluginGroupTextPanelExtraMenu({
name: `${PLUGIN_NAME}/grouppanelmenu`, name: `${PLUGIN_NAME}/grouppanelmenu`,
label: '免打扰', label: Translate.slient,
icon: 'mdi:bell-off-outline', icon: 'mdi:bell-off-outline',
onClick: (panelInfo) => { onClick: (panelInfo) => {
if (hasSilent(panelInfo.id)) { if (hasSilent(panelInfo.id)) {

@ -4,6 +4,7 @@ import {
getCachedUserInfo, getCachedUserInfo,
getServiceWorkerRegistration, getServiceWorkerRegistration,
} from '@capital/common'; } from '@capital/common';
import { Translate } from './translate';
import { hasSilent } from './silent'; import { hasSilent } from './silent';
export function initNotify() { export function initNotify() {
@ -37,7 +38,7 @@ export function initNotify() {
getServiceWorkerRegistration(); getServiceWorkerRegistration();
if (registration) { if (registration) {
registration.showNotification(`来自 ${nickname}`, { registration.showNotification(`${Translate.from} ${nickname}`, {
body: content, body: content,
icon, icon,
tag: 'tailchat-message', tag: 'tailchat-message',
@ -45,7 +46,7 @@ export function initNotify() {
}); });
} else { } else {
// fallback // fallback
new Notification(`来自 ${nickname}`, { new Notification(`${Translate.from} ${nickname}`, {
body: content, body: content,
icon, icon,
tag: 'tailchat-message', tag: 'tailchat-message',

@ -0,0 +1,13 @@
import { localTrans } from '@capital/common';
export const Translate = {
nosupport: localTrans({
'zh-CN': '当前浏览器不支持 Notification',
'en-US': 'This browser not support Notification',
}),
slient: localTrans({ 'zh-CN': '免打扰', 'en-US': 'Slient' }),
from: localTrans({
'zh-CN': '来自',
'en-US': 'From',
}),
};
Loading…
Cancel
Save