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

Add webview to l10n-sample #877

Open
Tracked by #922
jruales opened this issue Jun 9, 2023 · 3 comments
Open
Tracked by #922

Add webview to l10n-sample #877

jruales opened this issue Jun 9, 2023 · 3 comments
Assignees
Milestone

Comments

@jruales
Copy link

jruales commented Jun 9, 2023

The l10n sample is great, and I'm trying to incorporate it into an extension. I'm wondering how to integrate the l10n API into a webview. I would like to suggest adding a webview to the l10n-sample, or otherwise to add a new sample specifically for webview-l10n

@jruales
Copy link
Author

jruales commented Oct 3, 2023

I also had a question related to this topic. If I build my webviews using Webpack, would I be able to use the @vscode/l10n library from within the webview code, making calls to l10n.t() from within there?

@jruales
Copy link
Author

jruales commented Oct 3, 2023

I found this blog post that goes over one way of using the @vscode/l10n library from within the webview code:
https://www.eliostruyf.com/localization-webviews-visual-studio-code/

In that post, the author recommends sending over the contents of vscode.l10n.uri?.fsPath from the extension to the webview via postMessage. Is that the recommended way to proceed? I'm worried that postMessage would be slow to send so many strings, especially considering that all strings would go to all webviews, even if the webview only requires a subset of the strings.

I also wonder if I could directly access the localization file from the webview using Webview.asWebviewUri, which could be more performant than the postMessage approach.

@TylerLeonhardt
Copy link
Member

I would say at this time, there is no "recommended" way to do this. We want to light up localization for webviews in a more supported way... That's tracked here: microsoft/vscode#170919 (Notebook renderers are a form of webview)

Leveraging @vscode/l10n is certainly an option as you could:

  • send over vscode.l10n.uri
  • do await l10n.config({ uri: thatUriString })

The other option, which I think is more common, is to localize your strings in the extension host, and then send them over to the webview localized. You can do this in many different ways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants