Localize move notification titles to recipient's preferred language#101
Localize move notification titles to recipient's preferred language#101
Conversation
…nt locale Co-authored-by: ProLoser <67395+ProLoser@users.noreply.github.com>
…etch Co-authored-by: ProLoser <67395+ProLoser@users.noreply.github.com>
|
@copilot ACTUALLY don't do it on the backend in the cloud function, JUST do it on the client or in the webworker |
Co-authored-by: ProLoser <67395+ProLoser@users.noreply.github.com>
Done! Moved translation logic to the service worker (client-side). The backend Cloud Function is reverted to its original state, and the service worker now handles translating notification titles based on the user's language preference. Commit: 35c3a5a |
public/firebase-messaging-sw.js
Outdated
| const playerName = title ? title.replace(' made a move', '').trim() : player; | ||
|
|
||
| // Translate the title | ||
| const translatedTitle = translateTitle(title, playerName, translation); |
There was a problem hiding this comment.
@copilot use a token for the playername and don't check what type of notification it is as we should be applying translation to all notifications when one is available
There was a problem hiding this comment.
Updated! The backend now sends {{name}} token with playerName and translationKey in data. The service worker uses the translationKey to look up the translation and replaces {{name}} with the player name. This generic approach will work for any notification that has a matching translation key. Commit: 6dee5c7
…tifications Co-authored-by: ProLoser <67395+ProLoser@users.noreply.github.com>
Move notifications were hardcoded to English (
"${playerName} made a move"). Now they're sent in the recipient's preferred language.Changes
Cloud Function (
functions/index.js){{name}}token placeholderplayerNameandtranslationKeyin the data payload for client-side translationService Worker (
public/firebase-messaging-sw.js)translationKeyfrom notification data to look up translations generically{{name}}token withplayerNamefrom data payloadLocale Files
"moveNotification": "{{name}} <translated text>"to all 14 language filesExample
Implementation
Translation is handled client-side in the service worker when background notifications are received:
/locales/{lang}/translation.jsontranslationKeyfrom data to find the translation{{name}}token withplayerNamefrom dataThis approach uses token-based translation that can be applied generically to any notification with a matching translation key.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.