Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Weglot x BoostCommerce Proposal

This draft explains how Weglot and BoostCommerce can interact together.

Problem

Example Website : https://www.party-expert.com/

In this example website, the original language is EN. If a visitor choose the FR language, it won't be able to search a product in french because all suggestions are based on english product names.

Suggestions script link will be https://services.mybcapps.com/bc-sf-filter/search/suggest?q=[FRENCH_KEYWORD]&...

Proposal

Method

Weglot has a public function available in Weglot global object when app is installed: Weglot.search() :

Weglot.search(term: String, callback: Function)

  • term is the word the user is typing. It's the full value of the input in a language which isn't the original language of the website.
  • callback is a function that takes one argument, the term searched back into the original language

Example, in a store in which the original language is English, and the current language on the page is French:

Weglot.search("chemise", function(englishTerm) {
  console.log(englishTerm) // Prints out: "shirt"
})

If the current language on the page is English:

Weglot.search("shirt", function(englishTerm) {
  console.log(englishTerm) // Prints out "shirt" immediately
})

Weglot.search makes its calls to cdn-api.weglot.com, which is a CDN served by AWS Cloudfront. It has many edge locations throughout the word and ensures a very fast answer. Cached response times are below 50ms across the US.

Reference in the developer documentation: https://developers.weglot.com/integration-guides/javascript#weglot-search-term-callback

Implementation

If you decide to use this method in your application, you can:

  • Add a Weglot detection code
  • Whenever Weglot is active, BC would call Weglot.search before calling its servers
// We need to check initialized property to use search method
if (window.Weglot && window.Weglot.initialized) {
  window.Weglot.search(keywords, BCSuggestions);
} else {
  BCSuggestions(keywords);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment