Skip to content

Instantly share code, notes, and snippets.

@EduardoAC
Created February 11, 2024 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EduardoAC/402c06165f11646a70e3a354e5838d12 to your computer and use it in GitHub Desktop.
Save EduardoAC/402c06165f11646a70e3a354e5838d12 to your computer and use it in GitHub Desktop.
Web app polling function designed to monitor language changes in the browser extension for real-time synchronization.
import Cookies from "js-cookie";
// Function to check for changes in cookies
function checkLanguageCookieChanges() {
// Get the current value of the cookie
const currentLanguage = Cookie.get("{your-webApp-name}-language}");
// Compare with the previous value
if (currentLanguage !== checkLanguageCookieChanges.previousLanguage) {
// Cookie has changed
i18n.changeLanguage(currentLanguage);
// Update the previous value for the next check
checkCookieChanges.previousLanguage = currentLanguage;
}
}
// Initialize the previous value
checkLanguageCookieChanges.previousLanguage = Cookie.get(
"{your-webApp-name}-language}"
);
// Check for changes every 1 second (adjust as needed)
setInterval(checkCookieChanges, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment