我使用以下代码显示“推送Web通知”。
我需要翻译body.message
键中包含的文本。
我在窗口对象中有国家代码值,但无法从服务人员访问窗口。
如何翻译此翻译?
service-worker.js:
// Listen for incoming push notifications
self.addEventListener('push', function (event) {
// Extract payload as JSON object, default to empty object
var data = event.data.json() || {};
// Extract notification image URL
var image = data.image || 'https://sdk.pushy.me/web/assets/img/icon.png';
// Notification title and body
var title = data.title || '';
var body = data.message || '';
// Notification options
var options = {
body: body,
icon: image,
badge: image,
data: {
url: data.url
}
};
// Wait until notification is shown
event.waitUntil(self.registration.showNotification(title, options));
});