HeyItsPrescott Posted July 11 Share Posted July 11 Hi there, I'm hoping to create a Spanish language version of a form and to localize some of the English-language text Squarespace automatically adds to form field labels (see attached). I read @paul2009's excellent answer from 2021, but wonder if Squarespace's architecture has changed since then, because I've tried variations (.innerHTML, .innerText, .createTextNode and .appendChild, putting the script in the header, footer, code block) and for the life of me I can't get it to work. The localized form, definitely a work in progress, is at https://wearegoodmedicine.org/comparte-su-historia. Thanks in advance for your help, Prescott Link to comment
paul2009 Posted July 14 Share Posted July 14 (edited) On 7/11/2023 at 10:57 PM, HeyItsPrescott said: I'm hoping to create a Spanish language version of a form. I...wonder if Squarespace's architecture has changed since then, because I've tried variations...and for the life of me I can't get it to work. In May 2023, Squarespace replaced the Form Block with a new version. The selectors are now very different. Edited September 29 by paul2009 About: SQSP User for 17 yrs. Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥. Work: Founder of SF Digital, building Squarespace Extensions to supercharge your commerce website. Content: Links in my posts may refer to SF Digital products or may be affiliate links. If my advice helped, you can thank me by clicking one of the feedback emojis below. I love coffee too. Link to comment
Greg_pns Posted September 28 Share Posted September 28 On 7/14/2023 at 1:52 PM, paul2009 said: In May 2023, Squarespace replaced the Form Block with a new version. Hello, Do you happen to know the new selectors ? It seems like they're hidden, because the translation with javascript does not work when using the selectors that the 'inspect' function of my brower gives me. Link to comment
paul2009 Posted September 29 Share Posted September 29 18 hours ago, Greg_pns said: Do you happen to know the new selectors? Please see my post in this thread about some of the changes. Did this help? Please give feedback by clicking an icon below ⬇️ About: SQSP User for 17 yrs. Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥. Work: Founder of SF Digital, building Squarespace Extensions to supercharge your commerce website. Content: Links in my posts may refer to SF Digital products or may be affiliate links. If my advice helped, you can thank me by clicking one of the feedback emojis below. I love coffee too. Link to comment
Inscape Posted October 2 Share Posted October 2 On 9/28/2023 at 11:35 AM, Greg_pns said: the translation with javascript does not work when using the selectors that the 'inspect' function of my brower gives me @paul2009 I'm experiencing what Greg mentioned as well. No matter where and how I add this code, or any script attempting to translate these fields (specifically First Name and Last Name), it doesn't work. I've tried several solutions including yours, and read all your information about the updated classes; still no go. Page I'm working on is here: https://lavender-disc-ta5j.squarespace.com/fr/contact-us Link to comment
Solution Inscape Posted October 2 Solution Share Posted October 2 5 minutes ago, Inscape said: @paul2009 I'm experiencing what Greg mentioned as well. No matter where and how I add this code, or any script attempting to translate these fields (specifically First Name and Last Name), it doesn't work. I've tried several solutions including yours, and read all your information about the updated classes; still no go. Page I'm working on is here: https://lavender-disc-ta5j.squarespace.com/fr/contact-us @Greg_pns and @HeyItsPrescott, I ended up solving this by using a CSS pseudo-element instead of a script. In custom CSS, added: .field.first-name .caption-text {visibility:hidden} .field.first-name .caption-text::before {content:"Prénom"; display:inline-block !important; visibility:visible !important;} .field.last-name .caption-text {visibility:hidden} .field.last-name .caption-text::before {content:"Nom de famille"; display:inline-block !important; visibility:visible !important;} .description.required {visibility:hidden} .description.required::before {content:"(requis)"; display:inline-block; visibility:visible} Hope this helps! HeyItsPrescott 1 Link to comment
Greg_pns Posted October 3 Share Posted October 3 17 hours ago, Inscape said: @Greg_pns and @HeyItsPrescott, I ended up solving this by using a CSS pseudo-element instead of a script. In custom CSS, added: .field.first-name .caption-text {visibility:hidden} .field.first-name .caption-text::before {content:"Prénom"; display:inline-block !important; visibility:visible !important;} .field.last-name .caption-text {visibility:hidden} .field.last-name .caption-text::before {content:"Nom de famille"; display:inline-block !important; visibility:visible !important;} .description.required {visibility:hidden} .description.required::before {content:"(requis)"; display:inline-block; visibility:visible} Hope this helps! Thanks for your reply ! I ended up asking chatgpt to write me a javascript snippet that detects if there is "fr" in the URL, and then change the fields through css - as I have a multilingual website. Here it is if it can help someone else : <script> // Get the current URL var currentUrl = window.location.href; // Check if the URL contains "/fr/" if (currentUrl.includes("/fr/")) { // Create a new style element var style = document.createElement('style'); style.type = 'text/css'; // Define the CSS rules with !important var css = ` /* First name - for /fr/ */ .field.first-name .caption-text { visibility: hidden !important; } .field.first-name .caption-text:before { visibility: visible !important; content: "Prénom" !important; } /* Last name - for /fr/ */ .field.last-name .caption-text { visibility: hidden !important; } .field.last-name .caption-text:before { visibility: visible !important; content: "Nom" !important; } `; // Add the CSS rules to the style element if (style.styleSheet) { style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } // Append the style element to the document's head document.head.appendChild(style); } </script> HeyItsPrescott 1 Link to comment
Inscape Posted October 4 Share Posted October 4 On 10/3/2023 at 7:46 AM, Greg_pns said: javascript snippet that detects if there is "fr" in the URL, and then change the fields through css That's great @Greg_pns! Looks like the same principle as my solution (using CSS pseudo-elements), with the ability to automatically detect whether the page is French. In my solution, I had previously added a class to all French pages which allowed me to target them in Custom CSS. Link to comment
HeyItsPrescott Posted October 27 Author Share Posted October 27 Success!! Thanks, @Inscape and @Greg_pns! Whether by CSS or JavaScript, both seem to do the trick ... thanks! | merci! | ¡gracias! Inscape 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment