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

Set language after pagefind has been initialized #489

Closed
openscript opened this issue Nov 3, 2023 · 7 comments
Closed

Set language after pagefind has been initialized #489

openscript opened this issue Nov 3, 2023 · 7 comments
Labels
improvement Not a bug Pagefind Search The web-facing search js/wasm API Pagefind UI The prebuilt Pagefind UI components Pending Release Work complete, but not necessarily released.

Comments

@openscript
Copy link

I have a web app, where the language can be changed by the user without reloading the page. Pagefind doesn't get to know this change, so it will search in the wrong language.

Is it possible to reinitialize or change the Pagefinds language after it has been initialized?

@bglw
Copy link
Contributor

bglw commented Nov 3, 2023

Hmm, re-initializing isn't something I had considered, but I can see why it would be helpful here. I'll look at exposing something to allow this.

Part of the reason it doesn't exist is that there's a fairly high cost to doing so — not only is the index separated by language (so meta info will need to be re-fetched), the WebAssembly itself is loaded specific to a language, so re-initialization will be of the entire stack. Not necessarily a big deal, since changing language through a reload would do so anyway, but just FYI.

Will let you know when this is available!

@bglw bglw added improvement Not a bug Pagefind UI The prebuilt Pagefind UI components Pagefind Search The web-facing search js/wasm API labels Nov 3, 2023
@openscript
Copy link
Author

openscript commented Nov 3, 2023

@bglw Thank you so much! Not only for this, but your whole work on this project! :)

@bglw
Copy link
Contributor

bglw commented Nov 15, 2023

@openscript, are you using the JS search API directly, or the Default UI package?

@bglw
Copy link
Contributor

bglw commented Nov 15, 2023

In either case, this has been implemented in #498 and will go out with the next release 🙂

@bglw bglw added the Pending Release Work complete, but not necessarily released. label Nov 15, 2023
@openscript
Copy link
Author

@openscript, are you using the JS search API directly, or the Default UI package?

I'm using the api and bring my own UI.

@openscript
Copy link
Author

openscript commented Nov 15, 2023

In either case, this has been implemented in #498 and will go out with the next release 🙂

Thank you so much. Looking forward trying it out!

@bglw
Copy link
Contributor

bglw commented Nov 16, 2023

Released in v1.0.4 🎉

Let me know if that works out for you! I have also included a test specifically for your case here:

await pagefind.destroy();
document.querySelector('html').setAttribute("lang", "pt-br");
await pagefind.init();

@bglw bglw closed this as completed Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Not a bug Pagefind Search The web-facing search js/wasm API Pagefind UI The prebuilt Pagefind UI components Pending Release Work complete, but not necessarily released.
Projects
None yet
Development

No branches or pull requests

2 participants