Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: allow to use i18n.getMessage in a serviceWorker #93

Closed
carlosjeurissen opened this issue Oct 1, 2021 · 8 comments
Closed
Labels
implemented: chrome Implemented in Chrome implemented: safari Implemented in Safari proposal Proposal for a change or new feature topic: localization topic: service worker Related to service worker background scripts

Comments

@carlosjeurissen
Copy link
Contributor

carlosjeurissen commented Oct 1, 2021

With mv3, i18n.getMessage and i18n.getUILanguage are not a function in the service_worker background script. This is troublesome as this is needed to set the label of action buttons or the entries of context menus.

One of the reasons this might not be available is the sync nature of this method. Potentially we can resolve this by either offer an promise-based initialization function for this after which i18n.getMessage is available. Or make an async version of i18n.getMessage. Using fetch calls to the _locales files is not a viable alternative as this wouldn't allow the extension developer to rely on the native browser fallback system (es_419 would fall back to es). This would also be an issue since i18n.getUILanguage is unavailable and one has to rely either on navigator.language(s) or i18n.getAcceptLanguages which both would not give the language of the browser.

See also:

@carlosjeurissen carlosjeurissen changed the title Proposal: allow to use chrome.i18n.getMessage in a serviceWorker Proposal: allow to use i18n.getMessage in a serviceWorker Oct 9, 2021
@ghostwords
Copy link

This might have gotten fixed in Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=1159438#c24

@carlosjeurissen
Copy link
Contributor Author

This might have gotten fixed in Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=1159438#c24

Thanks for pointing that out! It actually hasn't been fixed. i18n.getUILanguage is now supported, yet i18n.getMessage is still unavailable.

@carlosjeurissen
Copy link
Contributor Author

Opened a new issue for it specifically for i18n.getMessage:
https://bugs.chromium.org/p/chromium/issues/detail?id=1268098

@dotproto
Copy link
Member

dotproto commented Nov 9, 2021

Thanks for opening that issue, @carlosjeurissen. To my knowledge Chrome intends to support i18n.getMessage() in Manifest V3, but in order to do so we need to tweak this method to be asynchronous due to the inherently async nature of service workers.

@carlosjeurissen
Copy link
Contributor Author

@dotproto Thanks for the update. Are there any proposals on how to do that? Potentially we can do something like i18n.initialise('$ieft_tag') which returns a promise which resolves when i18n.getMessage works. This would also cover https://crbug.com/660704

@maximtop
Copy link

maximtop commented Jul 28, 2022

On Chrome 103.0.5060.134 seems to be working already.

@xeenon xeenon added proposal Proposal for a change or new feature topic: service worker Related to service worker background scripts implemented: chrome Implemented in Chrome implemented: safari Implemented in Safari labels Aug 31, 2022
@xeenon
Copy link
Collaborator

xeenon commented Sep 1, 2022

I think we can close this. It was simply a bug in Chrome, and Safari has supported this in v3 since supporting v3.

@xeenon xeenon closed this as completed Sep 1, 2022
@carlosjeurissen
Copy link
Contributor Author

@xeenon Thanks for the added labels and closing the issue. Seems serviceWorkers are not yet supported in Firefox, however, this API will probably work just fine once they do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
implemented: chrome Implemented in Chrome implemented: safari Implemented in Safari proposal Proposal for a change or new feature topic: localization topic: service worker Related to service worker background scripts
Projects
None yet
Development

No branches or pull requests

5 participants