Created
December 22, 2023 17:58
-
-
Save memetican/49ac4b6bf85b579fc24ddcc568acec36 to your computer and use it in GitHub Desktop.
Webflow Localization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get the date from your source field | |
// Identify by class, ID, or a custom attriute | |
// HACK: We'll use today's date as a placeholder | |
const date = new Date(); | |
// Get the current locale (e.g., 'it-IT' for Italian, 'en-US' for American English) | |
const locale = document.documentElement.lang; | |
// If none, exit, we don't want to change the date | |
// or, you can get the browser's locale as a backup | |
if(!locale) | |
locale = navigator.language || navigator.userLanguage; | |
// Create an instance of Intl.DateTimeFormat with the desired locale and options | |
const options = { year: 'numeric', month: 'long', day: 'numeric' }; // Customize as needed | |
const formatter = new Intl.DateTimeFormat(locale, options); | |
// Format the date | |
const localizedDate = formatter.format(date); | |
// Update your stored date field | |
console.log(localizedDate); // This will output the date in Italian format |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment